/** * The flow-fact store: what every binding and every member path is known to * hold at one moment, and how one moment is snapshotted, restored, and * compared against another. * * D114 R1d: this was four private fields of `Analyzer` (`memberNarrowings`, * `narrowedNames`, `flowTouched`, `flowOrigins`) and the dozen methods that * read and wrote them, spread across 13,000 lines. They are one thing — the * answer to "what does flow analysis currently believe, and what did it * believe a moment ago" — so they live in one collaborator the analyzer owns * as `this.flowFacts`. The narrowing, loop and merge halves of the cluster * (`./narrowing.ts`, `./loops.ts`, `./merge.ts`) read this store through the * same shared host object rather than keeping copies of it. * * What the store asks of its host is one call — `applyFlowInvalidations`, * which belongs to the merge half — and that is declared as `FlowFactsHost`. */ import { type ValueType } from "../../types.ts"; import { type Binding, type MemberNarrowing } from "../scopes.ts"; /** The four flow-analysis fields of a binding, as of one moment. */ export interface FlowFactState { readonly type: ValueType; readonly storageType: ValueType; readonly frame: number | null; readonly assigned: boolean; } export interface FlowFactsSnapshot { readonly bindings: ReadonlyMap; readonly members: readonly ReadonlyMap[]; } export interface FlowFactInvalidations { readonly bindings: ReadonlySet; readonly members: ReadonlyMap>; readonly storageTypes: ReadonlyMap; } /** * Everything the flow-fact store asks of the analyzer that hosts it, and * nothing more. */ export interface FlowFactsHost { applyFlowInvalidations(branches: readonly FlowFactInvalidations[], includeBaseline?: boolean): void; } export declare class FlowFacts { private readonly host; readonly memberNarrowings: Map[]; /** Per scope depth, the names a narrowing has written there; see `narrowingsForVisibleBindings`. */ readonly narrowedNames: Set[]; /** Per scope depth, the bindings flow analysis has written; see `snapshotFlowFacts`. */ private readonly flowTouched; /** What each of those held before its first write, or null for a shadow born mid-flow. */ private readonly flowOrigins; constructor(host: FlowFactsHost); /** The three per-scope stacks this store keeps, pushed with the scope that owns them. */ enterScope(): void; exitScope(): void; /** * A snapshot used to copy every binding of every live scope, which made a * branch cost O(names in the module) and whole-module analysis quadratic in * module size. A binding nothing ever narrows cannot differ between two * moments, so only the bindings flow analysis has actually written are * visited — `flowTouched`, kept per scope depth so an exiting scope drops * its own, and `flowOrigins`, which remembers what each one held before its * first write. `flowOrigins` answers for a binding a *later* write touched * than the snapshot being restored: the snapshot has no entry, and its * pre-write state is exactly the state that snapshot recorded. A narrowing * shadow born after the snapshot stores `null` instead, because a full-scope * snapshot had nothing to restore it to either. */ flowFactState(binding: Binding): FlowFactState; /** Called immediately before flow analysis writes a binding, so the recorded state is the pre-write one. */ recordFlowFactOrigin(binding: Binding): void; /** A narrowing shadow created mid-flow: no older snapshot has a state for it. */ trackNarrowingShadow(shadow: Binding): void; private trackFlowBinding; /** Every binding whose flow facts may differ from another moment's, outermost scope first. */ private touchedFlowBindings; /** The state `snapshot` recorded for `binding`, or null when it did not exist yet. */ private flowStateIn; snapshotFlowFacts(): FlowFactsSnapshot; restoreFlowFacts(snapshot: FlowFactsSnapshot): void; analyzeIsolatedFlow(snapshot: FlowFactsSnapshot, analyze: () => void): FlowFactInvalidations; flowInvalidationsSince(snapshot: FlowFactsSnapshot): FlowFactInvalidations; flowSnapshotAfterInvalidations(baseline: FlowFactsSnapshot, invalidations: readonly FlowFactInvalidations[]): FlowFactsSnapshot; } //# sourceMappingURL=facts.d.ts.map