Skip to content

Commit 3c73625

Browse files
JoostKahejlsberg
andauthored
Properly cache types for shared control flow nodes (#41665) (#41906)
* Properly cache shared flow node types * Add test Co-authored-by: Anders Hejlsberg <[email protected]>
1 parent 1e9518c commit 3c73625

5 files changed

+950
-2
lines changed

src/compiler/checker.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -21702,6 +21702,7 @@ namespace ts {
2170221702
return errorType;
2170321703
}
2170421704
flowDepth++;
21705+
let sharedFlow: FlowNode | undefined;
2170521706
while (true) {
2170621707
const flags = flow.flags;
2170721708
if (flags & FlowFlags.Shared) {
@@ -21714,6 +21715,7 @@ namespace ts {
2171421715
return sharedFlowTypes[i];
2171521716
}
2171621717
}
21718+
sharedFlow = flow;
2171721719
}
2171821720
let type: FlowType | undefined;
2171921721
if (flags & FlowFlags.Assignment) {
@@ -21777,9 +21779,9 @@ namespace ts {
2177721779
// simply return the non-auto declared type to reduce follow-on errors.
2177821780
type = convertAutoToAny(declaredType);
2177921781
}
21780-
if (flags & FlowFlags.Shared) {
21782+
if (sharedFlow) {
2178121783
// Record visited node and the associated type in the cache.
21782-
sharedFlowNodes[sharedFlowCount] = flow;
21784+
sharedFlowNodes[sharedFlowCount] = sharedFlow;
2178321785
sharedFlowTypes[sharedFlowCount] = type;
2178421786
sharedFlowCount++;
2178521787
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
//// [controlFlowManyCallExpressionStatementsPerf.ts]
2+
function test(x: boolean): boolean { return x; }
3+
4+
let state = true;
5+
6+
if (state) {
7+
test(state as any && state);
8+
test(state as any && state);
9+
test(state as any && state);
10+
test(state as any && state);
11+
test(state as any && state);
12+
test(state as any && state);
13+
test(state as any && state);
14+
test(state as any && state);
15+
test(state as any && state);
16+
test(state as any && state);
17+
test(state as any && state);
18+
test(state as any && state);
19+
test(state as any && state);
20+
test(state as any && state);
21+
test(state as any && state);
22+
test(state as any && state);
23+
test(state as any && state);
24+
test(state as any && state);
25+
test(state as any && state);
26+
test(state as any && state);
27+
test(state as any && state);
28+
test(state as any && state);
29+
test(state as any && state);
30+
test(state as any && state);
31+
test(state as any && state);
32+
test(state as any && state);
33+
test(state as any && state);
34+
test(state as any && state);
35+
test(state as any && state);
36+
test(state as any && state);
37+
test(state as any && state);
38+
test(state as any && state);
39+
test(state as any && state);
40+
test(state as any && state);
41+
test(state as any && state);
42+
test(state as any && state);
43+
test(state as any && state);
44+
test(state as any && state);
45+
test(state as any && state);
46+
test(state as any && state);
47+
test(state as any && state);
48+
test(state as any && state);
49+
test(state as any && state);
50+
test(state as any && state);
51+
test(state as any && state);
52+
test(state as any && state);
53+
test(state as any && state);
54+
test(state as any && state);
55+
test(state as any && state);
56+
test(state as any && state);
57+
test(state as any && state);
58+
test(state as any && state);
59+
test(state as any && state);
60+
test(state as any && state);
61+
test(state as any && state);
62+
test(state as any && state);
63+
}
64+
65+
66+
//// [controlFlowManyCallExpressionStatementsPerf.js]
67+
"use strict";
68+
function test(x) { return x; }
69+
var state = true;
70+
if (state) {
71+
test(state && state);
72+
test(state && state);
73+
test(state && state);
74+
test(state && state);
75+
test(state && state);
76+
test(state && state);
77+
test(state && state);
78+
test(state && state);
79+
test(state && state);
80+
test(state && state);
81+
test(state && state);
82+
test(state && state);
83+
test(state && state);
84+
test(state && state);
85+
test(state && state);
86+
test(state && state);
87+
test(state && state);
88+
test(state && state);
89+
test(state && state);
90+
test(state && state);
91+
test(state && state);
92+
test(state && state);
93+
test(state && state);
94+
test(state && state);
95+
test(state && state);
96+
test(state && state);
97+
test(state && state);
98+
test(state && state);
99+
test(state && state);
100+
test(state && state);
101+
test(state && state);
102+
test(state && state);
103+
test(state && state);
104+
test(state && state);
105+
test(state && state);
106+
test(state && state);
107+
test(state && state);
108+
test(state && state);
109+
test(state && state);
110+
test(state && state);
111+
test(state && state);
112+
test(state && state);
113+
test(state && state);
114+
test(state && state);
115+
test(state && state);
116+
test(state && state);
117+
test(state && state);
118+
test(state && state);
119+
test(state && state);
120+
test(state && state);
121+
test(state && state);
122+
test(state && state);
123+
test(state && state);
124+
test(state && state);
125+
test(state && state);
126+
test(state && state);
127+
}

0 commit comments

Comments
 (0)