Skip to content

Commit

Permalink
Use more-precise stx loc for requires; fixes racket#110
Browse files Browse the repository at this point in the history
Also, avoid generating very many duplicate add-open-require and
unused-require annotations. This can happen when forms like combine-in
expand to rename sub-forms for every imported item. This should make
check-syntax quicker when used both by DrRacket and by things like
Racket Mode.

Caveats (i.e. please do review before merging):

- I'm not 100% sure I understand the usage of `phase-to-requires` so I
may have broken something else.

- I moved the generation of add-open-require annotations inside the
original-enough? test. It seems natural to handle dupe avoidance, for
those, at the same time we're handling it, for phase-to-requires. I'm
not sure how else to avoid those dupes, without introducing yet
another data structure.

So please do review. Even if my attempt to fix this, is poor,
hopefully I helped by narrowing down the cause (or at least proximate
cause) of the problem, and someone else could "fix it better".
  • Loading branch information
greghendershott committed Mar 25, 2020
1 parent 3c95321 commit 003f87d
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions drracket-tool-lib/drracket/private/syncheck/traversals.rkt
Expand Up @@ -466,12 +466,23 @@
(list adjusted-level mods)
(λ () (make-hash))))
(define raw-module-path (phaseless-spec->raw-module-path stx))
(annotate-require-open user-namespace user-directory raw-module-path level stx)
(when (original-enough? raw-module-path)
(define key (syntax->datum raw-module-path))
(hash-set! require-ht
key
(cons stx (hash-ref require-ht key '())))))
;; 1. Use raw-module-path not stx. Former has
;; more-precise location; matters for e.g. combine-in
;; and things that expand to it like multi-in. 2. Avoid
;; many duplicates as a result of e.g. combine-in
;; expanding to a `(just-meta _ (rename raw-module-path
;; local-id exported-d))` subform for every id imported
;; from the module.
(define xs (hash-ref require-ht key '()))
(define new? (not (findf (λ (x) (syntax-equal-datum-and-loc? x raw-module-path))
xs)))
(when new?
(annotate-require-open user-namespace user-directory
raw-module-path level stx))
(define val (if new? (cons raw-module-path xs) xs))
(hash-set! require-ht key val)))

(for ([spec (in-list (syntax->list #'(raw-require-specs ...)))])
(handle-raw-require-spec spec)))]
Expand Down Expand Up @@ -534,6 +545,10 @@
(syntax-source stx-obj)))
(void))]))))

(define (syntax-equal-datum-and-loc? a b)
(for/and ([f (in-list (list syntax->datum syntax-source syntax-line syntax-column))])
(and (equal? (f a) (f b)))))

(define (add-module-lang-require module-lang-requires stx)
(hash-set! module-lang-requires (module-lang-require-ht-key stx) #t))
(define (is-module-lang-require? module-lang-requires stx)
Expand Down Expand Up @@ -944,7 +959,6 @@
[(rename raw-module-path local-id exported-id) #'raw-module-path]
[_ stx]))


;; get-module-req-path : identifier number [#:nominal? boolean]
;; -> (union #f (list require-sexp sym ?? module-path-index?))
(define (get-module-req-path var phase-level #:nominal? [nominal-source-path? #t])
Expand Down

0 comments on commit 003f87d

Please sign in to comment.