From 053734c4c8c3e00d3faa47ad153f61c5bb18cdab Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 19 Aug 2011 03:34:56 -0600 Subject: [PATCH] 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: 7eb2042bd9296235ae425fcc56a05931a65d47d4 --- collects/compiler/decompile.rkt | 14 +++++++++----- collects/compiler/zo-marshal.rkt | 4 ++-- collects/compiler/zo-parse.rkt | 7 +++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/collects/compiler/decompile.rkt b/collects/compiler/decompile.rkt index ca9b60c7a5..903e6843ef 100644 --- a/collects/compiler/decompile.rkt +++ b/collects/compiler/decompile.rkt @@ -186,7 +186,7 @@ [(struct def-values (ids rhs)) `(define-values ,(map (lambda (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)])) ids) ,(decompile-expr rhs globs stack closed))] @@ -250,10 +250,14 @@ (match expr [(struct toplevel (depth pos const? ready?)) (let ([id (list-ref/protect (glob-desc-vars globs) pos 'toplevel)]) - (if (or no-check? const? ready?) - id - `(#%checked ,id)))])) - + (cond + [no-check? 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) (match expr [(struct toplevel (depth pos const? ready?)) diff --git a/collects/compiler/zo-marshal.rkt b/collects/compiler/zo-marshal.rkt index 124b01c48c..e435a97080 100644 --- a/collects/compiler/zo-marshal.rkt +++ b/collects/compiler/zo-marshal.rkt @@ -554,8 +554,8 @@ (if (or const? ready?) (cons pos (bitwise-ior - (if const? #x1 0) - (if ready? #x2 0))) + (if const? #x2 0) + (if ready? #x1 0))) pos)) out)] [(struct topsyntax (depth pos midpt)) diff --git a/collects/compiler/zo-parse.rkt b/collects/compiler/zo-parse.rkt index d1aaf68478..3c559ec62b 100644 --- a/collects/compiler/zo-parse.rkt +++ b/collects/compiler/zo-parse.rkt @@ -33,10 +33,13 @@ ;; Bytecode unmarshalers for various forms (define (read-toplevel v) - (define SCHEME_TOPLEVEL_CONST #x01) - (define SCHEME_TOPLEVEL_READY #x02) + (define SCHEME_TOPLEVEL_CONST #x02) + (define SCHEME_TOPLEVEL_READY #x01) (match v [(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 (positive? (bitwise-and flags SCHEME_TOPLEVEL_CONST)) (positive? (bitwise-and flags SCHEME_TOPLEVEL_READY)))]