Skip to content

Commit 19f1d3b

Browse files
committed
Less aggressive monomorphism for flow nodes
1 parent d5e08d4 commit 19f1d3b

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

src/compiler/binder.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ namespace ts {
148148
let Symbol: new (flags: SymbolFlags, name: __String) => Symbol; // tslint:disable-line variable-name
149149
let classifiableNames: UnderscoreEscapedMap<true>;
150150

151-
const unreachableFlow = createFlowNode(FlowFlags.Unreachable, /*antecedent*/ undefined, /*node*/ undefined);
152-
const reportedUnreachableFlow: FlowNode = createFlowNode(FlowFlags.Unreachable, /*antecedent*/ undefined, /*node*/ undefined);
151+
const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
152+
const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
153153

154154
// state used to aggregate transform flags during bind.
155155
let subtreeTransformFlags: TransformFlags = TransformFlags.None;
@@ -560,7 +560,7 @@ namespace ts {
560560
// A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave
561561
// similarly to break statements that exit to a label just past the statement body.
562562
if (!isIIFE) {
563-
currentFlow = createFlowNode(FlowFlags.Start, /*antecedent*/ undefined, /*node*/ undefined) as FlowStart;
563+
currentFlow = { flags: FlowFlags.Start };
564564
if (containerFlags & (ContainerFlags.IsFunctionExpression | ContainerFlags.IsObjectLiteralOrClassExpressionMethod)) {
565565
currentFlow.node = <FunctionExpression | ArrowFunction | MethodDeclaration>node;
566566
}
@@ -842,22 +842,12 @@ namespace ts {
842842
return isNarrowableReference(expr);
843843
}
844844

845-
function createFlowNode(flags: FlowFlags, antecedent: FlowNode | undefined, node: Node | undefined) {
846-
return {
847-
flags,
848-
antecedent,
849-
node,
850-
id: undefined,
851-
antecedents: undefined,
852-
} as FlowNode;
853-
}
854-
855845
function createBranchLabel(): FlowLabel {
856-
return createFlowNode(FlowFlags.BranchLabel, /*antecedent*/ undefined, /*node*/ undefined) as FlowLabel;
846+
return { flags: FlowFlags.BranchLabel, antecedents: undefined };
857847
}
858848

859849
function createLoopLabel(): FlowLabel {
860-
return createFlowNode(FlowFlags.LoopLabel, /*antecedent*/ undefined, /*node*/ undefined) as FlowLabel;
850+
return { flags: FlowFlags.LoopLabel, antecedents: undefined };
861851
}
862852

863853
function setFlowNodeReferenced(flow: FlowNode) {
@@ -887,34 +877,30 @@ namespace ts {
887877
return antecedent;
888878
}
889879
setFlowNodeReferenced(antecedent);
890-
return flowNodeCreated(createFlowNode(flags, antecedent, expression));
880+
return flowNodeCreated({ flags, antecedent, node: expression });
891881
}
892882

893883
function createFlowSwitchClause(antecedent: FlowNode, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): FlowNode {
894884
if (!isNarrowingExpression(switchStatement.expression)) {
895885
return antecedent;
896886
}
897887
setFlowNodeReferenced(antecedent);
898-
const result = createFlowNode(FlowFlags.SwitchClause, antecedent, /*node*/ undefined) as FlowSwitchClause;
899-
result.switchStatement = switchStatement;
900-
result.clauseStart = clauseStart;
901-
result.clauseEnd = clauseEnd;
902-
return flowNodeCreated(result);
888+
return flowNodeCreated({ flags: FlowFlags.SwitchClause, antecedent, switchStatement, clauseStart, clauseEnd });
903889
}
904890

905891
function createFlowAssignment(antecedent: FlowNode, node: Expression | VariableDeclaration | BindingElement): FlowNode {
906892
setFlowNodeReferenced(antecedent);
907-
return flowNodeCreated(createFlowNode(FlowFlags.Assignment, antecedent, node));
893+
return flowNodeCreated({ flags: FlowFlags.Assignment, antecedent, node });
908894
}
909895

910896
function createFlowCall(antecedent: FlowNode, node: CallExpression): FlowNode {
911897
setFlowNodeReferenced(antecedent);
912-
return flowNodeCreated(createFlowNode(FlowFlags.Call, antecedent, node));
898+
return flowNodeCreated({ flags: FlowFlags.Call, antecedent, node });
913899
}
914900

915901
function createFlowArrayMutation(antecedent: FlowNode, node: CallExpression | BinaryExpression): FlowNode {
916902
setFlowNodeReferenced(antecedent);
917-
return flowNodeCreated(createFlowNode(FlowFlags.ArrayMutation, antecedent, node));
903+
return flowNodeCreated({ flags: FlowFlags.ArrayMutation, antecedent, node });
918904
}
919905

920906
function finishFlowLabel(flow: FlowLabel): FlowNode {
@@ -1192,8 +1178,7 @@ namespace ts {
11921178
//
11931179
// extra edges that we inject allows to control this behavior
11941180
// if when walking the flow we step on post-finally edge - we can mark matching pre-finally edge as locked so it will be skipped.
1195-
const preFinallyFlow = createFlowNode(FlowFlags.PreFinally, preFinallyPrior, /*node*/ undefined) as PreFinallyFlow;
1196-
preFinallyFlow.lock = {};
1181+
const preFinallyFlow: PreFinallyFlow = { flags: FlowFlags.PreFinally, antecedent: preFinallyPrior, lock: {} };
11971182
addAntecedent(preFinallyLabel, preFinallyFlow);
11981183

11991184
currentFlow = finishFlowLabel(preFinallyLabel);
@@ -1212,7 +1197,7 @@ namespace ts {
12121197
}
12131198
}
12141199
if (!(currentFlow.flags & FlowFlags.Unreachable)) {
1215-
const afterFinallyFlow = flowNodeCreated(createFlowNode(FlowFlags.AfterFinally, currentFlow, /*node*/ undefined) as AfterFinallyFlow);
1200+
const afterFinallyFlow: AfterFinallyFlow = flowNodeCreated({ flags: FlowFlags.AfterFinally, antecedent: currentFlow });
12161201
preFinallyFlow.lock = afterFinallyFlow;
12171202
currentFlow = afterFinallyFlow;
12181203
}
@@ -1836,7 +1821,7 @@ namespace ts {
18361821
const host = getJSDocHost(typeAlias);
18371822
container = findAncestor(host.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer)) || file;
18381823
blockScopeContainer = getEnclosingBlockScopeContainer(host) || file;
1839-
currentFlow = createFlowNode(FlowFlags.Start, /*antecedent*/ undefined, /*node*/ undefined);
1824+
currentFlow = { flags: FlowFlags.Start };
18401825
parent = typeAlias;
18411826
bind(typeAlias.typeExpression);
18421827
if (isJSDocEnumTag(typeAlias) || !typeAlias.fullName || typeAlias.fullName.kind === SyntaxKind.Identifier) {

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@ namespace ts {
25782578

25792579
export interface FlowNodeBase {
25802580
flags: FlowFlags;
2581-
id: number | undefined; // Node id used by flow type cache in checker
2581+
id?: number; // Node id used by flow type cache in checker
25822582
}
25832583

25842584
export interface FlowLock {

0 commit comments

Comments
 (0)