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:
Matthew Flatt 2018-07-05 18:27:53 -06:00
parent 6a1232ee5a
commit b27ca8c6a9
3 changed files with 3168 additions and 3194 deletions

View File

@ -2721,6 +2721,21 @@ case of module-leve bindings; it doesn't cover local bindings.
(list #'module* #'stop)
#: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)

View File

@ -85,7 +85,6 @@
(define (expand-module s init-ctx enclosing-self
#:always-produce-compiled? [always-produce-compiled? #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-requires+provides [enclosing-r+p #f]
#:mpis-for-enclosing-reset [mpis-for-enclosing-reset #f]
@ -129,11 +128,7 @@
;; Initial require name provides the module's base scopes
(define initial-require-s (apply-module-scopes (m 'initial-require)))
(define all-scopes-s (if enclosing-all-scopes-stx
(apply-module-scopes
(syntax-shift-phase-level enclosing-all-scopes-stx
keep-enclosing-scope-at-phase))
initial-require-s))
(define all-scopes-s initial-require-s)
(define root-ctx (make-root-expand-context
#:self-mpi self
@ -1240,7 +1235,6 @@
(expand-submodule shifted-s self submod-ctx
#:is-star? #t
#:keep-enclosing-scope-at-phase neg-phase
#:enclosing-all-scopes-stx all-scopes-s
#:enclosing-requires+provides requires+provides
#:enclosing-is-cross-phase-persistent? enclosing-is-cross-phase-persistent?
#:mpis-to-reset mpis-to-reset
@ -1321,7 +1315,6 @@
#:keep-enclosing-scope-at-phase [keep-enclosing-scope-at-phase #f]
#:enclosing-requires+provides [enclosing-r+p #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
#:declared-submodule-names declared-submodule-names
#:compiled-submodules compiled-submodules
@ -1347,7 +1340,6 @@
self
#:always-produce-compiled? #t
#: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-is-cross-phase-persistent? enclosing-is-cross-phase-persistent?
#:mpis-for-enclosing-reset mpis-to-reset

File diff suppressed because it is too large Load Diff