cs: delayed parsing of cross-linklet info

Avoid parsing cross-linklet optimization information until it is
needed. This change also avoids a problem with saving hash codes
that are platform-specific.
This commit is contained in:
Matthew Flatt 2019-03-09 08:13:03 -07:00
parent b7e0d52b96
commit e46e791724
6 changed files with 52 additions and 20 deletions

View File

@ -12,7 +12,7 @@
(define collection 'multi)
(define version "7.2.0.7")
(define version "7.2.0.8")
(define deps `("racket-lib"
["racket" #:version ,version]))

View File

@ -429,11 +429,11 @@
format ; 'compile or 'interpret (where the latter may have compiled internal parts)
(mutable preparation) ; 'faslable, 'faslable-strict, 'callable, 'lazy, or (cons 'cross <machine>)
importss-abi ; ABI for each import, in parallel to `importss`
exports-info ; hash(sym -> known) for info about each export; see "known.rkt"
(mutable exports-info) ; hash(sym -> known) for info about export; see "known.rkt"; unfasl on demand
name ; name of the linklet (for debugging purposes)
importss ; list of list of import symbols
exports) ; list of export symbol-or-pair, pair is (cons export-symbol src-symbol)
(nongenerative #{linklet Zuquy0g9bh5vmeespyap4g-1}))
(nongenerative #{linklet Zuquy0g9bh5vmeespyap4g-2}))
(define (set-linklet-code linklet code preparation)
(make-linklet code
@ -468,6 +468,30 @@
(linklet-importss linklet)
(linklet-exports linklet)))
(define (linklet-pack-exports-info! l)
(let ([info (linklet-exports-info l)])
(when (hash? info)
(let ([new-info
(cond
[(zero? (hash-count info)) #f]
[else
(let-values ([(o get) (open-bytevector-output-port)])
;; convert to a hashtable so the fasled form is compact and
;; doesn't have hash codes:
(fasl-write (hash->eq-hashtable (hash-copy info)) o)
(get))])])
(linklet-exports-info-set! l new-info)))))
(define (linklet-unpack-exports-info! l)
(let ([info (linklet-exports-info l)])
(unless (hash? info)
(let ([new-info
(cond
[(not info) (hasheq)]
[else
(eq-hashtable->hash (fasl-read (open-bytevector-input-port info)))])])
(linklet-exports-info-set! l new-info)))))
(define compile-linklet
(case-lambda
[(c) (compile-linklet c #f #f #f '(serializable))]
@ -602,6 +626,7 @@
(let-values ([(lnk/inst more-import-keys) (get-import key)])
(cond
[(linklet? lnk/inst)
(linklet-unpack-exports-info! lnk/inst)
(values (linklet-exports-info lnk/inst)
;; No conversion needed:
#f

View File

@ -20,21 +20,25 @@
[(not i) (values ht cross-machine)]
[else
(let-values ([(key v) (hash-iterate-key+value orig-ht i)])
(let ([new-ht (if (and (linklet? v)
(pair? (linklet-paths v)))
(hash-set ht key
(adjust-cross-perparation
(set-linklet-paths
v
(map path->compiled-path
(linklet-paths v)))))
ht)])
(loop (hash-iterate-next orig-ht i)
new-ht
(or cross-machine
(and (linklet? v)
(let ([prep (linklet-preparation v)])
(and (pair? prep) (cdr prep))))))))]))))
(let ([new-v (if (and (linklet? v)
(pair? (linklet-paths v)))
(adjust-cross-perparation
(set-linklet-paths
v
(map path->compiled-path
(linklet-paths v))))
v)])
(when (linklet? new-v)
(linklet-pack-exports-info! new-v))
(let ([new-ht (if (eq? v new-v)
ht
(hash-set ht key new-v))])
(loop (hash-iterate-next orig-ht i)
new-ht
(or cross-machine
(and (linklet? v)
(let ([prep (linklet-preparation v)])
(and (pair? prep) (cdr prep)))))))))]))))
;; Before fasl conversion, change 'cross to 'faslable
(define (adjust-cross-perparation l)

View File

@ -274,6 +274,7 @@
hash-count
hash-keys-subset?
eq-hashtable->hash ; not exported to racket
hash->eq-hashtable ; not exported to racket
datum-intern-literal
set-intern-regexp?! ; not exported to racket

View File

@ -30,6 +30,8 @@
(define (eq-hashtable->hash ht)
(create-mutable-hash ht 'eq?))
(define (hash->eq-hashtable ht)
(mutable-hash-ht ht))
(define make-weak-hasheq
(case-lambda

View File

@ -13,12 +13,12 @@
consistently.)
*/
#define MZSCHEME_VERSION "7.2.0.7"
#define MZSCHEME_VERSION "7.2.0.8"
#define MZSCHEME_VERSION_X 7
#define MZSCHEME_VERSION_Y 2
#define MZSCHEME_VERSION_Z 0
#define MZSCHEME_VERSION_W 7
#define MZSCHEME_VERSION_W 8
#define MZSCHEME_VERSION_MAJOR ((MZSCHEME_VERSION_X * 100) + MZSCHEME_VERSION_Y)
#define MZSCHEME_VERSION_MINOR ((MZSCHEME_VERSION_Z * 1000) + MZSCHEME_VERSION_W)