Skip to content

Commit 1076606

Browse files
fishythefishCommit Queue
authored andcommitted
[dart2js] Remove all uses of useLegacySubtyping.
Bug: #60327 Fixes: #41960 Change-Id: Idc766a1cccd008aa7262c79effe25daa240850bf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416180 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Mayank Patke <[email protected]>
1 parent 77cd774 commit 1076606

22 files changed

+68
-184
lines changed

pkg/compiler/lib/src/elements/types.dart

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,18 +1885,16 @@ abstract class DartTypes {
18851885
/// The types defined in 'dart:core'.
18861886
CommonElements get commonElements;
18871887

1888-
bool get useLegacySubtyping;
1889-
18901888
DartType nullableType(DartType baseType) {
18911889
bool isNullable(DartType t) =>
18921890
// Note that we can assume null safety is enabled here.
18931891
t.isNull ||
18941892
t is NullableType ||
18951893
t is FutureOrType && isNullable(t.typeArgument) ||
1896-
isStrongTopType(t);
1894+
isTopType(t);
18971895

18981896
DartType result;
1899-
if (isStrongTopType(baseType) ||
1897+
if (isTopType(baseType) ||
19001898
baseType.isNull ||
19011899
baseType is NullableType ||
19021900
baseType is FutureOrType && isNullable(baseType.typeArgument)) {
@@ -2048,14 +2046,10 @@ abstract class DartTypes {
20482046
}
20492047

20502048
/// Returns `true` if [t] is a bottom type, that is, a subtype of every type.
2051-
bool isBottomType(DartType t) =>
2052-
t is NeverType || (useLegacySubtyping && t.isNull);
2049+
bool isBottomType(DartType t) => t is NeverType;
20532050

20542051
/// Returns `true` if [t] is a top type, that is, a supertype of every type.
20552052
bool isTopType(DartType t) =>
2056-
isStrongTopType(t) || useLegacySubtyping && t.isObject;
2057-
2058-
bool isStrongTopType(DartType t) =>
20592053
t is VoidType ||
20602054
t is DynamicType ||
20612055
t is ErasedType ||
@@ -2111,7 +2105,7 @@ abstract class DartTypes {
21112105
if (isTopType(t)) return true;
21122106

21132107
// Left Top:
2114-
if (isStrongTopType(s)) return false;
2108+
if (isTopType(s)) return false;
21152109

21162110
// Left Bottom:
21172111
if (isBottomType(s)) return true;
@@ -2127,15 +2121,15 @@ abstract class DartTypes {
21272121
// Left Null:
21282122
// Note: Interchanging the Left Null and Right Object rules allows us to
21292123
// reduce casework.
2130-
if (!useLegacySubtyping && s.isNull) {
2124+
if (s.isNull) {
21312125
if (t is FutureOrType) {
21322126
return isSubtype(s, t.typeArgument, env);
21332127
}
21342128
return t.isNull || t is NullableType;
21352129
}
21362130

21372131
// Right Object:
2138-
if (!useLegacySubtyping && t.isObject) {
2132+
if (t.isObject) {
21392133
if (s is FutureOrType) {
21402134
return isSubtype(s.typeArgument, t, env);
21412135
}
@@ -2151,8 +2145,7 @@ abstract class DartTypes {
21512145

21522146
// Left Nullable:
21532147
if (s is NullableType) {
2154-
return (useLegacySubtyping ||
2155-
isSubtype(commonElements.nullType, t, env)) &&
2148+
return (isSubtype(commonElements.nullType, t, env)) &&
21562149
isSubtype(s.baseType, t, env);
21572150
}
21582151

@@ -2172,8 +2165,7 @@ abstract class DartTypes {
21722165

21732166
// Right Nullable:
21742167
if (t is NullableType) {
2175-
return (!useLegacySubtyping &&
2176-
isSubtype(s, commonElements.nullType, env)) ||
2168+
return (isSubtype(s, commonElements.nullType, env)) ||
21772169
isSubtype(s, t.baseType, env);
21782170
}
21792171

@@ -2280,14 +2272,12 @@ abstract class DartTypes {
22802272
String sName = sNamed[sIndex++];
22812273
int comparison = sName.compareTo(tName);
22822274
if (comparison > 0) return false;
2283-
bool sIsRequired =
2284-
!useLegacySubtyping && sRequiredNamed.contains(sName);
2275+
bool sIsRequired = sRequiredNamed.contains(sName);
22852276
if (comparison < 0) {
22862277
if (sIsRequired) return false;
22872278
continue;
22882279
}
2289-
bool tIsRequired =
2290-
!useLegacySubtyping && tRequiredNamed.contains(tName);
2280+
bool tIsRequired = tRequiredNamed.contains(tName);
22912281
if (sIsRequired && !tIsRequired) return false;
22922282
if (!isSubtype(
22932283
tNamedTypes[tIndex],
@@ -2299,10 +2289,8 @@ abstract class DartTypes {
22992289
break;
23002290
}
23012291
}
2302-
if (!useLegacySubtyping) {
2303-
while (sIndex < sNamedLength) {
2304-
if (sRequiredNamed.contains(sNamed[sIndex++])) return false;
2305-
}
2292+
while (sIndex < sNamedLength) {
2293+
if (sRequiredNamed.contains(sNamed[sIndex++])) return false;
23062294
}
23072295
return true;
23082296
} finally {

pkg/compiler/lib/src/inferrer/abstract_value_domain.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,7 @@ mixin AbstractValueDomain {
232232
/// the input's abstract type. The check can only be removed with additional
233233
/// reasoning, for example, that a dominating check uses the same type
234234
/// expression.
235-
///
236-
/// [nullable] determines if the type in weak or legacy mode should be
237-
/// interpreted as nullable. This is passed as `false` for is-tests and `true`
238-
/// for as-checks and other contexts (e.g. parameter checks).
239-
AbstractValueWithPrecision createFromStaticType(
240-
DartType type, {
241-
required bool nullable,
242-
});
235+
AbstractValueWithPrecision createFromStaticType(DartType type);
243236

244237
/// Creates an [AbstractValue] for a non-null exact instance of [cls].
245238
AbstractValue createNonNullExact(ClassEntity cls);

pkg/compiler/lib/src/inferrer/builder.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault<TypeInformation?>
10231023
if (mask != null) return mask;
10241024
// TODO(sigmund): ensure that this is only called once per node.
10251025
DartType staticType = _getStaticType(receiver);
1026-
bool includeNull =
1027-
_dartTypes.useLegacySubtyping || staticType is NullableType;
1026+
bool includeNull = staticType is NullableType;
10281027
staticType = staticType.withoutNullability;
10291028
if (staticType is InterfaceType) {
10301029
ClassEntity cls = staticType.element;

pkg/compiler/lib/src/inferrer/computable.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,8 @@ class ComputableAbstractValueDomain with AbstractValueDomain {
175175
ComputableAbstractValue(_wrappedDomain.asyncStarStreamType);
176176

177177
@override
178-
AbstractValueWithPrecision createFromStaticType(
179-
DartType type, {
180-
required bool nullable,
181-
}) {
182-
final unwrapped = _wrappedDomain.createFromStaticType(
183-
type,
184-
nullable: nullable,
185-
);
178+
AbstractValueWithPrecision createFromStaticType(DartType type) {
179+
final unwrapped = _wrappedDomain.createFromStaticType(type);
186180
return AbstractValueWithPrecision(
187181
ComputableAbstractValue(unwrapped.abstractValue),
188182
unwrapped.isPrecise,

pkg/compiler/lib/src/inferrer/powersets/powerset_bits.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class PowersetBitsDomain {
213213
// ConstantValue
214214
// TODO(fishythefish): Naively calling `getType` on
215215
// [LateSentinelConstantValue] will produce Never.
216-
return createFromStaticType(value.getType(commonElements), nullable: false);
216+
return createFromStaticType(value.getType(commonElements));
217217
}
218218

219219
AbstractBool areDisjoint(int a, int b) {
@@ -455,7 +455,7 @@ class PowersetBitsDomain {
455455
return classInfo.exactBits;
456456
}
457457

458-
int createFromStaticType(DartType type, {required bool nullable}) {
458+
int createFromStaticType(DartType type) {
459459
if (dartTypes.isTopType(type)) {
460460
// A cone of a top type includes all values. This would be 'precise' if we
461461
// tracked that.
@@ -466,13 +466,7 @@ class PowersetBitsDomain {
466466
return _createFromStaticType(type.baseType, true);
467467
}
468468

469-
if (dartTypes.useLegacySubtyping) {
470-
// In legacy and weak mode, `String` is nullable depending on context.
471-
return _createFromStaticType(type, nullable);
472-
} else {
473-
// In strong mode nullability comes from explicit NullableType.
474-
return _createFromStaticType(type, false);
475-
}
469+
return _createFromStaticType(type, false);
476470
}
477471

478472
int _createFromStaticType(DartType type, bool nullable) {

pkg/compiler/lib/src/inferrer/powersets/powersets.dart

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -824,18 +824,9 @@ class PowersetDomain with AbstractValueDomain {
824824
}
825825

826826
@override
827-
AbstractValueWithPrecision createFromStaticType(
828-
DartType type, {
829-
required bool nullable,
830-
}) {
831-
int powersetBits = _powersetBitsDomain.createFromStaticType(
832-
type,
833-
nullable: nullable,
834-
);
835-
var unwrapped = _abstractValueDomain.createFromStaticType(
836-
type,
837-
nullable: nullable,
838-
);
827+
AbstractValueWithPrecision createFromStaticType(DartType type) {
828+
int powersetBits = _powersetBitsDomain.createFromStaticType(type);
829+
var unwrapped = _abstractValueDomain.createFromStaticType(type);
839830
return AbstractValueWithPrecision(
840831
PowersetValue(unwrapped.abstractValue, powersetBits),
841832
unwrapped.isPrecise,

pkg/compiler/lib/src/inferrer/trivial.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,7 @@ class TrivialAbstractValueDomain with AbstractValueDomain {
384384
const TrivialAbstractValue();
385385

386386
@override
387-
AbstractValueWithPrecision createFromStaticType(
388-
DartType type, {
389-
required bool nullable,
390-
}) {
387+
AbstractValueWithPrecision createFromStaticType(DartType type) {
391388
return const AbstractValueWithPrecision(TrivialAbstractValue(), false);
392389
}
393390

pkg/compiler/lib/src/inferrer/type_graph_nodes.dart

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,7 @@ class FieldTypeInformation extends MemberTypeInformation {
599599
AbstractValueDomain abstractValueDomain,
600600
this._member,
601601
DartType type,
602-
) : _type =
603-
abstractValueDomain
604-
.createFromStaticType(type, nullable: true)
605-
.abstractValue,
602+
) : _type = abstractValueDomain.createFromStaticType(type).abstractValue,
606603
super._internal(abstractValueDomain, _member);
607604

608605
@override
@@ -659,7 +656,7 @@ class GetterTypeInformation extends MemberTypeInformation {
659656
FunctionType type,
660657
) : _type =
661658
abstractValueDomain
662-
.createFromStaticType(type.returnType, nullable: true)
659+
.createFromStaticType(type.returnType)
663660
.abstractValue,
664661
super._internal(abstractValueDomain, _member);
665662

@@ -709,7 +706,7 @@ class MethodTypeInformation extends MemberTypeInformation {
709706
FunctionType type,
710707
) : _type =
711708
abstractValueDomain
712-
.createFromStaticType(type.returnType, nullable: true)
709+
.createFromStaticType(type.returnType)
713710
.abstractValue,
714711
super._internal(abstractValueDomain, _member);
715712

@@ -744,7 +741,7 @@ class FactoryConstructorTypeInformation extends MemberTypeInformation {
744741
FunctionType type,
745742
) : _type =
746743
abstractValueDomain
747-
.createFromStaticType(type.returnType, nullable: true)
744+
.createFromStaticType(type.returnType)
748745
.abstractValue,
749746
super._internal(abstractValueDomain, _member);
750747

@@ -842,10 +839,7 @@ class ParameterTypeInformation extends ElementTypeInformation {
842839
this._parameter,
843840
DartType type,
844841
this._method,
845-
) : _type =
846-
abstractValueDomain
847-
.createFromStaticType(type, nullable: true)
848-
.abstractValue,
842+
) : _type = abstractValueDomain.createFromStaticType(type).abstractValue,
849843
_inputType = abstractValueDomain.uncomputedType,
850844
super._internal() {
851845
_flags = _flags.add(_Flag.isClosureParameter);
@@ -858,10 +852,7 @@ class ParameterTypeInformation extends ElementTypeInformation {
858852
DartType type,
859853
this._method, {
860854
bool isInitializingFormal = false,
861-
}) : _type =
862-
abstractValueDomain
863-
.createFromStaticType(type, nullable: true)
864-
.abstractValue,
855+
}) : _type = abstractValueDomain.createFromStaticType(type).abstractValue,
865856
_inputType = abstractValueDomain.uncomputedType,
866857
super._internal() {
867858
_flags = _flags.update(_Flag.isInitializingFormal, isInitializingFormal);
@@ -891,8 +882,7 @@ class ParameterTypeInformation extends ElementTypeInformation {
891882
DartType type,
892883
FunctionEntity method,
893884
) {
894-
final staticType =
895-
domain.createFromStaticType(type, nullable: true).abstractValue;
885+
final staticType = domain.createFromStaticType(type).abstractValue;
896886
// We include null in the type of `==` because it usually does not already
897887
// include null. When we narrow the inferred type using this static type
898888
// we want to allow for null so that downstream we can know if null flows
@@ -2576,7 +2566,7 @@ class AwaitTypeInformation extends TypeInformation {
25762566
),
25772567
);
25782568
return inferrer.abstractValueDomain
2579-
.createFromStaticType(staticType, nullable: true)
2569+
.createFromStaticType(staticType)
25802570
.abstractValue;
25812571
}
25822572

pkg/compiler/lib/src/inferrer/type_system.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ class TypeSystem {
341341
}
342342

343343
AbstractValue narrowing =
344-
_abstractValueDomain
345-
.createFromStaticType(annotation, nullable: isCast)
346-
.abstractValue;
344+
_abstractValueDomain.createFromStaticType(annotation).abstractValue;
347345

348346
if (excludeNull) {
349347
narrowing = _abstractValueDomain.excludeNull(narrowing);
@@ -616,17 +614,13 @@ class TypeSystem {
616614
_abstractValueDomain,
617615
currentMember,
618616
simplifiedKeyType,
619-
_abstractValueDomain
620-
.createFromStaticType(keyStaticType, nullable: false)
621-
.abstractValue,
617+
_abstractValueDomain.createFromStaticType(keyStaticType).abstractValue,
622618
);
623619
final valueTypeInfo = ValueInMapTypeInformation(
624620
_abstractValueDomain,
625621
currentMember,
626622
simplifiedValueType,
627-
_abstractValueDomain
628-
.createFromStaticType(valueStaticType, nullable: false)
629-
.abstractValue,
623+
_abstractValueDomain.createFromStaticType(valueStaticType).abstractValue,
630624
);
631625
allocatedTypes.add(keyTypeInfo);
632626
allocatedTypes.add(valueTypeInfo);

pkg/compiler/lib/src/inferrer/typemasks/masks.dart

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,7 @@ class CommonMasks with AbstractValueDomain {
320320
}
321321

322322
@override
323-
AbstractValueWithPrecision createFromStaticType(
324-
DartType type, {
325-
required bool nullable,
326-
}) {
323+
AbstractValueWithPrecision createFromStaticType(DartType type) {
327324
if (dartTypes.isTopType(type)) {
328325
// A cone of a top type includes all values.
329326
return AbstractValueWithPrecision(dynamicType, true);
@@ -333,13 +330,7 @@ class CommonMasks with AbstractValueDomain {
333330
return _createFromStaticType(type.baseType, true);
334331
}
335332

336-
if (dartTypes.useLegacySubtyping) {
337-
// In legacy and weak mode, `String` is nullable depending on context.
338-
return _createFromStaticType(type, nullable);
339-
} else {
340-
// In strong mode nullability comes from explicit NullableType.
341-
return _createFromStaticType(type, false);
342-
}
333+
return _createFromStaticType(type, false);
343334
}
344335

345336
AbstractValueWithPrecision _createFromStaticType(
@@ -414,7 +405,7 @@ class CommonMasks with AbstractValueDomain {
414405
final shape = type.shape;
415406
final fields = type.fields;
416407
for (final field in fields) {
417-
final fieldType = createFromStaticType(field, nullable: nullable);
408+
final fieldType = createFromStaticType(field);
418409
types.add(fieldType.abstractValue as TypeMask);
419410
isPrecise &= fieldType.isPrecise;
420411
}

0 commit comments

Comments
 (0)