From dc33261641ad775109fff90d835fcbb3e43ec509 Mon Sep 17 00:00:00 2001 From: Zach Anderson Date: Wed, 5 Apr 2023 23:13:36 +0000 Subject: [PATCH] Revert "[dart2wasm] Fix runtime type tests" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a289c4d84870d9d403307535d281f2f8fc79c2f5. Reason for revert: https://github.com/flutter/flutter/issues/124282 Original change's description: > [dart2wasm] Fix runtime type tests > > emitTypeTest optimizes a test like `x is List` where `x : > Iterable`, i.e. tested-against type is a subtype of the operand's > static type. In these cases we can check just the class ID of the > operand without checking the type arguments. > > However this optimization cannot be done when the types don't have same > number of type arguments. Example: > > class H1 {} > > bool test(Object o) { > return o is H1; > } > > void main() { > print(test(H1())); > } > > Here `H1 <: Object`, but we still need to check the type parameter. > > This CL checks that the types have the same number of type arguments > before optimizing the test. > > Fixes #51187. > > This fix reveals another bug in `static_interop_test`, which is tracked > in #51200. The test is updated to work around the bug for now. > > New passing tests: > > - co19/LanguageFeatures/Patterns/matching_cast_A01_t01 > - co19/LanguageFeatures/Patterns/matching_list_A01_t01 > - co19/LanguageFeatures/Patterns/matching_list_A01_t02 > - co19/LanguageFeatures/Patterns/matching_object_A01_t01 > - co19/LanguageFeatures/Patterns/matching_object_A01_t02 > - co19/LanguageFeatures/Patterns/record_A01_t03 > - co19/LanguageFeatures/Patterns/record_A01_t06 > - co19/LanguageFeatures/Patterns/record_A01_t07 > - co19/LanguageFeatures/Patterns/record_A01_t08 > - co19/LanguageFeatures/Patterns/record_A01_t09 > - language/generic/deep_test > - language/generic_methods/type_expression_test > - language/patterns/object_pattern_inference_test > > Change-Id: Ibd9615666b7f7538c2a3f03fb7f5ebe9b16c3d54 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292881 > Reviewed-by: Joshua Litt > Commit-Queue: Ömer Ağacan Change-Id: Ieb222c086864744d33b77de69882e805981f1953 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293891 Commit-Queue: Zach Anderson Bot-Commit: Rubber Stamper Reviewed-by: Joshua Litt --- pkg/dart2wasm/lib/types.dart | 15 ++++----------- tests/web/wasm/static_interop_test.dart | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/pkg/dart2wasm/lib/types.dart b/pkg/dart2wasm/lib/types.dart index 44daee549b0..9a9f3df4349 100644 --- a/pkg/dart2wasm/lib/types.dart +++ b/pkg/dart2wasm/lib/types.dart @@ -611,23 +611,16 @@ class Types { } if (type.typeArguments.any((t) => t is! DynamicType)) { - // Type has at least one type argument that is not `dynamic`. - // - // In cases like `x is List` where `x : Iterable` (tested-against - // type is a subtype of the operand's static type and the types have same - // number of type arguments), it is not necessary to test the type - // arguments. + // If the tested-against type as an instance of the static operand type + // has the same type arguments as the static operand type, it is not + // necessary to test the type arguments. Class cls = translator.classForType(operandType); InterfaceType? base = translator.hierarchy .getTypeAsInstanceOf(type, cls, isNonNullableByDefault: codeGen.member.enclosingLibrary.isNonNullableByDefault) ?.withDeclaredNullability(operandType.declaredNullability); - - final sameNumTypeParams = operandType is InterfaceType && - operandType.typeArguments.length == type.typeArguments.length; - - if (!(sameNumTypeParams && base == operandType)) { + if (base != operandType) { makeType(codeGen, type); codeGen.call(translator.isSubtype.reference); _endPotentiallyNullableBlock(); diff --git a/tests/web/wasm/static_interop_test.dart b/tests/web/wasm/static_interop_test.dart index 3c66bd9d27e..25b7e7c54d8 100644 --- a/tests/web/wasm/static_interop_test.dart +++ b/tests/web/wasm/static_interop_test.dart @@ -311,7 +311,7 @@ extension AnonymousJSClassExtension on AnonymousJSClass { external String? get bleep; external int? get goo; external int? get ooo; - external List? saz; + external List? saz; external List? zoo; }