Skip to content

Commit cc83c79

Browse files
authored
Merge pull request #9578 from Microsoft/fix-salsa-out-of-memory-on-methods-returning-this
Provide a symbol for salsa-inferred class types
2 parents 135cc12 + 3c1a69b commit cc83c79

7 files changed

+303
-10
lines changed

Diff for: src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11673,7 +11673,7 @@ namespace ts {
1167311673
function getInferredClassType(symbol: Symbol) {
1167411674
const links = getSymbolLinks(symbol);
1167511675
if (!links.inferredClassType) {
11676-
links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined);
11676+
links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined);
1167711677
}
1167811678
return links.inferredClassType;
1167911679
}

Diff for: tests/baselines/reference/methodsReturningThis.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [input.js]
2+
function Class()
3+
{
4+
}
5+
6+
// error: 'Class' doesn't have property 'notPresent'
7+
Class.prototype.containsError = function () { return this.notPresent; };
8+
9+
// lots of methods that return this, which caused out-of-memory in #9527
10+
Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; };
11+
Class.prototype.m2 = function (x, y) { return this; };
12+
Class.prototype.m3 = function (x, y) { return this; };
13+
Class.prototype.m4 = function (angle) { return this; };
14+
Class.prototype.m5 = function (matrix) { return this; };
15+
Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; };
16+
Class.prototype.m7 = function(matrix) { return this; };
17+
Class.prototype.m8 = function() { return this; };
18+
Class.prototype.m9 = function () { return this; };
19+
20+
21+
22+
//// [output.js]
23+
function Class() {
24+
}
25+
// error: 'Class' doesn't have property 'notPresent'
26+
Class.prototype.containsError = function () { return this.notPresent; };
27+
// lots of methods that return this, which caused out-of-memory in #9527
28+
Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; };
29+
Class.prototype.m2 = function (x, y) { return this; };
30+
Class.prototype.m3 = function (x, y) { return this; };
31+
Class.prototype.m4 = function (angle) { return this; };
32+
Class.prototype.m5 = function (matrix) { return this; };
33+
Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; };
34+
Class.prototype.m7 = function (matrix) { return this; };
35+
Class.prototype.m8 = function () { return this; };
36+
Class.prototype.m9 = function () { return this; };
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
=== tests/cases/conformance/salsa/input.js ===
2+
function Class()
3+
>Class : Symbol(Class, Decl(input.js, 0, 0))
4+
{
5+
}
6+
7+
// error: 'Class' doesn't have property 'notPresent'
8+
Class.prototype.containsError = function () { return this.notPresent; };
9+
>Class.prototype : Symbol(Class.containsError, Decl(input.js, 2, 1))
10+
>Class : Symbol(Class, Decl(input.js, 0, 0))
11+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
12+
>containsError : Symbol(Class.containsError, Decl(input.js, 2, 1))
13+
>this : Symbol(Class, Decl(input.js, 0, 0))
14+
15+
// lots of methods that return this, which caused out-of-memory in #9527
16+
Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; };
17+
>Class.prototype : Symbol(Class.m1, Decl(input.js, 5, 72))
18+
>Class : Symbol(Class, Decl(input.js, 0, 0))
19+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
20+
>m1 : Symbol(Class.m1, Decl(input.js, 5, 72))
21+
>a : Symbol(a, Decl(input.js, 8, 31))
22+
>b : Symbol(b, Decl(input.js, 8, 33))
23+
>c : Symbol(c, Decl(input.js, 8, 36))
24+
>d : Symbol(d, Decl(input.js, 8, 39))
25+
>tx : Symbol(tx, Decl(input.js, 8, 42))
26+
>ty : Symbol(ty, Decl(input.js, 8, 46))
27+
>this : Symbol(Class, Decl(input.js, 0, 0))
28+
29+
Class.prototype.m2 = function (x, y) { return this; };
30+
>Class.prototype : Symbol(Class.m2, Decl(input.js, 8, 68))
31+
>Class : Symbol(Class, Decl(input.js, 0, 0))
32+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
33+
>m2 : Symbol(Class.m2, Decl(input.js, 8, 68))
34+
>x : Symbol(x, Decl(input.js, 9, 31))
35+
>y : Symbol(y, Decl(input.js, 9, 33))
36+
>this : Symbol(Class, Decl(input.js, 0, 0))
37+
38+
Class.prototype.m3 = function (x, y) { return this; };
39+
>Class.prototype : Symbol(Class.m3, Decl(input.js, 9, 54))
40+
>Class : Symbol(Class, Decl(input.js, 0, 0))
41+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
42+
>m3 : Symbol(Class.m3, Decl(input.js, 9, 54))
43+
>x : Symbol(x, Decl(input.js, 10, 31))
44+
>y : Symbol(y, Decl(input.js, 10, 33))
45+
>this : Symbol(Class, Decl(input.js, 0, 0))
46+
47+
Class.prototype.m4 = function (angle) { return this; };
48+
>Class.prototype : Symbol(Class.m4, Decl(input.js, 10, 54))
49+
>Class : Symbol(Class, Decl(input.js, 0, 0))
50+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
51+
>m4 : Symbol(Class.m4, Decl(input.js, 10, 54))
52+
>angle : Symbol(angle, Decl(input.js, 11, 31))
53+
>this : Symbol(Class, Decl(input.js, 0, 0))
54+
55+
Class.prototype.m5 = function (matrix) { return this; };
56+
>Class.prototype : Symbol(Class.m5, Decl(input.js, 11, 55))
57+
>Class : Symbol(Class, Decl(input.js, 0, 0))
58+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
59+
>m5 : Symbol(Class.m5, Decl(input.js, 11, 55))
60+
>matrix : Symbol(matrix, Decl(input.js, 12, 31))
61+
>this : Symbol(Class, Decl(input.js, 0, 0))
62+
63+
Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; };
64+
>Class.prototype : Symbol(Class.m6, Decl(input.js, 12, 56))
65+
>Class : Symbol(Class, Decl(input.js, 0, 0))
66+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
67+
>m6 : Symbol(Class.m6, Decl(input.js, 12, 56))
68+
>x : Symbol(x, Decl(input.js, 13, 31))
69+
>y : Symbol(y, Decl(input.js, 13, 33))
70+
>pivotX : Symbol(pivotX, Decl(input.js, 13, 36))
71+
>pivotY : Symbol(pivotY, Decl(input.js, 13, 44))
72+
>scaleX : Symbol(scaleX, Decl(input.js, 13, 52))
73+
>scaleY : Symbol(scaleY, Decl(input.js, 13, 60))
74+
>rotation : Symbol(rotation, Decl(input.js, 13, 68))
75+
>skewX : Symbol(skewX, Decl(input.js, 13, 78))
76+
>skewY : Symbol(skewY, Decl(input.js, 13, 85))
77+
>this : Symbol(Class, Decl(input.js, 0, 0))
78+
79+
Class.prototype.m7 = function(matrix) { return this; };
80+
>Class.prototype : Symbol(Class.m7, Decl(input.js, 13, 110))
81+
>Class : Symbol(Class, Decl(input.js, 0, 0))
82+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
83+
>m7 : Symbol(Class.m7, Decl(input.js, 13, 110))
84+
>matrix : Symbol(matrix, Decl(input.js, 14, 30))
85+
>this : Symbol(Class, Decl(input.js, 0, 0))
86+
87+
Class.prototype.m8 = function() { return this; };
88+
>Class.prototype : Symbol(Class.m8, Decl(input.js, 14, 55))
89+
>Class : Symbol(Class, Decl(input.js, 0, 0))
90+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
91+
>m8 : Symbol(Class.m8, Decl(input.js, 14, 55))
92+
>this : Symbol(Class, Decl(input.js, 0, 0))
93+
94+
Class.prototype.m9 = function () { return this; };
95+
>Class.prototype : Symbol(Class.m9, Decl(input.js, 15, 49))
96+
>Class : Symbol(Class, Decl(input.js, 0, 0))
97+
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
98+
>m9 : Symbol(Class.m9, Decl(input.js, 15, 49))
99+
>this : Symbol(Class, Decl(input.js, 0, 0))
100+
101+

0 commit comments

Comments
 (0)