Skip to content

Commit

Permalink
Keep syntax objects outside range for scopes
Browse files Browse the repository at this point in the history
Also, add some more debug logging. Part of #298.
  • Loading branch information
jackfirth committed Sep 19, 2024
1 parent f5e541e commit af0d931
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
5 changes: 3 additions & 2 deletions private/run-command.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

; This doesn't support anything but getting stdout -- but that's OK for now!
(define (run-command cmd-name . args)
(define stringified-args (map (λ (arg) (if (path? arg) (path->string arg) arg)) args))
(define cmd-path
(or (find-executable-path cmd-name)
; Racket doesn't know about $PATHEXT:
Expand All @@ -39,12 +40,12 @@
(unless (zero? exit-code)
(raise-arguments-error (name run-command)
"command exited with a nonzero exit code"
"command" (string-join (cons cmd-name args) " ")
"command" (string-join (cons cmd-name stringified-args) " ")
"exit code" exit-code
"stderr" stderr-string))
(when (non-empty-string? stderr-string)
(raise-arguments-error (name run-command)
"command exited successfully, but wrote to stderr"
"command" (string-join (cons cmd-name args) " ")
"command" (string-join (cons cmd-name stringified-args) " ")
"stderr" stderr-string))
stdout-string)
37 changes: 26 additions & 11 deletions private/source.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
rebellion/streaming/transducer
rebellion/type/record
resyntax/private/linemap
resyntax/private/logger
syntax/modread
syntax/parse)

Expand Down Expand Up @@ -101,7 +102,7 @@
(define expanded-originals-by-location (make-hash))

(define (add-all-original-subforms! stx)
(when (resyntax-should-analyze-syntax? stx)
(when (resyntax-should-analyze-syntax? stx #:as-visit? #false)
(hash-set! expanded-originals-by-location (syntax-source-location stx) stx))
(syntax-parse stx
[(subform ...) (for-each add-all-original-subforms! (attribute subform))]
Expand All @@ -110,16 +111,30 @@
(add-all-original-subforms! #'tail-form)]
[_ (void)]))

(define (resyntax-should-analyze-syntax? stx)
(and (syntax-original? stx)
;; Some macros are able to bend hygiene and syntax properties in such a way that they
;; introduce syntax objects into the program that are syntax-original?, but from a
;; different file than the one being expanded. So in addition to checking for
;; originality, we also check that they come from the same source as the main program
;; syntax object. The (open ...) clause of the define-signature macro bends hygiene
;; in this way, and is what originally motivated the addition of this check.
(equal? (syntax-source stx) program-source-name)
(range-set-overlaps? lines (syntax-line-range stx #:linemap code-linemap))))
(define/guard (resyntax-should-analyze-syntax? stx #:as-visit? [as-visit? #true])
(guard
(and (syntax-original? stx)
;; Some macros are able to bend hygiene and syntax properties in such a way that they
;; introduce syntax objects into the program that are syntax-original?, but from a
;; different file than the one being expanded. So in addition to checking for
;; originality, we also check that they come from the same source as the main program
;; syntax object. The (open ...) clause of the define-signature macro bends hygiene
;; in this way, and is what originally motivated the addition of this check.
(equal? (syntax-source stx) program-source-name))
#:else #false)
(guard as-visit? #:else #true)
(define stx-lines (syntax-line-range stx #:linemap code-linemap))
(define overlaps? (range-set-overlaps? lines stx-lines))
(unless overlaps?
(log-resyntax-debug
(string-append "ignoring visited syntax object because it's outside analyzed lines\n"
" analyzed lines: ~a\n"
" syntax lines: ~a\n"
" syntax: ~a")
lines
stx-lines
stx))
overlaps?)

(define/match (observe-event! sig val)
[('visit (? syntax? visited))
Expand Down

0 comments on commit af0d931

Please sign in to comment.