Skip to content

Commit def5e37

Browse files
committed
Revert "More efficient scheme for caching flow node reachability"
This reverts commit e97ebb7.
1 parent e97ebb7 commit def5e37

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace ts {
66
let nextNodeId = 1;
77
let nextMergeId = 1;
88
let nextFlowId = 1;
9-
let nextCheckerId = 1;
109

1110
const enum IterationUse {
1211
AllowsSyncIterablesFlag = 1 << 0,
@@ -299,7 +298,6 @@ namespace ts {
299298
let instantiationDepth = 0;
300299
let constraintDepth = 0;
301300
let currentNode: Node | undefined;
302-
let checkerId: number;
303301

304302
const emptySymbols = createSymbolTable();
305303
const identityMapper: (type: Type) => Type = identity;
@@ -844,6 +842,7 @@ namespace ts {
844842
const flowLoopTypes: Type[][] = [];
845843
const sharedFlowNodes: FlowNode[] = [];
846844
const sharedFlowTypes: FlowType[] = [];
845+
const flowNodeReachable: (boolean | undefined)[] = [];
847846
const potentialThisCollisions: Node[] = [];
848847
const potentialNewTargetCollisions: Node[] = [];
849848
const awaitedTypeStack: number[] = [];
@@ -16994,21 +16993,17 @@ namespace ts {
1699416993
}
1699516994

1699616995
function isReachableFlowNode(flow: FlowNode) {
16997-
return isReachableFlowNodeWorker(flow, /*noCacheCheck*/ false);
16996+
return isReachableFlowNodeWorker(flow, /*skipCacheCheck*/ false);
1699816997
}
1699916998

1700016999
function isReachableFlowNodeWorker(flow: FlowNode, noCacheCheck: boolean): boolean {
1700117000
while (true) {
1700217001
const flags = flow.flags;
17003-
if (flags & (FlowFlags.Shared | FlowFlags.Assignment | FlowFlags.Label)) {
17002+
if (flags & FlowFlags.Shared) {
1700417003
if (!noCacheCheck) {
17005-
if (flow.checkerId === checkerId) {
17006-
return !!(flow.flags & FlowFlags.Reachable);
17007-
}
17008-
const reachable = isReachableFlowNodeWorker(flow, /*noCacheCheck*/ true);
17009-
flow.checkerId = checkerId;
17010-
flow.flags = (flow.flags & ~FlowFlags.Reachable) | (reachable ? FlowFlags.Reachable : 0);
17011-
return reachable;
17004+
const id = getFlowNodeId(flow);
17005+
const reachable = flowNodeReachable[id];
17006+
return reachable !== undefined ? reachable : (flowNodeReachable[id] = isReachableFlowNodeWorker(flow, /*skipCacheCheck*/ true));
1701217007
}
1701317008
noCacheCheck = false;
1701417009
}
@@ -32292,9 +32287,6 @@ namespace ts {
3229232287
}
3229332288

3229432289
function initializeTypeChecker() {
32295-
checkerId = nextCheckerId;
32296-
nextCheckerId++;
32297-
3229832290
// Bind all source files and propagate errors
3229932291
for (const file of host.getSourceFiles()) {
3230032292
bindSourceFile(file, compilerOptions);

src/compiler/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,8 +2582,6 @@ namespace ts {
25822582
AfterFinally = 1 << 13, // Injected edge that links post-finally flow with the rest of the graph
25832583
/** @internal */
25842584
Cached = 1 << 14, // Indicates that at least one cross-call cache entry exists for this node, even if not a loop participant
2585-
/** @internal */
2586-
Reachable = 1 << 15, // Reachability as computed by isReachableFlowNode
25872585
Label = BranchLabel | LoopLabel,
25882586
Condition = TrueCondition | FalseCondition
25892587
}
@@ -2602,8 +2600,6 @@ namespace ts {
26022600
export interface FlowNodeBase {
26032601
flags: FlowFlags;
26042602
id?: number; // Node id used by flow type cache in checker
2605-
/** @internal */
2606-
checkerId?: number; // Checker id for FlowFlags.Reachable
26072603
}
26082604

26092605
export interface FlowLock {

0 commit comments

Comments
 (0)