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.
This commit is contained in:
Matthew Flatt 2019-04-24 14:58:15 -06:00
parent 688f03e208
commit fa1861869e
4 changed files with 13 additions and 13 deletions

View File

@ -676,9 +676,9 @@
[target-instance [target-instance
;; Instantiate into the given instance and return the ;; Instantiate into the given instance and return the
;; result of the linklet body: ;; result of the linklet body:
(call/cc (with-continuation-mark
(lambda (k) linklet-instantiate-key (instance-name target-instance)
(register-linklet-instantiate-continuation! k (instance-name target-instance)) (begin
(when (eq? 'lazy (linklet-preparation linklet)) (when (eq? 'lazy (linklet-preparation linklet))
;; Trigger lazy conversion of code from bytevector ;; Trigger lazy conversion of code from bytevector
(let ([code (eval-from-bytevector (linklet-code linklet) (linklet-paths linklet) (linklet-format linklet))]) (let ([code (eval-from-bytevector (linklet-code linklet) (linklet-paths linklet) (linklet-format linklet))])

View File

@ -5,7 +5,6 @@
(define-primitive-table internal-table (define-primitive-table internal-table
[extract-procedure (known-constant)] [extract-procedure (known-constant)]
[set-ctl-c-handler! (known-constant)] [set-ctl-c-handler! (known-constant)]
[register-linklet-instantiate-continuation! (known-constant)]
[impersonator-val (known-constant)] [impersonator-val (known-constant)]
[impersonate-ref (known-constant)] [impersonate-ref (known-constant)]
[impersonate-set! (known-constant)] [impersonate-set! (known-constant)]

View File

@ -83,7 +83,7 @@
uncaught-exception-handler uncaught-exception-handler
error-display-handler error-display-handler
error-escape-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-error-display-eprintf! ; not exported to Racket
set-log-system-message! ; not exported to Racket set-log-system-message! ; not exported to Racket

View File

@ -470,9 +470,7 @@
(define-thread-local link-instantiate-continuations (make-ephemeron-eq-hashtable)) (define-thread-local link-instantiate-continuations (make-ephemeron-eq-hashtable))
;; For `instantiate-linklet` to help report which linklet is being run: ;; For `instantiate-linklet` to help report which linklet is being run:
(define (register-linklet-instantiate-continuation! k name) (define linklet-instantiate-key (gensym "linklet"))
(when name
(hashtable-set! link-instantiate-continuations k name)))
;; Convert a contination to a list of function-name and ;; Convert a contination to a list of function-name and
;; source information. Cache the result half-way up the ;; source information. Cache the result half-way up the
@ -481,7 +479,7 @@
(define (continuation->trace k) (define (continuation->trace k)
(call-with-values (call-with-values
(lambda () (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 (cond
[(or (not (#%$continuation? k)) [(or (not (#%$continuation? k))
(eq? k #%$null-continuation)) (eq? k #%$null-continuation))
@ -490,9 +488,10 @@
=> (lambda (l) => (lambda (l)
(values slow-k l))] (values slow-k l))]
[else [else
(let* ([name (or (let ([n (hashtable-ref link-instantiate-continuations (let* ([next-attachments (continuation-next-attachments k)]
k [name (or (let ([n (and (not (eq? attachments next-attachments))
#f)]) (pair? attachments)
(extract-mark-from-frame (car attachments) linklet-instantiate-key #f))])
(and n (and n
(string->symbol (format "body of ~a" n)))) (string->symbol (format "body of ~a" n))))
(let* ([c (#%$continuation-return-code k)] (let* ([c (#%$continuation-return-code k)]
@ -513,7 +512,9 @@
(cons name src)))]) (cons name src)))])
(#%$split-continuation k 0) (#%$split-continuation k 0)
(call-with-values (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) (lambda (slow-k l)
(let ([l (if desc (let ([l (if desc
(cons desc l) (cons desc l)