Skip to content

Commit 36489ff

Browse files
committed
Add instantaneous events when depth limits are hit
1 parent 7b40895 commit 36489ff

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10804,6 +10804,7 @@ namespace ts {
1080410804
// very high likelihood we're dealing with an infinite generic type that perpetually generates
1080510805
// new type identities as we descend into it. We stop the recursion here and mark this type
1080610806
// and the outer types as having circular constraints.
10807+
tracing.instant(tracing.Phase.Check, "getImmediateBaseConstraint_DepthLimit", { typeId: t.id, originalTypeId: type.id, depth: constraintDepth });
1080710808
error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
1080810809
nonTerminating = true;
1080910810
return t.immediateBaseConstraint = noConstraintType;
@@ -12878,6 +12879,7 @@ namespace ts {
1287812879
// caps union types at 5000 unique literal types and 1000 unique object types.
1287912880
const estimatedCount = (count / (len - i)) * len;
1288012881
if (estimatedCount > (primitivesOnly ? 25000000 : 1000000)) {
12882+
tracing.instant(tracing.Phase.Check, "removeSubtypes_DepthLimit", { typeIds: types.map(t => t.id) });
1288112883
error(currentNode, Diagnostics.Expression_produces_a_union_type_that_is_too_complex_to_represent);
1288212884
return false;
1288312885
}
@@ -14940,6 +14942,7 @@ namespace ts {
1494014942
// We have reached 50 recursive type instantiations and there is a very high likelyhood we're dealing
1494114943
// with a combination of infinite generic types that perpetually generate new type identities. We stop
1494214944
// the recursion here by yielding the error type.
14945+
tracing.instant(tracing.Phase.Check, "instantiateType_DepthLimit", { typeId: type.id, instantiationDepth, instantiationCount });
1494314946
error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
1494414947
return errorType;
1494514948
}
@@ -16058,6 +16061,7 @@ namespace ts {
1605816061
reportIncompatibleStack();
1605916062
}
1606016063
if (overflow) {
16064+
tracing.instant(tracing.Phase.Check, "checkTypeRelatedTo_DepthLimit", { sourceId: source.id, targetId: target.id, depth });
1606116065
const diag = error(errorNode || currentNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
1606216066
if (errorOutputContainer) {
1606316067
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
@@ -17358,6 +17362,7 @@ namespace ts {
1735817362
numCombinations *= countTypes(getTypeOfSymbol(sourceProperty));
1735917363
if (numCombinations > 25) {
1736017364
// We've reached the complexity limit.
17365+
tracing.instant(tracing.Phase.Check, "typeRelatedToDiscriminatedType_DepthLimit", { sourceId: source.id, targetId: target.id, numCombinations });
1736117366
return Ternary.False;
1736217367
}
1736317368
}
@@ -18281,7 +18286,10 @@ namespace ts {
1828118286
for (let i = 0; i < depth; i++) {
1828218287
if (getRecursionIdentity(stack[i]) === identity) {
1828318288
count++;
18284-
if (count >= 5) return true;
18289+
if (count >= 5) {
18290+
tracing.instant(tracing.Phase.Check, "isDeeplyNestedType_DepthLimit", { typeId: type.id, typeIdStack: stack.map(t => t.id), depth, count });
18291+
return true;
18292+
}
1828518293
}
1828618294
}
1828718295
}
@@ -21089,6 +21097,7 @@ namespace ts {
2108921097
if (flowDepth === 2000) {
2109021098
// We have made 2000 recursive invocations. To avoid overflowing the call stack we report an error
2109121099
// and disable further control flow analysis in the containing function or module body.
21100+
tracing.instant(tracing.Phase.Check, "getTypeAtFlowNode_DepthLimit", { flowId: flow.id });
2109221101
flowAnalysisDisabled = true;
2109321102
reportFlowControlError(reference);
2109421103
return errorType;

src/compiler/tracing.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ namespace ts.tracing {
112112
performance.measure("Tracing", "beginTracing", "endTracing");
113113
}
114114

115+
export function instant(phase: Phase, name: string, args: object) {
116+
if (!traceFd) {
117+
return;
118+
}
119+
Debug.assert(fs);
120+
121+
performance.mark("beginTracing");
122+
fs.writeSync(traceFd, `{"pid":1,"tid":1,"ph":"i","cat":"${phase}","ts":${1000 * timestamp()},"name":"${name}","s":"g","args":{ "ts": ${JSON.stringify(args)} }},\n`);
123+
performance.mark("endTracing");
124+
performance.measure("Tracing", "beginTracing", "endTracing");
125+
}
126+
115127
function indexFromOne(lc: LineAndCharacter): LineAndCharacter {
116128
return {
117129
line: lc.line + 1,

0 commit comments

Comments
 (0)