Skip to content

Commit

Permalink
Properly cache types for shared control flow nodes (#41665) (#41906)
Browse files Browse the repository at this point in the history
* Properly cache shared flow node types

* Add test

Co-authored-by: Anders Hejlsberg <[email protected]>
  • Loading branch information
JoostK and ahejlsberg authored Dec 10, 2020
1 parent 1e9518c commit 3c73625
Show file tree
Hide file tree
Showing 5 changed files with 950 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21702,6 +21702,7 @@ namespace ts {
return errorType;
}
flowDepth++;
let sharedFlow: FlowNode | undefined;
while (true) {
const flags = flow.flags;
if (flags & FlowFlags.Shared) {
Expand All @@ -21714,6 +21715,7 @@ namespace ts {
return sharedFlowTypes[i];
}
}
sharedFlow = flow;
}
let type: FlowType | undefined;
if (flags & FlowFlags.Assignment) {
Expand Down Expand Up @@ -21777,9 +21779,9 @@ namespace ts {
// simply return the non-auto declared type to reduce follow-on errors.
type = convertAutoToAny(declaredType);
}
if (flags & FlowFlags.Shared) {
if (sharedFlow) {
// Record visited node and the associated type in the cache.
sharedFlowNodes[sharedFlowCount] = flow;
sharedFlowNodes[sharedFlowCount] = sharedFlow;
sharedFlowTypes[sharedFlowCount] = type;
sharedFlowCount++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//// [controlFlowManyCallExpressionStatementsPerf.ts]
function test(x: boolean): boolean { return x; }

let state = true;

if (state) {
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
test(state as any && state);
}


//// [controlFlowManyCallExpressionStatementsPerf.js]
"use strict";
function test(x) { return x; }
var state = true;
if (state) {
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
test(state && state);
}
Loading

0 comments on commit 3c73625

Please sign in to comment.