expander: avoid equal?-based hash table for module cache

Since a thread can be terminated while accessing the cache, it
can't be an `equal?`-based table where the lock can get lost.
This commit is contained in:
Matthew Flatt 2018-03-08 16:36:16 -07:00
parent e4e17db51d
commit 3cf2138841
2 changed files with 8 additions and 4 deletions

View File

@ -9,7 +9,7 @@
module-cache-set!
module-cache-ref)
(define module-cache (make-weak-hash))
(define module-cache (make-weak-hasheq))
(define (make-module-cache-key hash-code)
;; The result is preserved to retain the cache entry, and
@ -20,7 +20,10 @@
;; relative to the enclosing module, and that part of
;; the syntax object is unmarshaled once and used for
;; all instances of the module.
(and hash-code (list hash-code (current-load-relative-directory))))
(and hash-code
;; Encode as a symbol so we can use an eq?-based hash table
;; (i.e., explot the low-level lock on the symbol table)
(string->symbol (format "~s" (list hash-code (current-load-relative-directory))))))
(define (module-cache-set! key proc)
(hash-set! module-cache key (make-ephemeron key proc)))

View File

@ -33804,10 +33804,11 @@ static const char *startup_source =
"(let-values(((or-part_265)(if insp_11(inspector-superior? insp_11 guard-insp_4) #f)))"
"(if or-part_265 or-part_265(inspector-superior?(current-code-inspector) guard-insp_4)))))"
"(let-values() #t))))))))))"
"(define-values(module-cache)(make-weak-hash))"
"(define-values(module-cache)(make-weak-hasheq))"
"(define-values"
"(make-module-cache-key)"
"(lambda(hash-code_4)(begin(if hash-code_4(list hash-code_4(current-load-relative-directory)) #f))))"
"(lambda(hash-code_4)"
" (begin (if hash-code_4 (string->symbol (format \"~s\" (list hash-code_4 (current-load-relative-directory)))) #f))))"
"(define-values"
"(module-cache-set!)"
"(lambda(key_11 proc_9)(begin(hash-set! module-cache key_11(make-ephemeron key_11 proc_9)))))"