Skip to content

Commit 958da12

Browse files
committed
Cache more outputs, accept elaboration-omitting baselines
1 parent 7f97caa commit 958da12

14 files changed

+8
-56
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8953,7 +8953,7 @@ namespace ts {
89538953
}
89548954

89558955
if (relation === identityRelation) {
8956-
return isIdenticalTo(source, target);
8956+
return cacheResult(isIdenticalTo(source, target), comparisonId, /*reportErrors*/ false);
89578957
}
89588958

89598959
if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
@@ -8963,7 +8963,7 @@ namespace ts {
89638963
if (reportErrors) {
89648964
reportRelationError(headMessage, source, target);
89658965
}
8966-
return Ternary.False;
8966+
return cacheResult(Ternary.False, comparisonId, reportErrors);
89678967
}
89688968
// Above we check for excess properties with respect to the entire target type. When union
89698969
// and intersection types are further deconstructed on the target side, we don't want to
@@ -8995,6 +8995,7 @@ namespace ts {
89958995
reportError(Diagnostics.Type_0_has_no_properties_in_common_with_type_1, typeToString(source), typeToString(target));
89968996
}
89978997
}
8998+
// Intentionally not cached, so common property errors are repeated
89988999
return Ternary.False;
89999000
}
90009001

@@ -9048,10 +9049,13 @@ namespace ts {
90489049
reportElaboratedRelationError(headMessage, source, target);
90499050
}
90509051

9052+
return cacheResult(result, comparisonId, reportErrors);
9053+
}
9054+
9055+
function cacheResult(result: Ternary, comparisonId: string, reportErrors?: boolean) {
90519056
if (!relation.has(comparisonId) && result !== Ternary.Maybe) {
90529057
relation.set(comparisonId, result ? RelationComparisonResult.Succeeded : reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed);
90539058
}
9054-
90559059
return result;
90569060
}
90579061

tests/baselines/reference/arityAndOrderCompatibility01.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error
3535
Types of property 'pop' are incompatible.
3636
Type '() => string | number' is not assignable to type '() => string'.
3737
Type 'string | number' is not assignable to type 'string'.
38-
Type 'number' is not assignable to type 'string'.
3938
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string]'.
4039
Property 'length' is missing in type '{ 0: string; 1: number; }'.
4140
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'.
@@ -127,7 +126,6 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error
127126
!!! error TS2322: Types of property 'pop' are incompatible.
128127
!!! error TS2322: Type '() => string | number' is not assignable to type '() => string'.
129128
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
130-
!!! error TS2322: Type 'number' is not assignable to type 'string'.
131129
var m3: [string] = z;
132130
~~
133131
!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string]'.

