diff --git a/drracket-tool-text-lib/drracket/private/syncheck/contract-traversal.rkt b/drracket-tool-text-lib/drracket/private/syncheck/contract-traversal.rkt index 3fe3db832..b5426680f 100644 --- a/drracket-tool-text-lib/drracket/private/syncheck/contract-traversal.rkt +++ b/drracket-tool-text-lib/drracket/private/syncheck/contract-traversal.rkt @@ -29,22 +29,30 @@ [_ (void)])) ;; fill in the coloring-plans table for boundary contracts - (for ([(start-k start-val) (in-hash boundary-start-map)]) + (for ([start-val (in-hash-values boundary-start-map)]) (for ([start-stx (in-list start-val)]) - (do-contract-traversal start-stx #t - coloring-plans already-jumped-ids - low-binders binding-inits - domain-map range-map + (do-contract-traversal start-stx + #t + coloring-plans + already-jumped-ids + low-binders + binding-inits + domain-map + range-map #t binder+mods-binder))) ;; fill in the coloring-plans table for internal contracts - (for ([(start-k start-val) (in-hash internal-start-map)]) + (for ([start-val (in-hash-values internal-start-map)]) (for ([start-stx (in-list start-val)]) - (do-contract-traversal start-stx #f - coloring-plans already-jumped-ids - low-binders binding-inits - domain-map range-map + (do-contract-traversal start-stx + #f + coloring-plans + already-jumped-ids + low-binders + binding-inits + domain-map + range-map #f binder+mods-binder))) @@ -210,7 +218,7 @@ (let loop ([val (syntax-property stx prop)]) (cond [(symbol? val) - (hash-set! map val (cons stx (hash-ref map val '())))] + (hash-update! map val (λ (v) (cons stx v)) '())] [(pair? val) (loop (car val)) (loop (cdr val))]))) @@ -221,11 +229,11 @@ ;; approximate this by just asking 'did this identifier come from the core?' (which is known ;; to not bind any contracts (I hope)) (define (known-predicate? id) - (let ([ib (identifier-binding id)]) - (and (list? ib) - (let ([src (list-ref ib 0)]) - (let-values ([(base rel) (module-path-index-split src)]) - (member base '('#%kernel '#%runtime racket racket/base scheme scheme/base))))))) + (define ib (identifier-binding id)) + (and (list? ib) + (let ([src (list-ref ib 0)]) + (let-values ([(base rel) (module-path-index-split src)]) + (member base '('#%kernel '#%runtime racket racket/base scheme scheme/base)))))) (define (give-up stx boundary-contract? coloring-plans) (let loop ([stx stx]) diff --git a/drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt b/drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt index 0fe27611a..13601d2ee 100644 --- a/drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt +++ b/drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt @@ -791,13 +791,13 @@ (for ([k (in-hash-keys requires)]) (hash-set! new-hash k #t))) - (for ([(level binders) (in-hash phase-to-binders)]) - (for ([(_ binder+modss) (in-dict binders)]) - (for ([binder+mods (in-list binder+modss)]) - (define var (binder+mods-binder binder+mods)) - (define varset (lookup-phase-to-mapping phase-to-varsets level)) - (color-variable var level varset) - (document-variable var level)))) + (for* ([(level binders) (in-hash phase-to-binders)] + [(_ binder+modss) (in-dict binders)] + [binder+mods (in-list binder+modss)]) + (define var (binder+mods-binder binder+mods)) + (define varset (lookup-phase-to-mapping phase-to-varsets level)) + (color-variable var level varset) + (document-variable var level)) (for ([(level+mods varrefs) (in-hash phase-to-varrefs)]) (define level (list-ref level+mods 0)) @@ -805,21 +805,21 @@ (define binders (lookup-phase-to-mapping phase-to-binders level)) (define varsets (lookup-phase-to-mapping phase-to-varsets level)) (initialize-binder-connections binders connections) - (for ([vars (in-list (get-idss varrefs))]) - (for ([var (in-list vars)]) - (color-variable var level varsets) - (document-variable var level) - (connect-identifier var - mods - binders - unused/phases - phase-to-requires - level - user-namespace - user-directory - #t - connections - module-lang-requires)))) + (for* ([vars (in-list (get-idss varrefs))] + [var (in-list vars)]) + (color-variable var level varsets) + (document-variable var level) + (connect-identifier var + mods + binders + unused/phases + phase-to-requires + level + user-namespace + user-directory + #t + connections + module-lang-requires))) ;; build a set of all of the known phases @@ -827,7 +827,7 @@ (define all-mods (set)) (for ([phase (in-hash-keys phase-to-binders)]) (set! phases (set-add phases phase))) - (for ([(phase+mod _) (in-hash phase-to-requires)]) + (for ([phase+mod (in-hash-keys phase-to-requires)]) (define phase (list-ref phase+mod 0)) (define mod (list-ref phase+mod 1)) (set! phases (set-add phases phase)) @@ -855,10 +855,9 @@ (for ([(level tops) (in-hash phase-to-tops)]) (define binders (lookup-phase-to-mapping phase-to-binders level)) - (for ([vars (in-list (get-idss tops))]) - (for ([var (in-list vars)]) - (color/connect-top user-namespace user-directory binders var connections - module-lang-requires)))) + (for* ([vars (in-list (get-idss tops))] + [var (in-list vars)]) + (color/connect-top user-namespace user-directory binders var connections module-lang-requires))) (for ([(phase+mods require-hash) (in-hash phase-to-requires)]) ;; don't mark for-label requires as unused until we can properly handle them @@ -892,19 +891,17 @@ ;; color-unused : hash-table[sexp -o> syntax] hash-table[sexp -o> #f] hash-table[syntax -o> #t] ;; -> void (define (color-unused requires unused module-lang-requires) - (for ([(k v) (in-hash unused)]) + (for ([k (in-hash-keys unused)]) (define require-contexts - (hash-ref requires k - (λ () - (error 'syncheck/traversals.rkt - "requires doesn't have a mapping for ~s" - k)))) + (hash-ref requires + k + (λ () (error 'syncheck/traversals.rkt "requires doesn't have a mapping for ~s" k)))) (for ([require-context (in-list require-contexts)]) (define binder+mods (require-context-b+m require-context)) (define stx (binder+mods-binder binder+mods)) - (unless (hash-ref module-lang-requires (list (syntax-source stx) - (syntax-position stx) - (syntax-span stx)) #f) + (unless (hash-ref module-lang-requires + (list (syntax-source stx) (syntax-position stx) (syntax-span stx)) + #f) (define defs-text (current-annotations)) (define source-editor (find-source-editor stx)) (when (and defs-text source-editor) @@ -914,8 +911,7 @@ (define start (- pos 1)) (define fin (+ start span)) (send defs-text syncheck:add-unused-require source-editor start fin) - (send defs-text syncheck:add-text-type - source-editor start fin 'unused-identifier))) + (send defs-text syncheck:add-text-type source-editor start fin 'unused-identifier))) (color stx unused-require-style-name))))) ;; color-unused-binder : source integer integer -> void @@ -926,8 +922,8 @@ (color-range source start end unused-require-style-name)) (define (self-module? mpi) - (let-values ([(a b) (module-path-index-split mpi)]) - (and (not a) (not b)))) + (define-values (a b) (module-path-index-split mpi)) + (and (not a) (not b))) ;; connect-identifier : syntax ;; (or/c #f (listof symbol)) -- name of enclosing sub-modules @@ -1094,7 +1090,7 @@ (define phase-shift (if (pair? phase+space-shift) (car phase+space-shift) phase+space-shift)) (define phase+space (list-ref binding 6)) (define phase (if (pair? phase+space) (car phase+space) phase+space)) - (define space (if (pair? phase+space) (cdr phase+space) #f)) + (define space (and (pair? phase+space) (cdr phase+space))) (when (and (number? phase-level) (not (= phase-level (+ phase-shift @@ -1116,22 +1112,29 @@ [else #f]))) ;; color/connect-top : namespace directory id-set syntax connections[see defn for ctc] -> void -(define (color/connect-top user-namespace user-directory binders var connections - module-lang-requires) - (let ([top-bound? - (or (get-ids binders var) - (parameterize ([current-namespace user-namespace]) - (let/ec k - (namespace-variable-value (syntax-e var) #t (λ () (k #f))) - #t)))]) - (cond - [top-bound? - (color var lexically-bound-variable-style-name)] - [else - (add-mouse-over var (format "~s is a free variable" (syntax-e var))) - (color var free-variable-style-name)]) - (connect-identifier var #f binders #f #f 0 user-namespace user-directory #t connections - module-lang-requires))) +(define (color/connect-top user-namespace user-directory binders var connections module-lang-requires) + (define top-bound? + (or (get-ids binders var) + (parameterize ([current-namespace user-namespace]) + (let/ec k + (namespace-variable-value (syntax-e var) #t (λ () (k #f))) + #t)))) + (cond + [top-bound? (color var lexically-bound-variable-style-name)] + [else + (add-mouse-over var (format "~s is a free variable" (syntax-e var))) + (color var free-variable-style-name)]) + (connect-identifier var + #f + binders + #f + #f + 0 + user-namespace + user-directory + #t + connections + module-lang-requires)) ;; annotate-counts : connections[see defn] -> void ;; this function doesn't try to show the number of uses at @@ -1149,39 +1152,39 @@ ;; records the src locs of each 'end' position of each arrow) ;; to do this, but maybe lets leave that for another day. (define (annotate-counts connections) - (for ([(key val) (in-hash connections)]) - (when (list? val) - (define start (first val)) - (define end (second val)) - (define color? (third val)) - (define (show-starts) - (when (zero? start) - (define defs-text (current-annotations)) - (when defs-text - (send defs-text syncheck:unused-binder - (list-ref key 0) (list-ref key 1) (list-ref key 2)))) - (add-mouse-over/loc (list-ref key 0) (list-ref key 1) (list-ref key 2) - (cond - [(zero? start) - (string-constant cs-zero-varrefs)] - [(= 1 start) - (string-constant cs-one-varref)] - [else - (format (string-constant cs-n-varrefs) start)]))) - (define (show-ends) - (unless (= 1 end) - (add-mouse-over/loc (list-ref key 0) (list-ref key 1) (list-ref key 2) - (format (string-constant cs-binder-count) end)))) - (cond - [(zero? end) ;; assume this is a binder, show uses - #;(when (and color? (zero? start)) - (color-unused-binder (list-ref key 0) (list-ref key 1) (list-ref key 2))) - (show-starts)] - [(zero? start) ;; assume this is a use, show bindings (usually just one, so do nothing) - (show-ends)] - [else ;; crazyness, show both - (show-starts) - (show-ends)])))) + (for ([(key val) (in-hash connections)] + #:when (list? val)) + (define start (first val)) + (define end (second val)) + (define color? (third val)) + (define (show-starts) + (when (zero? start) + (define defs-text (current-annotations)) + (when defs-text + (send defs-text syncheck:unused-binder (list-ref key 0) (list-ref key 1) (list-ref key 2)))) + (add-mouse-over/loc (list-ref key 0) + (list-ref key 1) + (list-ref key 2) + (cond + [(zero? start) (string-constant cs-zero-varrefs)] + [(= 1 start) (string-constant cs-one-varref)] + [else (format (string-constant cs-n-varrefs) start)]))) + (define (show-ends) + (unless (= 1 end) + (add-mouse-over/loc (list-ref key 0) + (list-ref key 1) + (list-ref key 2) + (format (string-constant cs-binder-count) end)))) + (cond + ;; assume this is a binder, show uses + #;(when (and color? (zero? start)) + (color-unused-binder (list-ref key 0) (list-ref key 1) (list-ref key 2))) + [(zero? end) (show-starts)] + ;; assume this is a use, show bindings (usually just one, so do nothing) + [(zero? start) (show-ends)] + [else ;; crazyness, show both + (show-starts) + (show-ends)]))) ;; color-variable : syntax phase-level identifier-mapping -> void (define (color-variable var phase-level varsets) @@ -1197,10 +1200,11 @@ (define (is-lexical? b) (or (not b) (eq? b 'lexical) - (and (pair? b) - (let ([path (caddr b)]) - (and (module-path-index? path) - (self-module? path)))))) + (cond + [(pair? b) + (define path (caddr b)) + (and (module-path-index? path) (self-module? path))] + [else #f]))) ;; initialize-binder-connections : id-set connections -> void (define (initialize-binder-connections binders connections) @@ -1295,22 +1299,19 @@ ;; popup menu in this area allows the programmer to jump ;; to the definition of the id. (define (add-jump-to-definition stx id filename submods phase-level+space) - (let ([source (find-source-editor stx)] - [defs-text (current-annotations)]) - (when (and source - defs-text - (syntax-position stx) - (syntax-span stx)) - (let* ([pos-left (- (syntax-position stx) 1)] - [pos-right (+ pos-left (syntax-span stx))]) - (send defs-text syncheck:add-jump-to-definition/phase-level+space - source - pos-left - pos-right - id - filename - submods - phase-level+space))))) + (define source (find-source-editor stx)) + (define defs-text (current-annotations)) + (when (and source defs-text (syntax-position stx) (syntax-span stx)) + (let* ([pos-left (- (syntax-position stx) 1)] + [pos-right (+ pos-left (syntax-span stx))]) + (send defs-text syncheck:add-jump-to-definition/phase-level+space + source + pos-left + pos-right + id + filename + submods + phase-level+space)))) ;; annotate-require-open : namespace string -> (stx -> void) ;; relies on current-module-name-resolver, which in turn depends on @@ -1386,10 +1387,10 @@ (unless (and (len . >= . 4) (bytes=? #".rkt" (subbytes bts (- len 4)))) (k rkt-path/f)) - (let ([ss-path (bytes->path (bytes-append (subbytes bts 0 (- len 4)) #".ss"))]) - (unless (file-exists? ss-path) - (k rkt-path/f)) - ss-path)))) + (define ss-path (bytes->path (bytes-append (subbytes bts 0 (- len 4)) #".ss"))) + (unless (file-exists? ss-path) + (k rkt-path/f)) + ss-path))) (values cleaned-up-path rkt-submods))) ;; add-origins : syntax? id-set exact-integer? -> void @@ -1448,20 +1449,21 @@ (add-init-exp binding-to-init stx init-exp level-of-enclosing-module)) (add-id id-set stx level-of-enclosing-module #:mods mods)) (let loop ([stx stx]) - (let ([e (if (syntax? stx) (syntax-e stx) stx)]) - (cond - [(cons? e) - (define fst (car e)) - (define rst (cdr e)) - (cond - [(syntax? fst) - (add-id&init&sub-range-binders fst) - (loop rst)] - [else - (loop rst)])] - [(null? e) (void)] - [else - (add-id&init&sub-range-binders stx)])))) + (define e + (if (syntax? stx) + (syntax-e stx) + stx)) + (cond + [(cons? e) + (define fst (car e)) + (define rst (cdr e)) + (cond + [(syntax? fst) + (add-id&init&sub-range-binders fst) + (loop rst)] + [else (loop rst)])] + [(null? e) (void)] + [else (add-id&init&sub-range-binders stx)]))) ;; add-definition-target : syntax[(sequence of identifiers)] (listof symbol) -> void (define (add-definition-target stx mods phase-level) @@ -1470,31 +1472,27 @@ (for ([id (in-list (if (list? stx) stx (syntax->list stx)))]) (define source (syntax-source id)) (define ib (identifier-binding id phase-level)) - (when (and (list? ib) - source - defs-text - (syntax-position id) - (syntax-span id)) - (let* ([pos-left (- (syntax-position id) 1)] - [pos-right (+ pos-left (syntax-span id))]) - (send defs-text syncheck:add-definition-target/phase-level+space - source - pos-left - pos-right - (list-ref ib 1) - (map submodule-name mods) - phase-level)))))) + (when (and (list? ib) source defs-text (syntax-position id) (syntax-span id)) + (define pos-left (- (syntax-position id) 1)) + (define pos-right (+ pos-left (syntax-span id))) + (send defs-text syncheck:add-definition-target/phase-level+space + source + pos-left + pos-right + (list-ref ib 1) + (map submodule-name mods) + phase-level))))) ;; annotate-raw-keyword : syntax id-map integer -> void ;; annotates keywords when they were never expanded. eg. ;; if someone just types `(λ (x) x)' it has no 'origin ;; field, but there still are keywords. (define (annotate-raw-keyword stx id-map level-of-enclosing-module) - (let ([lst (syntax-e stx)]) - (when (pair? lst) - (let ([f-stx (car lst)]) - (when (identifier? f-stx) - (add-id id-map f-stx level-of-enclosing-module)))))) + (define lst (syntax-e stx)) + (when (pair? lst) + (let ([f-stx (car lst)]) + (when (identifier? f-stx) + (add-id id-map f-stx level-of-enclosing-module))))) ; ; @@ -1541,22 +1539,13 @@ tag)))))) (define (build-docs-label entry-desc) - (let ([libs (exported-index-desc-from-libs entry-desc)]) - (cond - [(null? libs) - (format - (string-constant cs-view-docs) - (exported-index-desc-name entry-desc))] - [else - (format - (string-constant cs-view-docs-from) - (format - (string-constant cs-view-docs) - (exported-index-desc-name entry-desc)) - (apply string-append - (add-between - (map (λ (x) (format "~s" x)) libs) - ", ")))]))) + (define libs (exported-index-desc-from-libs entry-desc)) + (cond + [(null? libs) (format (string-constant cs-view-docs) (exported-index-desc-name entry-desc))] + [else + (format (string-constant cs-view-docs-from) + (format (string-constant cs-view-docs) (exported-index-desc-name entry-desc)) + (apply string-append (add-between (map (λ (x) (format "~s" x)) libs) ", ")))])) ; ;