Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions default-recommendations/analyzers/identifier-usage-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,19 @@ analysis-test: "disappeared use of macro"
@inspect - m
@property usage-count
@assert 1


analysis-test: "custom macro with disappeared use"
--------------------
(require (for-syntax racket/base))
(define x 42)
(define-syntax (use-x stx)
(syntax-case stx ()
[(_ body)
(syntax-property #'body 'disappeared-use (list #'x))]))
(use-x (void))
--------------------
@within - (define x 42)
@inspect - x
@property usage-count
@assert 1
29 changes: 28 additions & 1 deletion default-recommendations/analyzers/identifier-usage.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@
(extract-ids origin))


;; Extract identifiers from the 'disappeared-use syntax property
;; The 'disappeared-use property can be either:
;; - A single identifier
;; - A list of identifiers
;; We extract all identifiers and label them with the given phase
(define (disappeared-use-property-identifiers stx phase)
(define disappeared (syntax-property stx 'disappeared-use))

(define (extract-ids obj)
(cond
[(not obj) (stream)]
[(identifier? obj)
;; Add the phase property to the identifier so it matches correctly
(stream (syntax-property obj 'phase phase))]
[(list? obj)
(apply stream-append (map extract-ids obj))]
[else (stream)]))

(extract-ids disappeared))


;; Find all identifier usage sites (not binding sites)
(define (usage-site-identifiers expanded-stx)
(let loop ([expanded-stx expanded-stx] [phase 0])
Expand All @@ -70,6 +91,12 @@
(for/list ([stx-node (in-stream (syntax-search-everything expanded-stx))])
(origin-property-identifiers stx-node phase))))

;; Collect identifiers from disappeared-use properties of all syntax objects
(define disappeared-ids
(apply stream-append
(for/list ([stx-node (in-stream (syntax-search-everything expanded-stx))])
(disappeared-use-property-identifiers stx-node phase))))

;; Collect identifiers from the expanded syntax tree
(define expanded-ids
(syntax-search expanded-stx
Expand Down Expand Up @@ -126,7 +153,7 @@
#:when (identifier? this-syntax)
(stream (attribute id))]))

(stream-append origin-ids expanded-ids)))
(stream-append origin-ids disappeared-ids expanded-ids)))


(define (fully-expanded-syntax-binding-table stx)
Expand Down