tests/baselines/reference/callWithSpread2.errors.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(30,5): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
22
Type 'string' is not assignable to type 'number'.
33
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(31,5): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
4-
Type 'string' is not assignable to type 'number'.
54
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(32,13): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
6-
Type 'string' is not assignable to type 'number'.
75
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(33,13): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
8-
Type 'string' is not assignable to type 'number'.
96
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(34,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
10-
Type 'string' is not assignable to type 'number'.
117
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(35,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
12-
Type 'string' is not assignable to type 'number'.
138
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(36,1): error TS2556: Expected 1-3 arguments, but got a minimum of 0.
149
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(37,1): error TS2556: Expected 1-3 arguments, but got a minimum of 0.
1510
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(38,1): error TS2556: Expected 1-3 arguments, but got a minimum of 0.
@@ -52,23 +47,18 @@ tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(38,1): erro
5247
all(...tuple)
5348
~~~~~~~~
5449
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
55-
!!! error TS2345: Type 'string' is not assignable to type 'number'.
5650
prefix("b", ...mixed)
5751
~~~~~~~~
5852
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
59-
!!! error TS2345: Type 'string' is not assignable to type 'number'.
6053
prefix("c", ...tuple)
6154
~~~~~~~~
6255
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
63-
!!! error TS2345: Type 'string' is not assignable to type 'number'.
6456
rest("e", ...mixed)
6557
~~~~~~~~
6658
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
67-
!!! error TS2345: Type 'string' is not assignable to type 'number'.
6859
rest("f", ...tuple)
6960
~~~~~~~~
7061
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
71-
!!! error TS2345: Type 'string' is not assignable to type 'number'.
7262
prefix(...ns) // required parameters are required
7363
~~~~~~~~~~~~~
7464
!!! error TS2556: Expected 1-3 arguments, but got a minimum of 0.

tests/baselines/reference/checkJsxChildrenProperty7.errors.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ tests/cases/conformance/jsx/file.tsx(25,16): error TS2322: Type '{ a: 10; b: "hi
99
Type '{ a: 10; b: "hi"; children: (string | Element)[]; }' is not assignable to type 'Prop'.
1010
Types of property 'children' are incompatible.
1111
Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
12-
Type '(string | Element)[]' is not assignable to type 'Element[]'.
1312
tests/cases/conformance/jsx/file.tsx(27,16): error TS2322: Type '{ a: 10; b: "hi"; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
1413
Type '{ a: 10; b: "hi"; children: (string | Element)[]; }' is not assignable to type 'Prop'.
1514
Types of property 'children' are incompatible.
1615
Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
17-
Type '(string | Element)[]' is not assignable to type 'Element[]'.
1816

1917

2018
==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
@@ -56,13 +54,11 @@ tests/cases/conformance/jsx/file.tsx(27,16): error TS2322: Type '{ a: 10; b: "hi
5654
!!! error TS2322: Type '{ a: 10; b: "hi"; children: (string | Element)[]; }' is not assignable to type 'Prop'.
5755
!!! error TS2322: Types of property 'children' are incompatible.
5856
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
59-
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element[]'.
6057
<AnotherButton /> </Comp>;
6158
let k3 = <Comp a={10} b="hi"> <Button />
6259
~~~~~~~~~~~~~
6360
!!! error TS2322: Type '{ a: 10; b: "hi"; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
6461
!!! error TS2322: Type '{ a: 10; b: "hi"; children: (string | Element)[]; }' is not assignable to type 'Prop'.
6562
!!! error TS2322: Types of property 'children' are incompatible.
6663
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
67-
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element[]'.
6864
<AnotherButton /></Comp>;

tests/baselines/reference/contextualTypeWithTuple.errors.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(24,1): error TS23
1818
Property '2' is missing in type '[C, string | number]'.
1919
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS2322: Type '[number, string | number]' is not assignable to type '[number, string]'.
2020
Type 'string | number' is not assignable to type 'string'.
21-
Type 'number' is not assignable to type 'string'.
2221

2322

2423
==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (7 errors) ====
@@ -73,5 +72,4 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23
7372
numStrTuple = unionTuple3;
7473
~~~~~~~~~~~
7574
!!! error TS2322: Type '[number, string | number]' is not assignable to type '[number, string]'.
76-
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
77-
!!! error TS2322: Type 'number' is not assignable to type 'string'.
75+
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.

tests/baselines/reference/contextualTypeWithUnionTypeObjectLiteral.errors.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,23 @@ tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(
77
Type '{ prop: string | number; }' is not assignable to type '{ prop: number; }'.
88
Types of property 'prop' are incompatible.
99
Type 'string | number' is not assignable to type 'number'.
10-
Type 'string' is not assignable to type 'number'.
1110
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(21,5): error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; }'.
1211
Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: number; }'.
1312
Types of property 'prop' are incompatible.
1413
Type 'string | number' is not assignable to type 'number'.
15-
Type 'string' is not assignable to type 'number'.
1614
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(25,5): error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; anotherP1: number; }'.
1715
Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: number; anotherP1: number; }'.
1816
Types of property 'prop' are incompatible.
1917
Type 'string | number' is not assignable to type 'number'.
20-
Type 'string' is not assignable to type 'number'.
2118
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(29,5): error TS2322: Type '{ prop: string | number; anotherP: string; anotherP1: number; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; anotherP1: number; }'.
2219
Type '{ prop: string | number; anotherP: string; anotherP1: number; }' is not assignable to type '{ prop: number; anotherP1: number; }'.
2320
Types of property 'prop' are incompatible.
2421
Type 'string | number' is not assignable to type 'number'.
25-
Type 'string' is not assignable to type 'number'.
2622
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(57,5): error TS2322: Type '{ commonMethodDifferentReturnType: (a: string, b: number) => string | number; }' is not assignable to type 'I11 | I21'.
2723
Type '{ commonMethodDifferentReturnType: (a: string, b: number) => string | number; }' is not assignable to type 'I21'.
2824
Types of property 'commonMethodDifferentReturnType' are incompatible.
2925
Type '(a: string, b: number) => string | number' is not assignable to type '(a: string, b: number) => number'.
3026
Type 'string | number' is not assignable to type 'number'.
31-
Type 'string' is not assignable to type 'number'.
3227

3328

