From a0ef78e97b6e5744fc68dec28ab54bb07d1d409c Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Mon, 30 Jan 2012 07:45:26 -0600 Subject: [PATCH] adjust online check syntax to try to fix a bug where renaming information can get "stale" and cause DrRacket to deadlock (this commit just sets up some stuff to make one fix possible, but that fix doesn't seem to be working, so the actual fix is disabled (see comment in commit)) --- collects/drracket/private/expanding-place.rkt | 3 +- .../drracket/private/syncheck/online-comp.rkt | 31 +++++++++++------- collects/drracket/tool-lib.rkt | 32 +++++++++++++++++-- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/collects/drracket/private/expanding-place.rkt b/collects/drracket/private/expanding-place.rkt index 729a857a02..f9d00329ec 100644 --- a/collects/drracket/private/expanding-place.rkt +++ b/collects/drracket/private/expanding-place.rkt @@ -128,7 +128,8 @@ (list (handler-key handler) ((handler-proc handler) expanded path - the-source)))) + the-source + orig-cust)))) (log-info "expanding-place.rkt: 11 handlers finished") (parameterize ([current-custodian orig-cust]) diff --git a/collects/drracket/private/syncheck/online-comp.rkt b/collects/drracket/private/syncheck/online-comp.rkt index d2ace36c1f..0cd315ba1a 100644 --- a/collects/drracket/private/syncheck/online-comp.rkt +++ b/collects/drracket/private/syncheck/online-comp.rkt @@ -11,20 +11,25 @@ (define obj% (class (annotations-mixin object%) - (init-field src) + (init-field src orig-cust) (define trace '()) (define-values (remote local) (place-channel)) (define table (make-hash)) - (thread - (λ () - (with-handlers ((exn:fail? (λ (x) (eprintf "online-comp.rkt: thread failed ~a\n" (exn-message x))))) - (let loop () - (define id/name (place-channel-get local)) - (define id (list-ref id/name 0)) - (define name (list-ref id/name 1)) - (define res ((hash-ref table id) name)) - (place-channel-put local res))))) + + ;; the hope is that changing the custodian like this + ;; shouldn't leak these threads, but it does seem to + ;; so for now we don't use it + (parameterize (#;[current-custodian orig-cust]) + (thread + (λ () + (with-handlers ((exn:fail? (λ (x) (eprintf "online-comp.rkt: thread failed ~a\n" (exn-message x))))) + (let loop () + (define id/name (place-channel-get local)) + (define id (list-ref id/name 0)) + (define name (list-ref id/name 1)) + (define res ((hash-ref table id) name)) + (place-channel-put local res)))))) (define/override (syncheck:find-source-object stx) (and (equal? src (syntax-source stx)) @@ -51,7 +56,7 @@ (define/public (get-trace) (reverse trace)) (super-new))) -(define (go expanded path the-source) +(define (go expanded path the-source orig-cust) (with-handlers ((exn:fail? (λ (x) (printf "~a\n" (exn-message x)) (printf "---\n") @@ -62,7 +67,9 @@ (printf " ~s\n" x)) (printf "===\n") (raise x)))) - (define obj (new obj% [src the-source])) + (define obj (new obj% + [src the-source] + [orig-cust orig-cust])) (define-values (expanded-expression expansion-completed) (make-traversal (current-namespace) (get-init-dir path))) diff --git a/collects/drracket/tool-lib.rkt b/collects/drracket/tool-lib.rkt index 7f5ffcfbf8..d426667baa 100644 --- a/collects/drracket/tool-lib.rkt +++ b/collects/drracket/tool-lib.rkt @@ -110,7 +110,10 @@ all of the names in the tools library, for use defining keybindings (proc-doc/names drracket:module-language-tools:add-online-expansion-handler - (-> path-string? symbol? (-> (is-a?/c drracket:unit:definitions-text<%>) any/c any) void?) + (-> path-string? symbol? (-> (is-a?/c drracket:unit:definitions-text<%>) + any/c + any) + void?) (mod-path id local-handler) @{Registers a pair of procedures with DrRacket's online expansion machinery. @@ -121,11 +124,34 @@ all of the names in the tools library, for use defining keybindings the fully expanded object to that first procedure. (The procedure is called in the same context as the expansion process.) - Note that the thread that calls this procedure may be - killed at anytime: DrRacket may kill it when the user types in the buffer + The contract for that procedure is + @racketblock[(-> syntax? path? any/c custodian? + any)] + There are three other arguments. + + @itemize[ + @item{ + The @racket[path?] argument is the path that was the @racket[current-directory] + when the code was expanded. This directory should be used as the + @racket[current-directory] when resolving module paths obtained from + the syntax object.} + + @item{ + The third argument is the source object used in the syntax objects that + come from the definitions window in DrRacket. It may be a path (if the file + was saved), but it also might not be. Use @racket[equal?] to compare it + with the @racket[syntax-source] field of syntax objects to determine if + they come from the definitions window.} + + @item{ Note that the thread that calls this procedure may be + killed at any time: DrRacket may kill it when the user types in the buffer (in order to start a new expansion), but bizarro code may also create a separate thread during expansion that lurks around and then mutates arbitrary things. + Some code, however, should be longer running, surviving such custodian + shutdowns. To support this, the procedure called in the separate place is + supplied with a more powerful custodian that is not shut down. }] + The result of the procedure is expected to be something that can be sent across a @racket[place-channel], which is then sent back to the original place where DrRacket itself is running and passed to the @racket[local-handler]