expander: fix tracking of submodule base scopes
When expanding a `(module* _name #f ...)` submodule, accumulate all module scopes on the `#f` and use the `#f` for a reexpansion. Attempting to start each time from the enclosing module's scope loses scopes that were generated from previous expansions. One consequence of losind a scope is that an original definition may appear to be macro-introduced, and the defined variable may become inaccessible in the module's namespace.
This commit is contained in:
parent
6a1232ee5a
commit
b27ca8c6a9
|
@ -2721,6 +2721,21 @@ case of module-leve bindings; it doesn't cover local bindings.
|
||||||
(list #'module* #'stop)
|
(list #'module* #'stop)
|
||||||
#:extend-stop-ids? #f)))
|
#:extend-stop-ids? #f)))
|
||||||
|
|
||||||
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Make sure that re-expansion of a `(module _name #f ....)`
|
||||||
|
;; submodule doesn't lose track of the base scope of the
|
||||||
|
;; submodule --- which would, for example, cause a definition
|
||||||
|
;; of `x` in the original submodule to be mapped to an
|
||||||
|
;; inaccessible `x.1`.
|
||||||
|
|
||||||
|
(parameterize ([current-namespace (make-base-namespace)])
|
||||||
|
(eval-syntax (expand '(module m racket/base
|
||||||
|
(require syntax/location)
|
||||||
|
(module* check #f
|
||||||
|
(define x 42)))))
|
||||||
|
(dynamic-require '(submod 'm check) #f)
|
||||||
|
(eval 'x (module->namespace '(submod 'm check))))
|
||||||
|
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(report-errs)
|
(report-errs)
|
||||||
|
|
|
@ -85,7 +85,6 @@
|
||||||
(define (expand-module s init-ctx enclosing-self
|
(define (expand-module s init-ctx enclosing-self
|
||||||
#:always-produce-compiled? [always-produce-compiled? #f]
|
#:always-produce-compiled? [always-produce-compiled? #f]
|
||||||
#:keep-enclosing-scope-at-phase [keep-enclosing-scope-at-phase #f]
|
#:keep-enclosing-scope-at-phase [keep-enclosing-scope-at-phase #f]
|
||||||
#:enclosing-all-scopes-stx [enclosing-all-scopes-stx #f]
|
|
||||||
#:enclosing-is-cross-phase-persistent? [enclosing-is-cross-phase-persistent? #f]
|
#:enclosing-is-cross-phase-persistent? [enclosing-is-cross-phase-persistent? #f]
|
||||||
#:enclosing-requires+provides [enclosing-r+p #f]
|
#:enclosing-requires+provides [enclosing-r+p #f]
|
||||||
#:mpis-for-enclosing-reset [mpis-for-enclosing-reset #f]
|
#:mpis-for-enclosing-reset [mpis-for-enclosing-reset #f]
|
||||||
|
@ -129,11 +128,7 @@
|
||||||
|
|
||||||
;; Initial require name provides the module's base scopes
|
;; Initial require name provides the module's base scopes
|
||||||
(define initial-require-s (apply-module-scopes (m 'initial-require)))
|
(define initial-require-s (apply-module-scopes (m 'initial-require)))
|
||||||
(define all-scopes-s (if enclosing-all-scopes-stx
|
(define all-scopes-s initial-require-s)
|
||||||
(apply-module-scopes
|
|
||||||
(syntax-shift-phase-level enclosing-all-scopes-stx
|
|
||||||
keep-enclosing-scope-at-phase))
|
|
||||||
initial-require-s))
|
|
||||||
|
|
||||||
(define root-ctx (make-root-expand-context
|
(define root-ctx (make-root-expand-context
|
||||||
#:self-mpi self
|
#:self-mpi self
|
||||||
|
@ -1240,7 +1235,6 @@
|
||||||
(expand-submodule shifted-s self submod-ctx
|
(expand-submodule shifted-s self submod-ctx
|
||||||
#:is-star? #t
|
#:is-star? #t
|
||||||
#:keep-enclosing-scope-at-phase neg-phase
|
#:keep-enclosing-scope-at-phase neg-phase
|
||||||
#:enclosing-all-scopes-stx all-scopes-s
|
|
||||||
#:enclosing-requires+provides requires+provides
|
#:enclosing-requires+provides requires+provides
|
||||||
#:enclosing-is-cross-phase-persistent? enclosing-is-cross-phase-persistent?
|
#:enclosing-is-cross-phase-persistent? enclosing-is-cross-phase-persistent?
|
||||||
#:mpis-to-reset mpis-to-reset
|
#:mpis-to-reset mpis-to-reset
|
||||||
|
@ -1321,7 +1315,6 @@
|
||||||
#:keep-enclosing-scope-at-phase [keep-enclosing-scope-at-phase #f]
|
#:keep-enclosing-scope-at-phase [keep-enclosing-scope-at-phase #f]
|
||||||
#:enclosing-requires+provides [enclosing-r+p #f]
|
#:enclosing-requires+provides [enclosing-r+p #f]
|
||||||
#:enclosing-is-cross-phase-persistent? [enclosing-is-cross-phase-persistent? #f]
|
#:enclosing-is-cross-phase-persistent? [enclosing-is-cross-phase-persistent? #f]
|
||||||
#:enclosing-all-scopes-stx [enclosing-all-scopes-stx #f]
|
|
||||||
#:mpis-to-reset mpis-to-reset
|
#:mpis-to-reset mpis-to-reset
|
||||||
#:declared-submodule-names declared-submodule-names
|
#:declared-submodule-names declared-submodule-names
|
||||||
#:compiled-submodules compiled-submodules
|
#:compiled-submodules compiled-submodules
|
||||||
|
@ -1347,7 +1340,6 @@
|
||||||
self
|
self
|
||||||
#:always-produce-compiled? #t
|
#:always-produce-compiled? #t
|
||||||
#:keep-enclosing-scope-at-phase keep-enclosing-scope-at-phase
|
#:keep-enclosing-scope-at-phase keep-enclosing-scope-at-phase
|
||||||
#:enclosing-all-scopes-stx enclosing-all-scopes-stx
|
|
||||||
#:enclosing-requires+provides enclosing-r+p
|
#:enclosing-requires+provides enclosing-r+p
|
||||||
#:enclosing-is-cross-phase-persistent? enclosing-is-cross-phase-persistent?
|
#:enclosing-is-cross-phase-persistent? enclosing-is-cross-phase-persistent?
|
||||||
#:mpis-for-enclosing-reset mpis-to-reset
|
#:mpis-for-enclosing-reset mpis-to-reset
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user