Skip to content

Commit 290d740

Browse files
mkustermannCommit Queue
authored and
Commit Queue
committed
[dart2wasm] Avoid WasmArray<_Type> allocations in interface subtype checking
Issue #55516 Change-Id: I2cddd95211f3d831965a1bba45774ad8d72847a9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369621 Reviewed-by: Srujan Gaddam <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent b11c932 commit 290d740

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

sdk/lib/_internal/wasm/lib/type.dart

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,17 @@ abstract class _TypeUniverse {
703703
substituteTypeArgument(type.as<_FutureOrType>().typeArgument,
704704
substitutions, rootFunction));
705705
} else if (type.isInterface) {
706-
_InterfaceType interfaceType = type.as<_InterfaceType>();
707-
final typeArguments = WasmArray<_Type>.filled(
708-
interfaceType.typeArguments.length, _literal<dynamic>());
709-
for (int i = 0; i < typeArguments.length; i++) {
710-
typeArguments[i] = substituteTypeArgument(
711-
interfaceType.typeArguments[i], substitutions, rootFunction);
706+
final interfaceType = type.as<_InterfaceType>();
707+
final arguments = interfaceType.typeArguments;
708+
if (arguments.length == 0) return interfaceType;
709+
final newArguments =
710+
WasmArray<_Type>.filled(arguments.length, _literal<dynamic>());
711+
for (int i = 0; i < arguments.length; i++) {
712+
newArguments[i] =
713+
substituteTypeArgument(arguments[i], substitutions, rootFunction);
712714
}
713715
return _InterfaceType(interfaceType.classId,
714-
interfaceType.isDeclaredNullable, typeArguments);
716+
interfaceType.isDeclaredNullable, newArguments);
715717
} else if (type.isInterfaceTypeParameterType) {
716718
assert(rootFunction == null);
717719
return substituteInterfaceTypeParameter(
@@ -885,24 +887,15 @@ abstract class _TypeUniverse {
885887
_typeRulesSubstitutions[sId][sSuperIndexOfT];
886888
assert(substitutions.isNotEmpty);
887889

888-
// If we have empty type arguments then create a list of dynamic type
889-
// arguments.
890-
WasmArray<_Type> typeArgumentsForSubstitution =
891-
substitutions.isNotEmpty && sTypeArguments.isEmpty
892-
? WasmArray<_Type>.filled(substitutions.length, _literal<dynamic>())
893-
: sTypeArguments;
894-
895-
// Finally substitute arguments. We must do this upfront so we can normalize
896-
// the type.
897-
// TODO(joshualitt): This process is expensive so we should cache the
898-
// result.
899-
final substituted =
900-
WasmArray<_Type>.filled(substitutions.length, _literal<dynamic>());
901-
for (int i = 0; i < substitutions.length; i++) {
902-
substituted[i] = substituteTypeArgument(
903-
substitutions[i], typeArgumentsForSubstitution, null);
890+
// Check arguments.
891+
for (int i = 0; i < tTypeArguments.length; i++) {
892+
final sArgForTClass =
893+
substituteTypeArgument(substitutions[i], sTypeArguments, null);
894+
if (!isSubtype(sArgForTClass, sEnv, tTypeArguments[i], tEnv)) {
895+
return false;
896+
}
904897
}
905-
return areTypeArgumentsSubtypes(substituted, sEnv, tTypeArguments, tEnv);
898+
return true;
906899
}
907900

908901
static bool isFunctionSubtype(_FunctionType s, _Environment? sEnv,

0 commit comments

Comments
 (0)