Skip to content

Commit 922aff8

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[test] Check we can scale to large numbers of classes, interfaces, fields, type parameters, etc.
Bug: #61310 Change-Id: Idf8557f996d1274a0120458b32604fbd356bd7a6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271220 Reviewed-by: Alexander Markov <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent a9a9c37 commit 922aff8

30 files changed

+872
-7
lines changed

runtime/tests/vm/dart/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Tests generated by `gclient runhooks`.
2+
*_test.dart
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
const n = 64;
7+
// TODO(https://github.com/dart-lang/sdk/issues/61310): n = 256
8+
9+
print("class C {");
10+
print(" String field;");
11+
print(" C(this.field);");
12+
13+
print(" createClosure() {");
14+
print(" return");
15+
for (var i = 0; i < n; i++) {
16+
print(" () =>");
17+
}
18+
print(" field;");
19+
print(" }");
20+
print("}");
21+
22+
print("""
23+
main() {
24+
const n = $n;
25+
dynamic c = C("42").createClosure();
26+
for (var i = 0; i < n; i++) {
27+
if (c is! Function) throw "Wrong!";
28+
c = c.call();
29+
}
30+
if (c != "42") throw "Wrong!";
31+
}
32+
""");
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
const n = 1 << 8;
7+
// TODO(https://github.com/dart-lang/sdk/issues/61310): n = 1 << 16
8+
9+
print("var list =");
10+
for (var i = 0; i < n; i++) {
11+
print("[");
12+
}
13+
print("null");
14+
for (var i = 0; i < n; i++) {
15+
print("]");
16+
}
17+
print(";");
18+
19+
print("""
20+
main() {
21+
const n = $n;
22+
dynamic l = list;
23+
for (var i = 0; i < n; i++) {
24+
if (l is! List) throw "wrong";
25+
l = l[0];
26+
}
27+
if (l != null) throw "wrong";
28+
}
29+
""");
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
const n = 512;
7+
8+
print("@pragma('vm:never-inline')");
9+
print("@pragma('vm:entry-point') // Stop TFA");
10+
print("@pragma('dart2js:noInline')");
11+
print("dynamic check(List<int> x, int y) {");
12+
print(" return x[0] == y");
13+
for (var i = 1; i < n; i++) {
14+
print(" && x[$i] == y");
15+
}
16+
print(" ;");
17+
print("}");
18+
19+
print("""
20+
main() {
21+
var x = new List<int>.filled($n, 42);
22+
if (!check(x, 42)) throw "Wrong!";
23+
}
24+
""");
25+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
const n = 1 << 8;
7+
// TODO(https://github.com/dart-lang/sdk/issues/61310): n = 1 << 16
8+
9+
print("var map =");
10+
for (var i = 0; i < n; i++) {
11+
print("{0:");
12+
}
13+
print("null");
14+
for (var i = 0; i < n; i++) {
15+
print("}");
16+
}
17+
print(";");
18+
19+
print("""
20+
main() {
21+
const n = $n;
22+
dynamic m = map;
23+
for (var i = 0; i < n; i++) {
24+
if (m is! Map) throw "wrong";
25+
m = m[0];
26+
}
27+
if (m != null) throw "wrong";
28+
}
29+
""");
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
const n = 1 << 8;
7+
// TODO(https://github.com/dart-lang/sdk/issues/61310): n = 1 << 16
8+
9+
print("var set =");
10+
for (var i = 0; i < n; i++) {
11+
print("{");
12+
}
13+
print("null");
14+
for (var i = 0; i < n; i++) {
15+
print("}");
16+
}
17+
print(";");
18+
19+
print("""
20+
main() {
21+
const n = $n;
22+
dynamic s = set;
23+
for (var i = 0; i < n; i++) {
24+
if (s is! Set) throw "wrong";
25+
s = s.single;
26+
}
27+
if (s != null) throw "wrong";
28+
}
29+
""");
30+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
const n = 1 << 8;
7+
// TODO(https://github.com/dart-lang/sdk/issues/61310): n = 1 << 16
8+
9+
print("class C<T> {}");
10+
11+
for (var i = 0; i < n; i++) {
12+
print("C<");
13+
}
14+
print("int");
15+
for (var i = 0; i < n; i++) {
16+
print(">");
17+
}
18+
print(" c = new");
19+
for (var i = 0; i < n; i++) {
20+
print("C<");
21+
}
22+
print("int");
23+
for (var i = 0; i < n; i++) {
24+
print(">");
25+
}
26+
print("();");
27+
28+
print("@pragma('vm:never-inline')");
29+
print("@pragma('vm:entry-point') // Stop TFA");
30+
print("@pragma('dart2js:noInline')");
31+
print("bool isCheck(dynamic c) {");
32+
print(" return c is ");
33+
for (var i = 0; i < n; i++) {
34+
print("C<");
35+
}
36+
print("int");
37+
for (var i = 0; i < n; i++) {
38+
print(">");
39+
}
40+
print(";");
41+
print("}");
42+
43+
print("@pragma('vm:never-inline')");
44+
print("@pragma('vm:entry-point') // Stop TFA");
45+
print("@pragma('dart2js:noInline')");
46+
print("void asCheck(dynamic c) {");
47+
print(" c as ");
48+
for (var i = 0; i < n; i++) {
49+
print("C<");
50+
}
51+
print("int");
52+
for (var i = 0; i < n; i++) {
53+
print(">");
54+
}
55+
print(";");
56+
print("}");
57+
58+
print("main() {");
59+
print(" if (!isCheck(c)) throw 'Wrong!';");
60+
print(" asCheck(c);");
61+
print("}");
62+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
const n = 1 << 10;
7+
8+
print(
9+
"// VMOptions=--optimization-counter-threshold=100 --no-use-osr --no-background-compilation",
10+
);
11+
12+
print("class C <");
13+
print(" T0");
14+
for (var i = 1; i < n; i++) {
15+
print(" ,T${i}");
16+
}
17+
print("> {");
18+
19+
print(" @pragma('vm:never-inline')");
20+
print(" @pragma('vm:entry-point') // Stop TFA");
21+
print(" @pragma('dart2js:noInline')");
22+
print(" static create<T>() {");
23+
print(" return new C<");
24+
for (var i = 0; i < (n - 1); i++) {
25+
print(" double,");
26+
}
27+
print(" T>();");
28+
print(" }");
29+
30+
print("""
31+
@pragma('vm:never-inline')
32+
@pragma('vm:entry-point') // Stop TFA
33+
@pragma('dart2js:noInline')
34+
dynamic checkIs(dynamic x) => x is T${n - 1};
35+
36+
@pragma('vm:never-inline')
37+
@pragma('vm:entry-point') // Stop TFA
38+
@pragma('dart2js:noInline')
39+
dynamic checkAs(dynamic x) => x as T${n - 1};
40+
41+
@pragma('vm:never-inline')
42+
@pragma('vm:entry-point') // Stop TFA
43+
@pragma('dart2js:noInline')
44+
dynamic checkInstantiate() => new G<G<T${n - 1}>>();
45+
}
46+
47+
class G<T> {}
48+
49+
main() {
50+
for (var i = 0; i < 101; i++) {
51+
var c1 = C.create<int>();
52+
if (c1.checkIs(42) != true) throw "Wrong is";
53+
if (c1.checkAs(42) != 42) throw "Wrong as";
54+
if (c1.checkInstantiate() is! G<G<int>>) throw "Wrong instantiate";
55+
56+
var c2 = C.create<double>();
57+
if (c2.checkIs(42.0) != true) throw "Wrong is";
58+
if (c2.checkAs(42.0) != 42.0) throw "Wrong as";
59+
if (c2.checkInstantiate() is! G<G<double>>) throw "Wrong instantiate";
60+
61+
var c3 = C.create<String>();
62+
if (c3.checkIs("42") != true) throw "Wrong is";
63+
if (c3.checkAs("42") != "42") throw "Wrong as";
64+
if (c3.checkInstantiate() is! G<G<String>>) throw "Wrong instantiate";
65+
}
66+
}
67+
""");
68+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
const n = 1 << 10;
7+
8+
print(
9+
"// VMOptions=--optimization-counter-threshold=100 --no-use-osr --no-background-compilation",
10+
);
11+
12+
print("class NotGeneric {");
13+
for (var i = 0; i < n; i++) {
14+
print(" dynamic field${i};");
15+
}
16+
print(" @pragma('vm:never-inline')");
17+
print(" @pragma('vm:entry-point') // Stop TFA");
18+
print(" @pragma('dart2js:noInline')");
19+
print(" NotGeneric(x) :");
20+
for (var i = 0; i < (n - 1); i++) {
21+
print(" field${i} = x,");
22+
}
23+
print(" field${n - 1} = x {}");
24+
25+
print(" @pragma('vm:never-inline')");
26+
print(" @pragma('vm:entry-point') // Stop TFA");
27+
print(" @pragma('dart2js:noInline')");
28+
print(" dynamic checkFields(dynamic x) {");
29+
for (var i = 0; i < n; i++) {
30+
print(" if (field${i} != x) return false;");
31+
}
32+
print(" return true;");
33+
print(" }");
34+
print("}");
35+
36+
print("""
37+
class C<T> extends NotGeneric {
38+
C(x) : super(x);
39+
40+
@pragma('vm:never-inline')
41+
@pragma('vm:entry-point') // Stop TFA
42+
@pragma('dart2js:noInline')
43+
dynamic checkIs(dynamic x) => x is T;
44+
45+
@pragma('vm:never-inline')
46+
@pragma('vm:entry-point') // Stop TFA
47+
@pragma('dart2js:noInline')
48+
dynamic checkAs(dynamic x) => x as T;
49+
50+
@pragma('vm:never-inline')
51+
@pragma('vm:entry-point') // Stop TFA
52+
@pragma('dart2js:noInline')
53+
dynamic checkInstantiate() => new G<G<T>>();
54+
}
55+
56+
class G<T> {}
57+
58+
main() {
59+
for (var i = 0; i < 101; i++) {
60+
var c1 = new C<int>(10);
61+
if (c1.checkIs(42) != true) throw "Wrong is";
62+
if (c1.checkAs(42) != 42) throw "Wrong as";
63+
if (c1.checkInstantiate() is! G<G<int>>) throw "Wrong instanitate";
64+
if (!c1.checkFields(10)) throw "Wrong fields";
65+
66+
var c2 = new C<double>(10);
67+
if (c2.checkIs(42.0) != true) throw "Wrong is";
68+
if (c2.checkAs(42.0) != 42.0) throw "Wrong as";
69+
if (c2.checkInstantiate() is! G<G<double>>) throw "Wrong instanitate";
70+
if (!c2.checkFields(10)) throw "Wrong fields";
71+
72+
var c3 = new C<String>(10);
73+
if (c3.checkIs("42") != true) throw "Wrong is";
74+
if (c3.checkAs("42") != "42") throw "Wrong as";
75+
if (c3.checkInstantiate() is! G<G<String>>) throw "Wrong instanitate";
76+
if (!c3.checkFields(10)) throw "Wrong fields";
77+
}
78+
}
79+
""");
80+
}

0 commit comments

Comments
 (0)