Skip to content

Commit 7cb1076

Browse files
Copilotjackfirth
andcommitted
Address code review feedback
Export binding-site-identifiers and use it directly in variable-mutability-analyzer to avoid redundant initialization loop. Add documentation to fully-expanded-syntax-id-table. Co-authored-by: jackfirth <[email protected]>
1 parent 771cba4 commit 7cb1076

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

default-recommendations/analyzers/private/expanded-id-table.rkt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
[in-expanded-id-table-phase
1818
(-> expanded-id-table? (or/c exact-nonnegative-integer? #false) (sequence/c (entry/c expanded-identifier? any/c)))]
1919
[syntax-label-id-phases (-> syntax? syntax?)]
20+
[binding-site-identifiers (-> syntax? stream?)]
2021
[fully-expanded-syntax-id-table (-> syntax? expanded-id-table?)]))
2122

2223

@@ -153,6 +154,10 @@
153154
(map recur (append* (attribute body))))])))
154155

155156

157+
;; Builds an expanded-id-table from phase-labeled syntax.
158+
;; The input syntax should already have phase labels added via syntax-label-id-phases.
159+
;; Returns an expanded-id-table mapping expanded-identifiers to empty lists,
160+
;; with one entry for each binding site in the syntax.
156161
(define (fully-expanded-syntax-id-table stx)
157162
;; stx is expected to already have phase labels via syntax-label-id-phases
158163
(define table (make-expanded-id-table))

default-recommendations/analyzers/variable-mutability.rkt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@
4747
(define (variable-mutability stx)
4848
(define labeled-stx (syntax-label-id-phases (syntax-label-paths stx 'expanded-path)))
4949

50-
;; Create table with all bound identifiers initialized to 'immutable
51-
(define variable-table (fully-expanded-syntax-id-table labeled-stx))
52-
53-
;; Initialize all entries with 'immutable
54-
(for ([entry (in-expanded-id-table variable-table)])
55-
(expanded-id-table-set! variable-table (entry-key entry) 'immutable))
50+
;; Create table and initialize all bound identifiers with 'immutable
51+
(define variable-table (make-expanded-id-table))
52+
(for ([id (in-stream (binding-site-identifiers labeled-stx))])
53+
(define phase (syntax-property id 'phase))
54+
(expanded-id-table-set! variable-table (expanded-identifier id phase) 'immutable))
5655

5756
;; Mark mutated variables as 'mutable
5857
(for ([id (in-stream (mutated-variables labeled-stx))])

0 commit comments

Comments
 (0)