Skip to content

Commit 38ef374

Browse files
fishythefishCommit Queue
authored andcommitted
[dart2js] Remove LegacyType.
Bug: #60327 Change-Id: Ia236d1674ba8030da3b91e88ac869e99fe5b8399 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416024 Reviewed-by: Nate Biggs <[email protected]>
1 parent 1f8ab5f commit 38ef374

25 files changed

+17
-310
lines changed

pkg/compiler/lib/src/deferred_load/entity_data_info.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,6 @@ class TypeEntityDataVisitor implements DartTypeVisitor<void, Null> {
391391
types.forEach(visit);
392392
}
393393

394-
@override
395-
void visitLegacyType(LegacyType type, Null argument) {
396-
visit(type.baseType);
397-
}
398-
399394
@override
400395
void visitNullableType(NullableType type, Null argument) {
401396
visit(type.baseType);

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

Lines changed: 8 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:js_shared/variance.dart';
66

77
import '../common/elements.dart' show CommonElements;
88
import '../common/names.dart';
9-
import '../options.dart';
109
import '../serialization/serialization.dart';
1110
import '../util/util.dart' show equalElements, equalSets, identicalElements;
1211
import '../universe/record_shape.dart';
@@ -72,8 +71,6 @@ abstract class DartType {
7271
switch (kind) {
7372
case DartTypeKind.none:
7473
return null;
75-
case DartTypeKind.legacyType:
76-
return LegacyType._readFromDataSource(source, functionTypeVariables);
7774
case DartTypeKind.nullableType:
7875
return NullableType._readFromDataSource(source, functionTypeVariables);
7976
case DartTypeKind.neverType:
@@ -112,8 +109,8 @@ abstract class DartType {
112109
List<FunctionTypeVariable> functionTypeVariables,
113110
);
114111

115-
/// Returns the base type if this is a [LegacyType] or [NullableType] and
116-
/// returns this type otherwise.
112+
/// Returns the base type if this is a [NullableType] and returns this type
113+
/// otherwise.
117114
DartType get withoutNullability => this;
118115

119116
/// Whether this type contains a type variable.
@@ -142,10 +139,10 @@ abstract class DartType {
142139
bool _equals(DartType other, _Assumptions? assumptions);
143140

144141
@override
145-
String toString() => toStructuredText(null, null);
142+
String toString() => toStructuredText(null);
146143

147-
String toStructuredText(DartTypes? dartTypes, CompilerOptions? options) =>
148-
_DartTypeToStringVisitor(dartTypes, options).run(this);
144+
String toStructuredText(DartTypes? dartTypes) =>
145+
_DartTypeToStringVisitor(dartTypes).run(this);
149146
}
150147

151148
/// Pairs of [FunctionTypeVariable]s that are currently assumed to be
@@ -231,67 +228,6 @@ class _Assumptions {
231228
}
232229
}
233230

234-
class LegacyType extends DartType {
235-
final DartType baseType;
236-
237-
const LegacyType._(this.baseType);
238-
239-
factory LegacyType._readFromDataSource(
240-
DataSourceReader source,
241-
List<FunctionTypeVariable> functionTypeVariables,
242-
) {
243-
DartType baseType = DartType.readFromDataSource(
244-
source,
245-
functionTypeVariables,
246-
);
247-
return LegacyType._(baseType);
248-
}
249-
250-
@override
251-
void writeToDataSink(
252-
DataSinkWriter sink,
253-
List<FunctionTypeVariable> functionTypeVariables,
254-
) {
255-
sink.writeEnum(DartTypeKind.legacyType);
256-
baseType.writeToDataSink(sink, functionTypeVariables);
257-
}
258-
259-
@override
260-
DartType get withoutNullability => baseType;
261-
262-
@override
263-
bool get containsTypeVariables => baseType.containsTypeVariables;
264-
265-
@override
266-
void forEachTypeVariable(void Function(TypeVariableType variable) f) {
267-
baseType.forEachTypeVariable(f);
268-
}
269-
270-
@override
271-
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
272-
visitor.visitLegacyType(this, argument);
273-
274-
@override
275-
int get hashCode => baseType.hashCode * 31;
276-
277-
@override
278-
bool operator ==(other) {
279-
if (identical(this, other)) return true;
280-
if (other is! LegacyType) return false;
281-
return _equalsInternal(other, null);
282-
}
283-
284-
@override
285-
bool _equals(DartType other, _Assumptions? assumptions) {
286-
if (identical(this, other)) return true;
287-
if (other is! LegacyType) return false;
288-
return _equalsInternal(other, assumptions);
289-
}
290-
291-
bool _equalsInternal(LegacyType other, _Assumptions? assumptions) =>
292-
baseType._equals(other.baseType, assumptions);
293-
}
294-
295231
class NullableType extends DartType {
296232
final DartType baseType;
297233

@@ -1091,8 +1027,6 @@ abstract class DartTypeVisitor<R, A> {
10911027

10921028
R visit(covariant DartType type, A argument) => type.accept(this, argument);
10931029

1094-
R visitLegacyType(covariant LegacyType type, A argument);
1095-
10961030
R visitNullableType(covariant NullableType type, A argument);
10971031

10981032
R visitNeverType(covariant NeverType type, A argument);
@@ -1133,9 +1067,6 @@ class _LegacyErasureVisitor extends DartTypeVisitor<DartType, Null> {
11331067
@override
11341068
DartType visit(DartType type, Null _) => type.accept(this, null);
11351069

1136-
@override
1137-
DartType visitLegacyType(LegacyType type, Null _) => erase(type.baseType);
1138-
11391070
@override
11401071
DartType visitNullableType(NullableType type, Null _) {
11411072
var baseType = erase(type.baseType);
@@ -1280,19 +1211,6 @@ abstract class DartTypeSubstitutionVisitor<A>
12801211
bool freshReference,
12811212
) => type;
12821213

1283-
@override
1284-
DartType visitLegacyType(covariant LegacyType type, A argument) {
1285-
DartType? probe = _map[type];
1286-
if (probe != null) return probe;
1287-
1288-
DartType newBaseType = visit(type.baseType, argument);
1289-
// Create a new type only if necessary.
1290-
if (identical(type.baseType, newBaseType)) {
1291-
return _mapped(type, type);
1292-
}
1293-
return _mapped(type, dartTypes.legacyType(newBaseType));
1294-
}
1295-
12961214
@override
12971215
DartType visitNullableType(covariant NullableType type, A argument) {
12981216
DartType? probe = _map[type];
@@ -1540,7 +1458,6 @@ abstract class DartTypeStructuralPredicateVisitor
15401458

15411459
bool run(DartType type) => visit(type, null);
15421460

1543-
bool handleLegacyType(LegacyType type) => false;
15441461
bool handleNullableType(NullableType type) => false;
15451462
bool handleNeverType(NeverType type) => false;
15461463
bool handleVoidType(VoidType type) => false;
@@ -1555,10 +1472,6 @@ abstract class DartTypeStructuralPredicateVisitor
15551472
bool handleAnyType(AnyType type) => false;
15561473
bool handleFutureOrType(FutureOrType type) => false;
15571474

1558-
@override
1559-
bool visitLegacyType(LegacyType type, List<FunctionTypeVariable>? bindings) =>
1560-
handleLegacyType(type) || visit(type.baseType, bindings);
1561-
15621475
@override
15631476
bool visitNullableType(
15641477
NullableType type,
@@ -1727,14 +1640,13 @@ class _DeferredName {
17271640

17281641
class _DartTypeToStringVisitor extends DartTypeVisitor<void, void> {
17291642
final DartTypes? _dartTypes; // May be null.
1730-
final CompilerOptions? _options; // May be null.
17311643
final List<Object> _fragments = []; // Strings and _DeferredNames
17321644
bool _lastIsIdentifier = false;
17331645
List<FunctionTypeVariable>? _boundVariables;
17341646
Map<FunctionTypeVariable, _DeferredName>? _variableToName;
17351647
Set<FunctionType>? _genericFunctions;
17361648

1737-
_DartTypeToStringVisitor(this._dartTypes, this._options);
1649+
_DartTypeToStringVisitor(this._dartTypes);
17381650

17391651
String run(DartType type) {
17401652
_visit(type);
@@ -1793,18 +1705,6 @@ class _DartTypeToStringVisitor extends DartTypeVisitor<void, void> {
17931705
type.accept(this, null);
17941706
}
17951707

1796-
@override
1797-
void visitLegacyType(covariant LegacyType type, _) {
1798-
_visit(type.baseType);
1799-
// We do not emit the '*' token for legacy types because this is a purely
1800-
// internal notion. The language specification does not define a '*' token
1801-
// in the type language, and no such token should be surfaced to users.
1802-
// For debugging, pass `--debug-print-legacy-stars` to emit the '*'.
1803-
if (_options == null || _options.printLegacyStars) {
1804-
_token('*');
1805-
}
1806-
}
1807-
18081708
@override
18091709
void visitNullableType(covariant NullableType type, _) {
18101710
_visit(type.baseType);
@@ -1987,25 +1887,11 @@ abstract class DartTypes {
19871887

19881888
bool get useLegacySubtyping;
19891889

1990-
DartType legacyType(DartType baseType) {
1991-
DartType result;
1992-
if (isStrongTopType(baseType) ||
1993-
baseType.isNull ||
1994-
baseType is LegacyType ||
1995-
baseType is NullableType) {
1996-
result = baseType;
1997-
} else {
1998-
result = LegacyType._(baseType);
1999-
}
2000-
return result;
2001-
}
2002-
20031890
DartType nullableType(DartType baseType) {
20041891
bool isNullable(DartType t) =>
20051892
// Note that we can assume null safety is enabled here.
20061893
t.isNull ||
20071894
t is NullableType ||
2008-
t is LegacyType && isNullable(t.baseType) ||
20091895
t is FutureOrType && isNullable(t.typeArgument) ||
20101896
isStrongTopType(t);
20111897

@@ -2017,16 +1903,6 @@ abstract class DartTypes {
20171903
result = baseType;
20181904
} else if (baseType is NeverType) {
20191905
result = commonElements.nullType;
2020-
} else if (baseType is LegacyType) {
2021-
DartType legacyBaseType = baseType.baseType;
2022-
if (legacyBaseType is NeverType) {
2023-
result = commonElements.nullType;
2024-
} else if (legacyBaseType is FutureOrType &&
2025-
isNullable(legacyBaseType.typeArgument)) {
2026-
result = legacyBaseType;
2027-
} else {
2028-
result = nullableType(legacyBaseType);
2029-
}
20301906
} else {
20311907
result = NullableType._(baseType);
20321908
}
@@ -2177,9 +2053,7 @@ abstract class DartTypes {
21772053

21782054
/// Returns `true` if [t] is a top type, that is, a supertype of every type.
21792055
bool isTopType(DartType t) =>
2180-
isStrongTopType(t) ||
2181-
t is LegacyType && t.baseType.isObject ||
2182-
useLegacySubtyping && t.isObject;
2056+
isStrongTopType(t) || useLegacySubtyping && t.isObject;
21832057

21842058
bool isStrongTopType(DartType t) =>
21852059
t is VoidType ||
@@ -2257,36 +2131,17 @@ abstract class DartTypes {
22572131
if (t is FutureOrType) {
22582132
return isSubtype(s, t.typeArgument, env);
22592133
}
2260-
return t.isNull || t is LegacyType || t is NullableType;
2134+
return t.isNull || t is NullableType;
22612135
}
22622136

22632137
// Right Object:
22642138
if (!useLegacySubtyping && t.isObject) {
22652139
if (s is FutureOrType) {
22662140
return isSubtype(s.typeArgument, t, env);
22672141
}
2268-
if (s is LegacyType) {
2269-
return isSubtype(s.baseType, t, env);
2270-
}
22712142
return s is! NullableType;
22722143
}
22732144

2274-
// Left Legacy:
2275-
if (s is LegacyType) {
2276-
return isSubtype(s.baseType, t, env);
2277-
}
2278-
2279-
// Right Legacy:
2280-
if (t is LegacyType) {
2281-
// Note that to convert `T*` to `T?`, we can't just say `t._toNullable`.
2282-
// The resulting type `T?` may be normalizable (e.g. if `T` is `Never`).
2283-
return isSubtype(
2284-
s,
2285-
useLegacySubtyping ? t.baseType : nullableType(t),
2286-
env,
2287-
);
2288-
}
2289-
22902145
// Left FutureOr:
22912146
if (s is FutureOrType) {
22922147
DartType typeArgument = s.typeArgument;
@@ -2620,9 +2475,6 @@ abstract class DartTypes {
26202475
return false;
26212476
}
26222477
if (type is NullableType) return false;
2623-
if (type is LegacyType) {
2624-
return isNonNullableIfSound(type.baseType);
2625-
}
26262478
if (type is InterfaceType) {
26272479
if (type.isNull) return false;
26282480
return true;
@@ -2640,7 +2492,6 @@ abstract class DartTypes {
26402492
}
26412493

26422494
DartType getUnionFreeType(DartType type) {
2643-
if (type is LegacyType) return getUnionFreeType(type.baseType);
26442495
if (type is NullableType) return getUnionFreeType(type.baseType);
26452496
if (type is FutureOrType) return getUnionFreeType(type.typeArgument);
26462497
return type;

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -466,19 +466,6 @@ class PowersetBitsDomain {
466466
return _createFromStaticType(type.baseType, true);
467467
}
468468

469-
if (type is LegacyType) {
470-
DartType baseType = type.baseType;
471-
if (baseType is NeverType) {
472-
// Never* is same as Null, for both 'is' and 'as'.
473-
return nullMask;
474-
}
475-
476-
// Object* is a top type for both 'is' and 'as'. This is handled in the
477-
// 'cone of top type' case above.
478-
479-
return _createFromStaticType(baseType, nullable);
480-
}
481-
482469
if (dartTypes.useLegacySubtyping) {
483470
// In legacy and weak mode, `String` is nullable depending on context.
484471
return _createFromStaticType(type, nullable);

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,6 @@ class CommonMasks with AbstractValueDomain {
333333
return _createFromStaticType(type.baseType, true);
334334
}
335335

336-
if (type is LegacyType) {
337-
DartType baseType = type.baseType;
338-
if (baseType is NeverType) {
339-
// Never* is same as Null, for both 'is' and 'as'.
340-
return AbstractValueWithPrecision(nullType, true);
341-
}
342-
343-
// Object* is a top type for both 'is' and 'as'. This is handled in the
344-
// 'cone of top type' case above.
345-
346-
return _createFromStaticType(baseType, nullable);
347-
}
348-
349336
if (dartTypes.useLegacySubtyping) {
350337
// In legacy and weak mode, `String` is nullable depending on context.
351338
return _createFromStaticType(type, nullable);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ImpactBuilder extends ir.RecursiveVisitor implements ImpactRegistry {
108108
CompilerOptions get _options => _elementMap.options;
109109

110110
String _typeToString(DartType type) =>
111-
type.toStructuredText(_elementMap.types, _elementMap.options);
111+
type.toStructuredText(_elementMap.types);
112112

113113
/// Return the named arguments names as a list of strings.
114114
List<String> _getNamedArguments(ir.Arguments arguments) =>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ class DartTypeConverter extends ir.DartTypeVisitor<DartType> {
6363
case ir.Nullability.nullable:
6464
return _dartTypes.nullableType(baseType);
6565
case ir.Nullability.legacy:
66-
return _dartTypes.legacyType(baseType);
66+
throw UnsupportedError(
67+
'Unexpected legacy nullability on $nullabilitySource',
68+
);
6769
case ir.Nullability.undetermined:
6870
// Type parameters may have undetermined nullability since it is derived
6971
// from the intersection of the declared nullability with the

pkg/compiler/lib/src/js_backend/namer.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,10 +1166,6 @@ class _TypeConstantRepresentationVisitor extends DartTypeVisitor<String, Null> {
11661166

11671167
String _represent(DartType type) => visit(type, null);
11681168

1169-
@override
1170-
String visitLegacyType(LegacyType type, _) =>
1171-
'legacy_${_represent(type.baseType)}';
1172-
11731169
@override
11741170
String visitNullableType(NullableType type, _) =>
11751171
'nullable_${_represent(type.baseType)}';

0 commit comments

Comments
 (0)