Skip to content

Commit

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

* Add test
  • Loading branch information
ahejlsberg authored and JoostK committed Dec 9, 2020
1 parent 1e9518c commit 0ebfeb4
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
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
@@ -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);
}

0 comments on commit 0ebfeb4

Please sign in to comment.