From 293facfdf643d70d47c64bc526cd54c31bb64f27 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Wed, 21 Oct 2026 12:20:12 -0500 Subject: [PATCH] Group record-flow references by symbol once per name --- .../lowering/runtime-optional-records.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/compiler/src/frontend/lowering/runtime-optional-records.ts b/packages/compiler/src/frontend/lowering/runtime-optional-records.ts index 18e136d69..7f1bb046a 100644 --- a/packages/compiler/src/frontend/lowering/runtime-optional-records.ts +++ b/packages/compiler/src/frontend/lowering/runtime-optional-records.ts @@ -81,7 +81,9 @@ export class RecordFlowClasses { /** Identifiers by name; symbols resolve only for the names of slots and * functions, so the scan asks the checker about few nodes. */ private readonly names = new Map(); - private readonly references = new Map(); + /** The identifiers of each name grouped by the symbol they resolve to, + * built on the first reference query for that name. */ + private readonly references = new Map>(); /** Names written as shorthand properties (`{ p }`): the checker resolves * those to the property, so a binding of that name stays open. */ private readonly shorthandNames = new Set(); @@ -349,14 +351,20 @@ export class RecordFlowClasses { /** The identifiers that name `symbol`, its declaration included. */ private referencesOf(symbol: ts.Symbol): readonly ts.Identifier[] { - let list = this.references.get(symbol); - if (!list) { - list = (this.names.get(ts.symbolName(symbol)) ?? []).filter( - (node) => this.host.symbolOf(node) === symbol, - ); - this.references.set(symbol, list); + const name = ts.symbolName(symbol); + let bySymbol = this.references.get(name); + if (!bySymbol) { + bySymbol = new Map(); + for (const node of this.names.get(name) ?? []) { + const resolved = this.host.symbolOf(node); + if (!resolved) continue; + const list = bySymbol.get(resolved); + if (list) list.push(node); + else bySymbol.set(resolved, [node]); + } + this.references.set(name, bySymbol); } - return list; + return bySymbol.get(symbol) ?? []; } private collectFunctions(): void {