From f2a7405ddaa8a06dcb0e27bb84cd32de9c58319a Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 8 Aug 2018 09:53:32 -0600 Subject: [PATCH] syntax/moddep: DAG repair and `#:show` argument --- .../syntax/scribblings/moddep.scrbl | 19 +++++++++++++------ racket/collects/syntax/moddep.rkt | 10 ++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/pkgs/racket-doc/syntax/scribblings/moddep.scrbl b/pkgs/racket-doc/syntax/scribblings/moddep.scrbl index 4c62fdf9e1..42fc152d34 100644 --- a/pkgs/racket-doc/syntax/scribblings/moddep.scrbl +++ b/pkgs/racket-doc/syntax/scribblings/moddep.scrbl @@ -11,18 +11,25 @@ and @racketmodname[syntax/modresolve], in addition to the following: @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]) + [#:path-to path-to-module-path-v (or/c #f module-path?) #f] + [#:show show + (string? any/c string? (or/c #f exact-integer?) . -> . any) + (lambda (indent path require-mode phase) + (printf "~a~a~a ~a\n" indent path require-mode phase))]) void?]{ -A debugging aid that prints the import hierarchy starting from a given -module path. +A debugging aid that prints (by default) the import hierarchy starting +from a given module path. Supply an alternate @racket[show] function +to handle each path instead of having it printed; the second argument +is a result of @racket[resolved-module-path-name]. -If @racket[dag?] is true, then a module is printed only the first time -is encountered in the hierarchy. +If @racket[dag?] is true, then a module is passed to @racket[show] +only the first time is encountered in the hierarchy at a given phase. 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.}]} + @racket[#:path-to] arguments.} + #:changed "7.0.0.10" @elem{Added the @racket[#:show] argument.}]} diff --git a/racket/collects/syntax/moddep.rkt b/racket/collects/syntax/moddep.rkt index 037020d2d0..dc8c53c8b7 100644 --- a/racket/collects/syntax/moddep.rkt +++ b/racket/collects/syntax/moddep.rkt @@ -12,12 +12,12 @@ (define (show-import-tree module-path #:dag? [dag? #f] - #:path-to [given-path-to #f]) + #:path-to [given-path-to #f] + #:show [show (lambda (indent path require-mode phase) + (printf "~a~a~a ~a\n" indent path require-mode phase))]) (define path-to (and given-path-to (simplify-path (resolve-module-path given-path-to #f)))) (define seen (and dag? (make-hash))) (let loop ([path (resolve-module-path module-path #f)] [indent ""] [fs ""] [phase 0] [accum '()]) - (unless path-to - (printf "~a~a~a ~a\n" indent path fs phase)) (when (equal? path-to path) (let ([accum (let loop ([accum (cons (list indent path fs phase) accum)]) (cond @@ -27,8 +27,10 @@ (hash-set! seen accum #t) (cons (car accum) (loop (cdr accum)))]))]) (for ([i (in-list (reverse accum))]) - (apply printf "~a~a~a ~a\n" i)))) + (apply show i)))) (unless (and seen (hash-ref seen (cons path phase) #f)) + (unless path-to + (show indent path fs phase)) (when seen (hash-set! seen (cons path phase) #t)) (define plain-path (if (pair? path) (cadr path) path)) (let ([code (get-module-code plain-path