From aa68692b37ef6558cc1660e7d5073943389e12c1 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 2 Jul 2012 09:53:19 -0600 Subject: [PATCH] allow `begin' wrapper on a submodule to re-expand Closes PR 12835 --- collects/scribblings/reference/syntax.scrbl | 5 +++-- collects/tests/racket/submodule.rktl | 13 +++++++++++++ src/racket/src/module.c | 9 +++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/collects/scribblings/reference/syntax.scrbl b/collects/scribblings/reference/syntax.scrbl index be90676988..7518c302a2 100644 --- a/collects/scribblings/reference/syntax.scrbl +++ b/collects/scribblings/reference/syntax.scrbl @@ -269,8 +269,9 @@ form. See also @racket[module-compiled-language-info], If a @racket[module] form has a single body @racket[form] and if the form is a @racket[#%plain-module-begin] form, then the body @racket[form] is traversed to find @racket[module] and -@racket[module*] forms that are either immediate or under -@racket[begin-for-syntax]. (That is, the body is search before adding +@racket[module*] forms that are either immediate, under +@racket[begin], or under @racket[begin-for-syntax]. (That is, the +body is searched before adding any lexical context due to the module's initial @racket[module-path] import.) Each such module form is given a @indexed-racket['submodule] @tech{syntax property} that whose value is the initial module form. diff --git a/collects/tests/racket/submodule.rktl b/collects/tests/racket/submodule.rktl index 6c5bcc9014..13c09df857 100644 --- a/collects/tests/racket/submodule.rktl +++ b/collects/tests/racket/submodule.rktl @@ -356,6 +356,19 @@ (require (submod ".." X)) (define y (add1 x))))))) +;; Check that we can wrap a `begin' around a submodule: +(parameterize ([current-namespace (make-base-namespace)]) + (define m (expand + '(module m racket/base + (module sub racket/base + (require (for-syntax racket/base)) + (define-syntax (sym-app stx) + (syntax-case stx () + [() 10])))))) + (eval (syntax-case m () + [(md m r/b (m-b mod)) + #`(md m r/b (m-b (begin 10 mod)))]))) + ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; `begin-for-syntax' doesn't affect `module' with non-#f language: diff --git a/src/racket/src/module.c b/src/racket/src/module.c index ef1a55a2a7..4258d0d29b 100644 --- a/src/racket/src/module.c +++ b/src/racket/src/module.c @@ -6402,6 +6402,15 @@ Scheme_Object *do_annotate_submodules(Scheme_Object *fm, int phase) changed = 1; a = v; } + } else if (scheme_stx_module_eq3(scheme_begin_stx, v, + scheme_make_integer(0), scheme_make_integer(phase), + NULL)) { + /* found `begin' */ + v = do_annotate_submodules(a, phase); + if (!SAME_OBJ(v, a)) { + changed = 1; + a = v; + } } } }