|
10 | 10 | (all-from-out "modresolve.rkt")
|
11 | 11 | show-import-tree)
|
12 | 12 |
|
13 |
| - (define (show-import-tree module-path) |
14 |
| - (let loop ([path (resolve-module-path module-path #f)][indent ""][fs ""]) |
15 |
| - (printf "~a~a~a\n" indent path fs) |
16 |
| - (let ([code (get-module-code path)]) |
17 |
| - (let ([imports (module-compiled-imports code)]) |
18 |
| - (define ((mk-loop fs) i) |
19 |
| - (let ([p (resolve-module-path-index i path)]) |
20 |
| - (unless (symbol? p) |
21 |
| - (loop p |
22 |
| - (format " ~a" indent) |
23 |
| - fs)))) |
24 |
| - (for-each (lambda (i) |
25 |
| - (for-each |
26 |
| - (mk-loop (case (car i) |
27 |
| - [(0) ""] |
28 |
| - [(1) " [for-syntax]"] |
29 |
| - [(-1) " [for-syntax]"] |
30 |
| - [(#f) " [for-label]"] |
31 |
| - [else (format " [for-meta ~a]" (car i))])) |
32 |
| - (cdr i))) |
33 |
| - imports)))))) |
| 13 | + (define (show-import-tree module-path |
| 14 | + #:dag? [dag? #f] |
| 15 | + #:path-to [given-path-to #f]) |
| 16 | + (define path-to (and given-path-to (simplify-path (resolve-module-path given-path-to #f)))) |
| 17 | + (define seen (and dag? (make-hash))) |
| 18 | + (let loop ([path (resolve-module-path module-path #f)] [indent ""] [fs ""] [phase 0] [accum '()]) |
| 19 | + (unless path-to |
| 20 | + (printf "~a~a~a ~a\n" indent path fs phase)) |
| 21 | + (when (equal? path-to path) |
| 22 | + (let ([accum (let loop ([accum (cons (list indent path fs phase) accum)]) |
| 23 | + (cond |
| 24 | + [(null? accum) null] |
| 25 | + [(hash-ref seen accum #f) null] |
| 26 | + [else |
| 27 | + (hash-set! seen accum #t) |
| 28 | + (cons (car accum) (loop (cdr accum)))]))]) |
| 29 | + (for ([i (in-list (reverse accum))]) |
| 30 | + (apply printf "~a~a~a ~a\n" i)))) |
| 31 | + (unless (and seen (hash-ref seen (cons path phase) #f)) |
| 32 | + (when seen (hash-set! seen (cons path phase) #t)) |
| 33 | + (define plain-path (if (pair? path) (cadr path) path)) |
| 34 | + (let ([code (get-module-code plain-path |
| 35 | + #:submodule-path (if (pair? path) (cddr path) '()))]) |
| 36 | + (let ([imports (module-compiled-imports code)] |
| 37 | + [accum (cons (list indent path fs phase) accum)]) |
| 38 | + (define ((mk-loop phase-shift fs) i) |
| 39 | + (let ([p (resolve-module-path-index i plain-path)]) |
| 40 | + (unless (symbol? p) |
| 41 | + (loop (if (path? p) |
| 42 | + (simplify-path p) |
| 43 | + (list* 'submod (simplify-path (cadr p)) (cddr p))) |
| 44 | + (format " ~a" indent) |
| 45 | + fs |
| 46 | + (and phase phase-shift (+ phase phase-shift)) |
| 47 | + accum)))) |
| 48 | + (for-each (lambda (i) |
| 49 | + (for-each |
| 50 | + (mk-loop (car i) |
| 51 | + (case (car i) |
| 52 | + [(0) ""] |
| 53 | + [(1) " [for-syntax]"] |
| 54 | + [(-1) " [for-template]"] |
| 55 | + [(#f) " [for-label]"] |
| 56 | + [else (format " [for-meta ~a]" (car i))])) |
| 57 | + (cdr i))) |
| 58 | + imports))))))) |
0 commit comments