From fa1861869ed462679e09f70fd90ffe2a1642f3e7 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 24 Apr 2019 14:58:15 -0600 Subject: [PATCH] cs: use continuation marks for module context Instead of a separate hash table mapping continuations to linklet-instance names, use a continuation mark. That's faster, because capturing a continuation means copying part of it on continue. --- racket/src/cs/linklet.sls | 6 +++--- racket/src/cs/primitive/internal.ss | 1 - racket/src/cs/rumble.sls | 2 +- racket/src/cs/rumble/error.ss | 17 +++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/racket/src/cs/linklet.sls b/racket/src/cs/linklet.sls index c42eecf17d..17ff22ac52 100644 --- a/racket/src/cs/linklet.sls +++ b/racket/src/cs/linklet.sls @@ -676,9 +676,9 @@ [target-instance ;; Instantiate into the given instance and return the ;; result of the linklet body: - (call/cc - (lambda (k) - (register-linklet-instantiate-continuation! k (instance-name target-instance)) + (with-continuation-mark + linklet-instantiate-key (instance-name target-instance) + (begin (when (eq? 'lazy (linklet-preparation linklet)) ;; Trigger lazy conversion of code from bytevector (let ([code (eval-from-bytevector (linklet-code linklet) (linklet-paths linklet) (linklet-format linklet))]) diff --git a/racket/src/cs/primitive/internal.ss b/racket/src/cs/primitive/internal.ss index 7a25b5bfdc..c5548e9847 100644 --- a/racket/src/cs/primitive/internal.ss +++ b/racket/src/cs/primitive/internal.ss @@ -5,7 +5,6 @@ (define-primitive-table internal-table [extract-procedure (known-constant)] [set-ctl-c-handler! (known-constant)] - [register-linklet-instantiate-continuation! (known-constant)] [impersonator-val (known-constant)] [impersonate-ref (known-constant)] [impersonate-set! (known-constant)] diff --git a/racket/src/cs/rumble.sls b/racket/src/cs/rumble.sls index d879dd7e61..5d94cf83a4 100644 --- a/racket/src/cs/rumble.sls +++ b/racket/src/cs/rumble.sls @@ -83,7 +83,7 @@ uncaught-exception-handler error-display-handler error-escape-handler - register-linklet-instantiate-continuation! ; not exported to Racket + linklet-instantiate-key ; not exported to Racket set-error-display-eprintf! ; not exported to Racket set-log-system-message! ; not exported to Racket diff --git a/racket/src/cs/rumble/error.ss b/racket/src/cs/rumble/error.ss index 05df920e6f..16ac5794aa 100644 --- a/racket/src/cs/rumble/error.ss +++ b/racket/src/cs/rumble/error.ss @@ -470,9 +470,7 @@ (define-thread-local link-instantiate-continuations (make-ephemeron-eq-hashtable)) ;; For `instantiate-linklet` to help report which linklet is being run: -(define (register-linklet-instantiate-continuation! k name) - (when name - (hashtable-set! link-instantiate-continuations k name))) +(define linklet-instantiate-key (gensym "linklet")) ;; Convert a contination to a list of function-name and ;; source information. Cache the result half-way up the @@ -481,7 +479,7 @@ (define (continuation->trace k) (call-with-values (lambda () - (let loop ([k k] [slow-k k] [move? #f]) + (let loop ([k k] [slow-k k] [move? #f] [attachments (continuation-next-attachments k)]) (cond [(or (not (#%$continuation? k)) (eq? k #%$null-continuation)) @@ -490,9 +488,10 @@ => (lambda (l) (values slow-k l))] [else - (let* ([name (or (let ([n (hashtable-ref link-instantiate-continuations - k - #f)]) + (let* ([next-attachments (continuation-next-attachments k)] + [name (or (let ([n (and (not (eq? attachments next-attachments)) + (pair? attachments) + (extract-mark-from-frame (car attachments) linklet-instantiate-key #f))]) (and n (string->symbol (format "body of ~a" n)))) (let* ([c (#%$continuation-return-code k)] @@ -513,7 +512,9 @@ (cons name src)))]) (#%$split-continuation k 0) (call-with-values - (lambda () (loop (#%$continuation-link k) (if move? (#%$continuation-link slow-k) slow-k) (not move?))) + (lambda () (loop (#%$continuation-link k) + (if move? (#%$continuation-link slow-k) slow-k) (not move?) + next-attachments)) (lambda (slow-k l) (let ([l (if desc (cons desc l)