fix/simplify logging for main expand and expand-to-top-form
This commit is contained in:
parent
3a40125168
commit
2f7c0dd9fa
|
@ -132,7 +132,7 @@
|
||||||
;; [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))
|
(when observable? (log-expand-start-top))
|
||||||
(per-top-level s ns
|
(per-top-level s ns
|
||||||
#:single (lambda (s ns as-tail?) (expand-single s ns observable? to-parsed? serializable?))
|
#:single (lambda (s ns as-tail?) (expand-single s ns observable? to-parsed? serializable?))
|
||||||
#:combine cons
|
#:combine cons
|
||||||
|
@ -197,7 +197,7 @@
|
||||||
(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)
|
(log-expand-start-top)
|
||||||
(per-top-level s ns
|
(per-top-level s ns
|
||||||
#:single #f
|
#:single #f
|
||||||
#:quick-immediate? #f
|
#:quick-immediate? #f
|
||||||
|
@ -226,17 +226,13 @@
|
||||||
[just-once? just-once?]
|
[just-once? just-once?]
|
||||||
[for-serializable? serializable?]))
|
[for-serializable? serializable?]))
|
||||||
(define wb-s (and just-once? s))
|
(define wb-s (and just-once? s))
|
||||||
|
(log-expand tl-ctx 'visit s)
|
||||||
(define-values (require-lifts lifts exp-s)
|
(define-values (require-lifts lifts exp-s)
|
||||||
(if (and quick-immediate?
|
(expand-capturing-lifts s (struct*-copy expand-context tl-ctx
|
||||||
;; To avoid annoying the macro stepper, bail out quietly
|
[only-immediate? #t]
|
||||||
;; if the input is obviously a core form
|
[def-ctx-scopes (box null)] ; discarding is ok
|
||||||
(core-form-sym s phase))
|
[phase phase]
|
||||||
(values null null s)
|
[namespace ns])))
|
||||||
(expand-capturing-lifts s (struct*-copy expand-context tl-ctx
|
|
||||||
[only-immediate? #t]
|
|
||||||
[def-ctx-scopes (box null)] ; discarding is ok
|
|
||||||
[phase phase]
|
|
||||||
[namespace ns]))))
|
|
||||||
(define disarmed-exp-s (raw:syntax-disarm exp-s))
|
(define disarmed-exp-s (raw:syntax-disarm exp-s))
|
||||||
(cond
|
(cond
|
||||||
[(or (pair? require-lifts) (pair? lifts))
|
[(or (pair? require-lifts) (pair? lifts))
|
||||||
|
@ -248,12 +244,14 @@
|
||||||
(if just-once?
|
(if just-once?
|
||||||
new-s
|
new-s
|
||||||
(loop new-s phase ns as-tail?))]
|
(loop new-s phase ns as-tail?))]
|
||||||
[(not single) exp-s]
|
[(not single)
|
||||||
|
(log-expand tl-ctx 'return exp-s)
|
||||||
|
exp-s]
|
||||||
[(and just-once? (not (eq? exp-s wb-s))) exp-s]
|
[(and just-once? (not (eq? exp-s wb-s))) exp-s]
|
||||||
[else
|
[else
|
||||||
(case (core-form-sym disarmed-exp-s phase)
|
(case (core-form-sym disarmed-exp-s phase)
|
||||||
[(begin)
|
[(begin)
|
||||||
(log-top-begin-before ctx exp-s)
|
(log-expand ctx 'prim-begin)
|
||||||
(define-match m disarmed-exp-s '(begin e ...))
|
(define-match m disarmed-exp-s '(begin e ...))
|
||||||
;; Map `loop` over the `e`s, but in the case of `eval`,
|
;; Map `loop` over the `e`s, but in the case of `eval`,
|
||||||
;; tail-call for last one:
|
;; tail-call for last one:
|
||||||
|
@ -276,22 +274,28 @@
|
||||||
(cond
|
(cond
|
||||||
[wrap
|
[wrap
|
||||||
(define new-s (wrap (m 'begin) exp-s (begin-loop (m 'e))))
|
(define new-s (wrap (m 'begin) exp-s (begin-loop (m 'e))))
|
||||||
(log-top-begin-after tl-ctx new-s)
|
(log-expand tl-ctx 'return new-s)
|
||||||
new-s]
|
new-s]
|
||||||
[else (begin-loop (m 'e))])]
|
[else (begin-loop (m 'e))])]
|
||||||
[(begin-for-syntax)
|
[(begin-for-syntax)
|
||||||
|
(log-expand tl-ctx 'prim-begin-for-syntax)
|
||||||
(define-match m disarmed-exp-s '(begin-for-syntax e ...))
|
(define-match m disarmed-exp-s '(begin-for-syntax e ...))
|
||||||
(define next-phase (add1 phase))
|
(define next-phase (add1 phase))
|
||||||
(define next-ns (namespace->namespace-at-phase ns next-phase))
|
(define next-ns (namespace->namespace-at-phase ns next-phase))
|
||||||
|
(log-expand tl-ctx 'prepare-env)
|
||||||
(when quick-immediate?
|
(when quick-immediate?
|
||||||
;; In case `expand-capturing-lifts` didn't already:
|
;; In case `expand-capturing-lifts` didn't already:
|
||||||
(namespace-visit-available-modules! ns))
|
(namespace-visit-available-modules! ns))
|
||||||
(namespace-visit-available-modules! next-ns) ; to match old behavior for empty body
|
(namespace-visit-available-modules! next-ns) ; to match old behavior for empty body
|
||||||
(define l
|
(define l
|
||||||
(for/list ([s (in-list (m 'e))])
|
(for/list ([s (in-list (m 'e))])
|
||||||
|
(log-expand tl-ctx 'next)
|
||||||
(loop s next-phase next-ns #f)))
|
(loop s next-phase next-ns #f)))
|
||||||
(cond
|
(cond
|
||||||
[wrap (wrap (m 'begin-for-syntax) exp-s l)]
|
[wrap
|
||||||
|
(define new-s (wrap (m 'begin-for-syntax) exp-s l))
|
||||||
|
(log-expand tl-ctx 'return new-s)
|
||||||
|
new-s]
|
||||||
[combine l]
|
[combine l]
|
||||||
[else (void)])]
|
[else (void)])]
|
||||||
[else
|
[else
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
log-expand*
|
log-expand*
|
||||||
log-expand...
|
log-expand...
|
||||||
...log-expand
|
...log-expand
|
||||||
log-expand-start)
|
log-expand-start-top)
|
||||||
|
|
||||||
(define-syntax log-expand...
|
(define-syntax log-expand...
|
||||||
(syntax-rules (lambda)
|
(syntax-rules (lambda)
|
||||||
|
@ -45,10 +45,10 @@
|
||||||
[else (apply list* args)])))]
|
[else (apply list* args)])))]
|
||||||
[else (error 'call-expand-observe "bad key: ~s" key)]))
|
[else (error 'call-expand-observe "bad key: ~s" key)]))
|
||||||
|
|
||||||
(define (log-expand-start)
|
(define (log-expand-start-top)
|
||||||
(define obs (current-expand-observe))
|
(define obs (current-expand-observe))
|
||||||
(when obs
|
(when obs
|
||||||
(call-expand-observe obs 'start-expand)))
|
(call-expand-observe obs 'start-top)))
|
||||||
|
|
||||||
;; For historical reasons, an expander observer currently expects
|
;; For historical reasons, an expander observer currently expects
|
||||||
;; numbers
|
;; numbers
|
||||||
|
@ -158,4 +158,6 @@
|
||||||
|
|
||||||
(local-value-result . (154 . 1))
|
(local-value-result . (154 . 1))
|
||||||
|
|
||||||
(prepare-env . (157 . 0))))
|
(prepare-env . (157 . 0))
|
||||||
|
|
||||||
|
(start-top . (201 . 0))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user