make syntax/moddep
more useful
This tool seems misplaced, but improve it a little to be practical for larger module hierarchies.
This commit is contained in:
parent
11e81f8776
commit
32b274dee1
|
@ -9,7 +9,20 @@ Re-exports @racketmodname[syntax/modread],
|
||||||
@racketmodname[syntax/modcode], @racketmodname[syntax/modcollapse],
|
@racketmodname[syntax/modcode], @racketmodname[syntax/modcollapse],
|
||||||
and @racketmodname[syntax/modresolve], in addition to the following:
|
and @racketmodname[syntax/modresolve], in addition to the following:
|
||||||
|
|
||||||
@defproc[(show-import-tree [module-path-v module-path?]) void?]{
|
@defproc[(show-import-tree [module-path-v module-path?]
|
||||||
|
[#:dag? dag? any/c #f]
|
||||||
|
[#:path-to path-to-module-path-v (or/c #f module-path?) #f])
|
||||||
|
void?]{
|
||||||
|
|
||||||
A debugging aid that prints the import hierarchy starting from a given
|
A debugging aid that prints the import hierarchy starting from a given
|
||||||
module path.}
|
module path.
|
||||||
|
|
||||||
|
If @racket[dag?] is true, then a module is printed only the first time
|
||||||
|
is encountered in the hierarchy.
|
||||||
|
|
||||||
|
If @racket[path-to-module-path-v] is a module path, then only the
|
||||||
|
spines of the tree that reach @racket[path-to-module-path-v] are
|
||||||
|
shown.
|
||||||
|
|
||||||
|
@history[#:changed "6.12.0.4" @elem{Added the @racket[#:dag?] and
|
||||||
|
@racket[#:path-to] arguments.}]}
|
||||||
|
|
|
@ -10,24 +10,49 @@
|
||||||
(all-from-out "modresolve.rkt")
|
(all-from-out "modresolve.rkt")
|
||||||
show-import-tree)
|
show-import-tree)
|
||||||
|
|
||||||
(define (show-import-tree module-path)
|
(define (show-import-tree module-path
|
||||||
(let loop ([path (resolve-module-path module-path #f)][indent ""][fs ""])
|
#:dag? [dag? #f]
|
||||||
(printf "~a~a~a\n" indent path fs)
|
#:path-to [given-path-to #f])
|
||||||
(let ([code (get-module-code path)])
|
(define path-to (and given-path-to (simplify-path (resolve-module-path given-path-to #f))))
|
||||||
(let ([imports (module-compiled-imports code)])
|
(define seen (and dag? (make-hash)))
|
||||||
(define ((mk-loop fs) i)
|
(let loop ([path (resolve-module-path module-path #f)] [indent ""] [fs ""] [phase 0] [accum '()])
|
||||||
(let ([p (resolve-module-path-index i path)])
|
(unless path-to
|
||||||
(unless (symbol? p)
|
(printf "~a~a~a ~a\n" indent path fs phase))
|
||||||
(loop p
|
(when (equal? path-to path)
|
||||||
(format " ~a" indent)
|
(let ([accum (let loop ([accum (cons (list indent path fs phase) accum)])
|
||||||
fs))))
|
(cond
|
||||||
(for-each (lambda (i)
|
[(null? accum) null]
|
||||||
(for-each
|
[(hash-ref seen accum #f) null]
|
||||||
(mk-loop (case (car i)
|
[else
|
||||||
[(0) ""]
|
(hash-set! seen accum #t)
|
||||||
[(1) " [for-syntax]"]
|
(cons (car accum) (loop (cdr accum)))]))])
|
||||||
[(-1) " [for-syntax]"]
|
(for ([i (in-list (reverse accum))])
|
||||||
[(#f) " [for-label]"]
|
(apply printf "~a~a~a ~a\n" i))))
|
||||||
[else (format " [for-meta ~a]" (car i))]))
|
(unless (and seen (hash-ref seen (cons path phase) #f))
|
||||||
(cdr i)))
|
(when seen (hash-set! seen (cons path phase) #t))
|
||||||
imports))))))
|
(define plain-path (if (pair? path) (cadr path) path))
|
||||||
|
(let ([code (get-module-code plain-path
|
||||||
|
#:submodule-path (if (pair? path) (cddr path) '()))])
|
||||||
|
(let ([imports (module-compiled-imports code)]
|
||||||
|
[accum (cons (list indent path fs phase) accum)])
|
||||||
|
(define ((mk-loop phase-shift fs) i)
|
||||||
|
(let ([p (resolve-module-path-index i plain-path)])
|
||||||
|
(unless (symbol? p)
|
||||||
|
(loop (if (path? p)
|
||||||
|
(simplify-path p)
|
||||||
|
(list* 'submod (simplify-path (cadr p)) (cddr p)))
|
||||||
|
(format " ~a" indent)
|
||||||
|
fs
|
||||||
|
(and phase phase-shift (+ phase phase-shift))
|
||||||
|
accum))))
|
||||||
|
(for-each (lambda (i)
|
||||||
|
(for-each
|
||||||
|
(mk-loop (car i)
|
||||||
|
(case (car i)
|
||||||
|
[(0) ""]
|
||||||
|
[(1) " [for-syntax]"]
|
||||||
|
[(-1) " [for-template]"]
|
||||||
|
[(#f) " [for-label]"]
|
||||||
|
[else (format " [for-meta ~a]" (car i))]))
|
||||||
|
(cdr i)))
|
||||||
|
imports)))))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user