Skip to content
This repository was archived by the owner on Sep 13, 2019. It is now read-only.

Commit 40db7af

Browse files
committed
expander: add missing environment-prep for lifted requires
Also, add checking for a parse phase that must not trigger macros.
1 parent 66d0a29 commit 40db7af

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

racket/src/expander/expand/context.rkt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
requires+provides ; enclosing module's requires+provides during `provide`
6565
* name ; #f or identifier to name the expression
6666
observer ; logging observer (for the macro debugger)
67-
for-serializable?)) ; accumulate submodules as serializable?
67+
for-serializable? ; accumulate submodules as serializable?
68+
should-not-encounter-macros?)) ; #t when "expanding" to parse
6869

6970
(define (make-expand-context ns
7071
#:to-parsed? [to-parsed? #f]
@@ -107,7 +108,8 @@
107108
#f ; requires+provides
108109
#f ; name
109110
(and observable? (current-expand-observe))
110-
for-serializable?))
111+
for-serializable?
112+
#f))
111113

112114
(define (copy-root-expand-context ctx root-ctx)
113115
(struct*-copy expand-context ctx
@@ -192,4 +194,5 @@
192194
(define (as-to-parsed-context ctx)
193195
(struct*-copy expand-context ctx
194196
[to-parsed? #t]
195-
[observer #f]))
197+
[observer #f]
198+
[should-not-encounter-macros? #t]))

racket/src/expander/expand/local-expand.rkt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"../syntax/scope.rkt"
77
"../syntax/binding.rkt"
88
"../namespace/core.rkt"
9+
"../namespace/module.rkt"
910
"context.rkt"
1011
"main.rkt"
1112
"syntax-local.rkt"
@@ -107,6 +108,8 @@
107108
#:to-parsed-ok? to-parsed-ok?
108109
#:track-to-be-defined? track-to-be-defined?))
109110

111+
(namespace-visit-available-modules! (expand-context-namespace ctx) phase)
112+
110113
(log-expand local-ctx 'enter-local s)
111114
(define input-s (add-intdef-scopes (flip-introduction-scopes s ctx) intdefs))
112115

racket/src/expander/expand/main.rkt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@
270270
(define adj-s (avoid-current-expand-context (substitute-alternate-id s id) t ctx))
271271
(log-expand ctx 'exit-macro s)
272272
(expand adj-s ctx)]
273+
[(expand-context-should-not-encounter-macros? ctx)
274+
(raise-syntax-error #f
275+
"encountered a macro binding in form that should be fully expanded"
276+
s)]
273277
[else
274278
(log-expand* ctx #:when (and (expand-context-only-immediate? ctx)
275279
(not (rename-transformer? t)))

racket/src/expander/expand/module.rkt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@
791791
(define-values (exp-rhs parsed-rhs vals)
792792
(expand+eval-for-syntaxes-binding (m 'rhs) ids
793793
(struct*-copy expand-context partial-body-ctx
794+
[lifts #f]
795+
;; require lifts ok, others disallowed
796+
[module-lifts #f]
797+
[to-module-lifts #f]
794798
[need-eventually-defined need-eventually-defined])
795799
#:log-next? #f))
796800
;; Install transformers in the namespace for expansion:
@@ -1290,7 +1294,7 @@
12901294
#:modules-being-compiled modules-being-compiled)
12911295
(unless is-star?
12921296
(log-expand* ctx ['enter-prim s] [(if is-star? 'prim-submodule* 'prim-submodule)]))
1293-
1297+
12941298
;; Register name and check for duplicates
12951299
(define-match m s '(module name . _))
12961300
(define name (syntax-e (m 'name)))

racket/src/expander/expand/syntax-local.rkt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
(check who exact-nonnegative-integer? n)
213213
(define ctx (get-current-expand-context who))
214214
(define lifts (expand-context-lifts ctx))
215+
(unless lifts (raise-arguments-error who "no lift target"))
215216
(define counter (root-expand-context-counter ctx))
216217
(define ids (for/list ([i (in-range n)])
217218
(set-box! counter (add1 (unbox counter)))
@@ -264,6 +265,7 @@
264265
(more-checks)
265266
(define ctx (get-current-expand-context who))
266267
(define lift-ctx (get-lift-ctx ctx))
268+
(unless lift-ctx (raise-arguments-error who "no lift target"))
267269
(define phase (expand-context-phase ctx)) ; we're currently at this phase
268270
(define wrt-phase (get-wrt-phase lift-ctx)) ; lift context is at this phase
269271
(define added-s (if intro? (flip-introduction-scopes s ctx) s))
@@ -294,6 +296,8 @@
294296
#:post-wrap
295297
(lambda (s phase require-lift-ctx)
296298
(wrap-form '#%require (add-scope s sc) phase))))
299+
(namespace-visit-available-modules! (expand-context-namespace ctx)
300+
(expand-context-phase ctx))
297301
(define result-s (add-scope use-s sc))
298302
(log-expand ctx 'lift-require added-s use-s result-s)
299303
result-s)

0 commit comments

Comments
 (0)