3429
==== tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts (6 errors) ====
@@ -63,14 +58,12 @@ tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(
6358
!!! error TS2322: Type '{ prop: string | number; }' is not assignable to type '{ prop: number; }'.
6459
!!! error TS2322: Types of property 'prop' are incompatible.
6560
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
66-
!!! error TS2322: Type 'string' is not assignable to type 'number'.
6761
var objStrOrNum6: { prop: string; anotherP: string; } | { prop: number } = {
6862
~~~~~~~~~~~~
6963
!!! error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; }'.
7064
!!! error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: number; }'.
7165
!!! error TS2322: Types of property 'prop' are incompatible.
7266
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
73-
!!! error TS2322: Type 'string' is not assignable to type 'number'.
7467
prop: strOrNumber,
7568
anotherP: str
7669
};
@@ -80,7 +73,6 @@ tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(
8073
!!! error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: number; anotherP1: number; }'.
8174
!!! error TS2322: Types of property 'prop' are incompatible.
8275
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
83-
!!! error TS2322: Type 'string' is not assignable to type 'number'.
8476
prop: strOrNumber,
8577
anotherP: str
8678
};
@@ -90,7 +82,6 @@ tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(
9082
!!! error TS2322: Type '{ prop: string | number; anotherP: string; anotherP1: number; }' is not assignable to type '{ prop: number; anotherP1: number; }'.
9183
!!! error TS2322: Types of property 'prop' are incompatible.
9284
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
93-
!!! error TS2322: Type 'string' is not assignable to type 'number'.
9485
prop: strOrNumber,
9586
anotherP: str,
9687
anotherP1: num
@@ -125,6 +116,5 @@ tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(
125116
!!! error TS2322: Types of property 'commonMethodDifferentReturnType' are incompatible.
126117
!!! error TS2322: Type '(a: string, b: number) => string | number' is not assignable to type '(a: string, b: number) => number'.
127118
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
128-
!!! error TS2322: Type 'string' is not assignable to type 'number'.
129119
commonMethodDifferentReturnType: (a, b) => strOrNumber,
130120
};

tests/baselines/reference/controlFlowIterationErrors.errors.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(11,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'.
22
Type 'number' is not assignable to type 'string'.
33
tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(22,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'.
4-
Type 'number' is not assignable to type 'string'.
54
tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(34,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
65
Type 'string' is not assignable to type 'number'.
76
tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(45,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
8-
Type 'string' is not assignable to type 'number'.
97

108

119
==== tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts (4 errors) ====
@@ -36,7 +34,6 @@ tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(45,17): error
3634
x = len(x);
3735
~
3836
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'.
39-
!!! error TS2345: Type 'number' is not assignable to type 'string'.
4037
}
4138
x;
4239
}
@@ -65,7 +62,6 @@ tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(45,17): error
6562
x = foo(x);
6663
~
6764
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
68-
!!! error TS2345: Type 'string' is not assignable to type 'number'.
6965
}
7066
x;
7167
}

tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(64,33): error
2121
Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'.
2222
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(66,24): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'.
2323
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(67,24): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'.
24-
Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'.
2524
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(72,5): error TS2536: Type 'keyof (T & U)' cannot be used to index type 'T | U'.
2625
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(76,5): error TS2322: Type 'T | U' is not assignable to type 'T & U'.
2726
Type 'T' is not assignable to type 'T & U'.
@@ -142,7 +141,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(77,5): error
142141
setProperty(shape, cond ? "name" : "size", 10); // Error
143142
~~~~~~~~~~~~~~~~~~~~~~
144143
!!! error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'.
145-
!!! error TS2345: Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'.
146144
}
147145

148146
function f20<T, U>(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) {

tests/baselines/reference/nonPrimitiveStrictNull.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(11,1): erro
99
Type 'undefined' is not assignable to type 'object'.
1010
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(17,7): error TS2339: Property 'toString' does not exist on type 'never'.
1111
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(21,5): error TS2322: Type 'object | null' is not assignable to type 'object'.
12-
Type 'null' is not assignable to type 'object'.
1312
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(26,5): error TS2531: Object is possibly 'null'.
1413
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(28,5): error TS2532: Object is possibly 'undefined'.
1514
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(32,5): error TS2533: Object is possibly 'null' or 'undefined'.
@@ -63,7 +62,6 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(53,14): err
6362
a = b; // error, b is not narrowed
6463
~
6564
!!! error TS2322: Type 'object | null' is not assignable to type 'object'.
66-
!!! error TS2322: Type 'null' is not assignable to type 'object'.
6765
}
6866

6967
if (typeof d === 'object') {

0 commit comments

Comments
 (0)