fix compiler handling of top-/module-level constants

The JIT and bytecode compiler disagreed on the definition of
"constant". Now there are two levels: "constant" means constant across
all instantiations, and "fixed" means constant for a given instantation.
The JIT uses this distinction to generate direct-primitive calls
or not. (Without the distinction, a direct jump to `reverse' could
be wrong, because `racket/base' might get instantiated with the
JIT disabled or not.)

Also, fixed a bug in the JIT's `vector-set!' code in the case that
the target vector is a top-/module-level reference that is ready,
fixed, or constant.

original commit: 7eb2042bd9
This commit is contained in:
Matthew Flatt 2011-08-19 03:34:56 -06:00
parent eec721ff4c
commit 053734c4c8
3 changed files with 16 additions and 9 deletions

View File

@ -186,7 +186,7 @@
[(struct def-values (ids rhs)) [(struct def-values (ids rhs))
`(define-values ,(map (lambda (tl) `(define-values ,(map (lambda (tl)
(match tl (match tl
[(struct toplevel (depth pos const? mutated?)) [(struct toplevel (depth pos const? set-const?))
(list-ref/protect (glob-desc-vars globs) pos 'def-vals)])) (list-ref/protect (glob-desc-vars globs) pos 'def-vals)]))
ids) ids)
,(decompile-expr rhs globs stack closed))] ,(decompile-expr rhs globs stack closed))]
@ -250,9 +250,13 @@
(match expr (match expr
[(struct toplevel (depth pos const? ready?)) [(struct toplevel (depth pos const? ready?))
(let ([id (list-ref/protect (glob-desc-vars globs) pos 'toplevel)]) (let ([id (list-ref/protect (glob-desc-vars globs) pos 'toplevel)])
(if (or no-check? const? ready?) (cond
id [no-check? id]
`(#%checked ,id)))])) [(and (not const?) (not ready?))
`(#%checked ,id)]
#;[(and const? ready?) `(#%const ,id)]
#;[const? `(#%iconst ,id)]
[else id]))]))
(define (decompile-expr expr globs stack closed) (define (decompile-expr expr globs stack closed)
(match expr (match expr

View File

@ -554,8 +554,8 @@
(if (or const? ready?) (if (or const? ready?)
(cons pos (cons pos
(bitwise-ior (bitwise-ior
(if const? #x1 0) (if const? #x2 0)
(if ready? #x2 0))) (if ready? #x1 0)))
pos)) pos))
out)] out)]
[(struct topsyntax (depth pos midpt)) [(struct topsyntax (depth pos midpt))

View File

@ -33,10 +33,13 @@
;; Bytecode unmarshalers for various forms ;; Bytecode unmarshalers for various forms
(define (read-toplevel v) (define (read-toplevel v)
(define SCHEME_TOPLEVEL_CONST #x01) (define SCHEME_TOPLEVEL_CONST #x02)
(define SCHEME_TOPLEVEL_READY #x02) (define SCHEME_TOPLEVEL_READY #x01)
(match v (match v
[(cons depth (cons pos flags)) [(cons depth (cons pos flags))
;; In the VM, the two flag bits are actually interpreted
;; as a number when the toplevel is a reference, but we
;; interpret the bits as flags here for backward compatibility.
(make-toplevel depth pos (make-toplevel depth pos
(positive? (bitwise-and flags SCHEME_TOPLEVEL_CONST)) (positive? (bitwise-and flags SCHEME_TOPLEVEL_CONST))
(positive? (bitwise-and flags SCHEME_TOPLEVEL_READY)))] (positive? (bitwise-and flags SCHEME_TOPLEVEL_READY)))]