|
9 | 9 | [identifier-usage-analyzer expansion-analyzer?])) |
10 | 10 |
|
11 | 11 |
|
12 | | -(require racket/list |
| 12 | +(require racket/hash |
| 13 | + racket/list |
13 | 14 | racket/stream |
14 | 15 | rebellion/collection/entry |
15 | 16 | rebellion/streaming/transducer |
|
159 | 160 | ;; Create expanded-id-table to track bound identifiers with empty usage lists |
160 | 161 | (define table (make-expanded-id-table)) |
161 | 162 |
|
| 163 | + ;; Group bound identifiers by phase for efficient lookup |
| 164 | + (define bound-by-phase (make-hash)) |
| 165 | + |
162 | 166 | ;; Initialize all bound identifiers with empty usage lists |
163 | 167 | (for ([id (in-stream (binding-site-identifiers labeled-stx))]) |
164 | 168 | (define id-phase (syntax-property id 'phase)) |
165 | | - (expanded-id-table-set! table (expanded-identifier id id-phase) '())) |
| 169 | + (define expanded-id (expanded-identifier id id-phase)) |
| 170 | + (expanded-id-table-set! table expanded-id '()) |
| 171 | + (hash-update! bound-by-phase id-phase (λ (lst) (cons expanded-id lst)) '())) |
166 | 172 |
|
167 | | - ;; For each usage, find its binding and add it to the usage list |
| 173 | + ;; For each usage, find its binding within the same phase and add it to the usage list |
168 | 174 | (for ([used-id (in-stream (usage-site-identifiers labeled-stx))]) |
169 | 175 | (define used-phase (syntax-property used-id 'phase)) |
170 | | - (for ([bound-entry (in-expanded-id-table table)]) |
171 | | - (define bound-expanded-id (entry-key bound-entry)) |
| 176 | + (define bound-at-phase (hash-ref bound-by-phase used-phase '())) |
| 177 | + (for ([bound-expanded-id bound-at-phase]) |
172 | 178 | (define bound-id (expanded-identifier-syntax bound-expanded-id)) |
173 | | - (define bound-phase (expanded-identifier-phase bound-expanded-id)) |
174 | | - (when (and (equal? bound-phase used-phase) |
175 | | - (free-identifier=? bound-id used-id)) |
176 | | - (define current-usages (entry-value bound-entry)) |
| 179 | + (when (free-identifier=? bound-id used-id) |
| 180 | + (define current-usages (expanded-id-table-ref table bound-expanded-id '())) |
177 | 181 | (expanded-id-table-set! table bound-expanded-id (cons used-id current-usages))))) |
178 | 182 |
|
179 | 183 | table) |
|
0 commit comments