Skip to content

Commit ef75007

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2js] Fix as-check type registration.
We would expect failing as checks to throw in all modes (unless --omit-as-casts is provided). However, the new test program fails in production mode. This is because we are not registering the type usage of the function's type parameter. This leads us to drop the as check completely later on. We should be doing subtype checks with nullability if we want to consider an as test omitted. Golem patch results: https://golem.corp.goog/Comparison?repository=dart#targetA%3Ddart2js%3BmachineTypeA%3Dlinux-x64%3BrevisionA%3D107840%3BpatchA%3Dnatebiggs--dart2js--Fix-as-check-type-registration.-7%3BtargetB%3Ddart2js%3BmachineTypeB%3Dlinux-x64%3BrevisionB%3D107839%3BpatchB%3DNone Fixed: #54419 Change-Id: If93f78a939a690f05f5398c1a5ca971df1fc9243 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343821 Reviewed-by: Mayank Patke <[email protected]> Reviewed-by: Stephen Adams <[email protected]> Commit-Queue: Nate Biggs <[email protected]>
1 parent 49aef32 commit ef75007

18 files changed

+53
-35
lines changed

pkg/compiler/lib/src/ir/impact_data.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ class ImpactBuilder extends StaticTypeVisitor implements ImpactRegistry {
222222
void handleAsExpression(ir.AsExpression node, ir.DartType operandType,
223223
{bool? isCalculatedTypeSubtype}) {
224224
if (isCalculatedTypeSubtype ??
225-
typeEnvironment.isSubtypeOf(operandType, node.type,
226-
ir.SubtypeCheckMode.ignoringNullabilities)) {
225+
typeEnvironment.isSubtypeOf(
226+
operandType, node.type, ir.SubtypeCheckMode.withNullabilities)) {
227227
// Skip unneeded casts.
228228
return;
229229
}

pkg/compiler/lib/src/ir/static_type.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
13201320
// Check if the calculated operandType is a subtype of the type specified
13211321
// in the `as` expression.
13221322
final isCalculatedTypeSubtype = typeEnvironment.isSubtypeOf(
1323-
operandType, node.type, ir.SubtypeCheckMode.ignoringNullabilities);
1323+
operandType, node.type, ir.SubtypeCheckMode.withNullabilities);
13241324
if (!isCalculatedTypeSubtype &&
13251325
operand is ir.VariableGet &&
13261326
!_invalidatedVariables.contains(operand.variable)) {

pkg/compiler/test/closure/data/generic.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ class Class1<T> {
5656
}
5757

5858
var local2 =
59-
/*prod.hasThis*/
60-
/*spec.fields=[S,this],free=[S,this],hasThis*/
59+
/*fields=[S,this],free=[S,this],hasThis*/
6160
(o) {
6261
return
63-
/*prod.hasThis*/
64-
/*spec.fields=[S,this],free=[S,this],hasThis*/
62+
/*fields=[S,this],free=[S,this],hasThis*/
6563
() => Map<T, S>();
6664
};
6765
return local2(local<double>());

pkg/compiler/test/closure/data/list_literal_untested_class.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class A<T> {
99
/*member: A.method:hasThis*/
1010
@pragma('dart2js:noInline')
1111
method() {
12-
/*spec.fields=[this],free=[this],hasThis*/
13-
/*prod.hasThis*/
12+
/*fields=[this],free=[this],hasThis*/
1413
dynamic local() => <T>[];
1514
return local;
1615
}

pkg/compiler/test/closure/data/list_literal_untested_method.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:expect/expect.dart';
66

77
@pragma('dart2js:noInline')
88
method<T>() {
9-
/*spec.fields=[T],free=[T]*/
9+
/*fields=[T],free=[T]*/
1010
dynamic local() => <T>[];
1111
return local;
1212
}

pkg/compiler/test/closure/data/map_literal_untested_class.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class A<T> {
99
/*member: A.method:hasThis*/
1010
@pragma('dart2js:noInline')
1111
method() {
12-
/*spec.fields=[this],free=[this],hasThis*/
13-
/*prod.hasThis*/
12+
/*fields=[this],free=[this],hasThis*/
1413
dynamic local() => <T, int>{};
1514
return local;
1615
}

pkg/compiler/test/closure/data/map_literal_untested_method.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:expect/expect.dart';
66

77
@pragma('dart2js:noInline')
88
method<T>() {
9-
/*spec.fields=[T],free=[T]*/
9+
/*fields=[T],free=[T]*/
1010
dynamic local() => <T, int>{};
1111
return local;
1212
}

pkg/compiler/test/codegen/data/array_add.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
return t1;
1313
}*/
1414
/*prod.member: test1:function() {
15-
var t1 = [];
15+
var t1 = A._setArrayType([], type$.JSArray_int);
1616
t1.push(1);
1717
return t1;
1818
}*/

pkg/compiler/test/codegen/literal_list_test.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ foo() {
1818
main() {
1919
runTest() async {
2020
await compile(TEST_ONE, entry: 'foo', check: (String generated) {
21-
Expect.isTrue(generated.contains('print([1, 2]);'),
22-
"Code pattern 'print([1, 2]);' not found in\n$generated");
23-
Expect.isTrue(generated.contains('print([3]);'),
24-
"Code pattern 'print([3]);' not found in\n$generated");
25-
Expect.isTrue(generated.contains('print([4, 5]);'),
26-
"Code pattern 'print([4, 5]);' not found in\n$generated");
21+
Expect.isTrue(
22+
generated.contains('A.print(A._setArrayType([1, 2], t1));'),
23+
"Code pattern 'A.print(A._setArrayType([1, 2], t1));' "
24+
"not found in\n$generated");
25+
Expect.isTrue(
26+
generated.contains('A.print(A._setArrayType([3], t1));'),
27+
"Code pattern 'A.print(A._setArrayType([3], t1));' "
28+
"not found in\n$generated");
29+
Expect.isTrue(
30+
generated.contains('A.print(A._setArrayType([4, 5], t1));'),
31+
"Code pattern 'A.print(A._setArrayType([4, 5], t1));' "
32+
"not found in\n$generated");
2733
});
2834
}
2935

pkg/compiler/test/rti/data/async_foreach.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import 'package:compiler/src/util/testing.dart';
88

99
/*spec.class: Class:explicit=[Class.T*],implicit=[Class.T],needsArgs,test*/
10-
/*prod.class: Class:needsArgs*/
10+
/*prod.class: Class:implicit=[Class.T],needsArgs,test*/
1111
class Class<T> {
1212
method() {
1313
var list = <T>[];

0 commit comments

Comments
 (0)