expand and expand-to-top-form unset observer parameter
This change means that if a macro transformer calls expand (not local-expand, but top-level expand), the macro debugger won't receive the inner expand's events. Previously, the macro debugger tried to parse and then discard the inner expand, but that was brittle and complicated the grammar.
This commit is contained in:
parent
ceee75b5ce
commit
19df146ccf
File diff suppressed because it is too large
Load Diff
|
@ -57,7 +57,7 @@
|
||||||
(per-top-level s ns
|
(per-top-level s ns
|
||||||
#:single (lambda (s ns tail?)
|
#:single (lambda (s ns tail?)
|
||||||
(eval-compiled (compile s ns) ns tail?))
|
(eval-compiled (compile s ns) ns tail?))
|
||||||
#:observable? #f)]))
|
#:observer #f)]))
|
||||||
|
|
||||||
(define (eval-compiled c ns [as-tail? #t])
|
(define (eval-compiled c ns [as-tail? #t])
|
||||||
(cond
|
(cond
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
serializable?
|
serializable?
|
||||||
to-source?)))
|
to-source?)))
|
||||||
#:combine append
|
#:combine append
|
||||||
#:observable? #f)]))
|
#:observer #f)]))
|
||||||
(if (and (= 1 (length cs))
|
(if (and (= 1 (length cs))
|
||||||
(not (compiled-multiple-top? (car cs))))
|
(not (compiled-multiple-top? (car cs))))
|
||||||
(car cs)
|
(car cs)
|
||||||
|
@ -132,19 +132,21 @@
|
||||||
;; [Don't use keyword arguments here, because the function is
|
;; [Don't use keyword arguments here, because the function is
|
||||||
;; exported for use by an embedding runtime system.]
|
;; exported for use by an embedding runtime system.]
|
||||||
(define (expand s [ns (current-namespace)] [observable? #f] [to-parsed? #f] [serializable? #f])
|
(define (expand s [ns (current-namespace)] [observable? #f] [to-parsed? #f] [serializable? #f])
|
||||||
(when observable? (log-expand-start-top))
|
(define observer (and observable? (current-expand-observe)))
|
||||||
(per-top-level s ns
|
(when observer (...log-expand observer ['start-top]))
|
||||||
#:single (lambda (s ns as-tail?) (expand-single s ns observable? to-parsed? serializable?))
|
(parameterize ((current-expand-observe #f))
|
||||||
#:combine cons
|
(per-top-level s ns
|
||||||
#:wrap re-pair
|
#:single (lambda (s ns as-tail?) (expand-single s ns observer to-parsed? serializable?))
|
||||||
#:observable? observable?))
|
#:combine cons
|
||||||
|
#:wrap re-pair
|
||||||
|
#:observer observer)))
|
||||||
|
|
||||||
(define (expand-single s ns observable? to-parsed? serializable?)
|
(define (expand-single s ns observer to-parsed? serializable?)
|
||||||
(define rebuild-s (keep-properties-only s))
|
(define rebuild-s (keep-properties-only s))
|
||||||
(define ctx (make-expand-context ns
|
(define ctx (make-expand-context ns
|
||||||
#:to-parsed? to-parsed?
|
#:to-parsed? to-parsed?
|
||||||
#:for-serializable? serializable?
|
#:for-serializable? serializable?
|
||||||
#:observable? observable?))
|
#:observer observer))
|
||||||
(define-values (require-lifts lifts exp-s) (expand-capturing-lifts s ctx))
|
(define-values (require-lifts lifts exp-s) (expand-capturing-lifts s ctx))
|
||||||
(cond
|
(cond
|
||||||
[(and (null? require-lifts) (null? lifts)) exp-s]
|
[(and (null? require-lifts) (null? lifts)) exp-s]
|
||||||
|
@ -153,14 +155,14 @@
|
||||||
lifts
|
lifts
|
||||||
exp-s rebuild-s
|
exp-s rebuild-s
|
||||||
#:adjust-form (lambda (form)
|
#:adjust-form (lambda (form)
|
||||||
(expand-single form ns observable? to-parsed? serializable?)))]
|
(expand-single form ns observer to-parsed? serializable?)))]
|
||||||
[else
|
[else
|
||||||
(log-top-lift-begin-before ctx require-lifts lifts exp-s ns)
|
(log-top-lift-begin-before ctx require-lifts lifts exp-s ns)
|
||||||
(define new-s
|
(define new-s
|
||||||
(wrap-lifts-as-begin (append require-lifts lifts)
|
(wrap-lifts-as-begin (append require-lifts lifts)
|
||||||
#:adjust-form (lambda (form)
|
#:adjust-form (lambda (form)
|
||||||
(log-expand ctx 'next)
|
(log-expand ctx 'next)
|
||||||
(expand-single form ns observable? to-parsed? serializable?))
|
(expand-single form ns observer to-parsed? serializable?))
|
||||||
#:adjust-body (lambda (form)
|
#:adjust-body (lambda (form)
|
||||||
(cond
|
(cond
|
||||||
[to-parsed? form]
|
[to-parsed? form]
|
||||||
|
@ -169,7 +171,7 @@
|
||||||
;; This re-expansion should be unnecessary, but we do it
|
;; This re-expansion should be unnecessary, but we do it
|
||||||
;; for a kind of consistentcy with `expand/capture-lifts`
|
;; for a kind of consistentcy with `expand/capture-lifts`
|
||||||
;; and for expansion observers
|
;; and for expansion observers
|
||||||
(expand-single form ns observable? to-parsed? serializable?)]))
|
(expand-single form ns observer to-parsed? serializable?)]))
|
||||||
exp-s
|
exp-s
|
||||||
(namespace-phase ns)))
|
(namespace-phase ns)))
|
||||||
(log-top-begin-after ctx new-s)
|
(log-top-begin-after ctx new-s)
|
||||||
|
@ -181,11 +183,11 @@
|
||||||
#:combine cons
|
#:combine cons
|
||||||
#:wrap re-pair
|
#:wrap re-pair
|
||||||
#:just-once? #t
|
#:just-once? #t
|
||||||
#:observable? #t))
|
#:observer #f))
|
||||||
|
|
||||||
(define (expand-single-once s ns)
|
(define (expand-single-once s ns)
|
||||||
(define-values (require-lifts lifts exp-s)
|
(define-values (require-lifts lifts exp-s)
|
||||||
(expand-capturing-lifts s (struct*-copy expand-context (make-expand-context ns #:observable? #t)
|
(expand-capturing-lifts s (struct*-copy expand-context (make-expand-context ns)
|
||||||
[just-once? #t])))
|
[just-once? #t])))
|
||||||
(cond
|
(cond
|
||||||
[(and (null? require-lifts) (null? lifts)) exp-s]
|
[(and (null? require-lifts) (null? lifts)) exp-s]
|
||||||
|
@ -197,11 +199,13 @@
|
||||||
(define (expand-to-top-form s [ns (current-namespace)])
|
(define (expand-to-top-form s [ns (current-namespace)])
|
||||||
;; Use `per-top-level` for immediate expansion and lift handling,
|
;; Use `per-top-level` for immediate expansion and lift handling,
|
||||||
;; but `#:single #f` makes it return immediately
|
;; but `#:single #f` makes it return immediately
|
||||||
(log-expand-start-top)
|
(define observer (current-expand-observe))
|
||||||
(per-top-level s ns
|
(when observer (...log-expand observer ['start-top]))
|
||||||
#:single #f
|
(parameterize ((current-expand-observe #f))
|
||||||
#:quick-immediate? #f
|
(per-top-level s ns
|
||||||
#:observable? #t))
|
#:single #f
|
||||||
|
#:quick-immediate? #f
|
||||||
|
#:observer observer)))
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
@ -215,9 +219,9 @@
|
||||||
#:just-once? [just-once? #f] ; single expansion step
|
#:just-once? [just-once? #f] ; single expansion step
|
||||||
#:quick-immediate? [quick-immediate? #t]
|
#:quick-immediate? [quick-immediate? #t]
|
||||||
#:serializable? [serializable? #f] ; for module+submodule expansion
|
#:serializable? [serializable? #f] ; for module+submodule expansion
|
||||||
#:observable? observable?)
|
#:observer observer)
|
||||||
(define s (maybe-intro given-s ns))
|
(define s (maybe-intro given-s ns))
|
||||||
(define ctx (make-expand-context ns #:observable? observable?))
|
(define ctx (make-expand-context ns #:observer observer))
|
||||||
(define phase (namespace-phase ns))
|
(define phase (namespace-phase ns))
|
||||||
(let loop ([s s] [phase phase] [ns ns] [as-tail? #t])
|
(let loop ([s s] [phase phase] [ns ns] [as-tail? #t])
|
||||||
(define tl-ctx (struct*-copy expand-context ctx
|
(define tl-ctx (struct*-copy expand-context ctx
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
(define (make-expand-context ns
|
(define (make-expand-context ns
|
||||||
#:to-parsed? [to-parsed? #f]
|
#:to-parsed? [to-parsed? #f]
|
||||||
#:for-serializable? [for-serializable? #f]
|
#:for-serializable? [for-serializable? #f]
|
||||||
#:observable? [observable? #f])
|
#:observer [observer #f])
|
||||||
(define root-ctx (namespace-get-root-expand-ctx ns))
|
(define root-ctx (namespace-get-root-expand-ctx ns))
|
||||||
(expand-context (root-expand-context-module-scopes root-ctx)
|
(expand-context (root-expand-context-module-scopes root-ctx)
|
||||||
(root-expand-context-post-expansion-scope root-ctx)
|
(root-expand-context-post-expansion-scope root-ctx)
|
||||||
|
@ -107,7 +107,7 @@
|
||||||
#f ; to-module-lifts
|
#f ; to-module-lifts
|
||||||
#f ; requires+provides
|
#f ; requires+provides
|
||||||
#f ; name
|
#f ; name
|
||||||
(and observable? (current-expand-observe))
|
observer
|
||||||
for-serializable?
|
for-serializable?
|
||||||
#f))
|
#f))
|
||||||
|
|
||||||
|
@ -136,8 +136,10 @@
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
|
|
||||||
;; For macro debugging; see "log.rkt"
|
;; For macro debugging. This parameter is only used by the expander
|
||||||
|
;; entry points in "../eval/main.rkt" to set the expand-context
|
||||||
|
;; observer. Other expander code uses "log.rkt" to send expansion
|
||||||
|
;; events to the observer.
|
||||||
(define current-expand-observe (make-parameter #f
|
(define current-expand-observe (make-parameter #f
|
||||||
(lambda (v)
|
(lambda (v)
|
||||||
(unless (or (not v)
|
(unless (or (not v)
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
(provide log-expand
|
(provide log-expand
|
||||||
log-expand*
|
log-expand*
|
||||||
log-expand...
|
log-expand...
|
||||||
...log-expand
|
...log-expand)
|
||||||
log-expand-start-top)
|
|
||||||
|
|
||||||
(define-syntax log-expand...
|
(define-syntax log-expand...
|
||||||
(syntax-rules (lambda)
|
(syntax-rules (lambda)
|
||||||
|
@ -45,11 +44,6 @@
|
||||||
[(null? args) #f]
|
[(null? args) #f]
|
||||||
[else (apply list* args)])))
|
[else (apply list* args)])))
|
||||||
|
|
||||||
(define (log-expand-start-top)
|
|
||||||
(define obs (current-expand-observe))
|
|
||||||
(when obs
|
|
||||||
(call-expand-observe obs 'start-top)))
|
|
||||||
|
|
||||||
(define key->arity
|
(define key->arity
|
||||||
;; event-symbol => (U Nat 'any)
|
;; event-symbol => (U Nat 'any)
|
||||||
#hash(;; basic empty tokens
|
#hash(;; basic empty tokens
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user