Skip to content

Commit 4c442cd

Browse files
fishythefishcommit-bot@chromium.org
authored andcommitted
[dart2js] Remove treatAsDynamic.
Change-Id: I361de27bcd61b18e0bf1ea07516e71a84a1c3807 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126604 Commit-Queue: Mayank Patke <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]>
1 parent de53a2c commit 4c442cd

File tree

12 files changed

+23
-36
lines changed

12 files changed

+23
-36
lines changed

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@ abstract class DartType {
3636
DartType get unaliased => this;
3737

3838
/// Is `true` if this type is a top type.
39-
// TODO(fishythefish): Update this for normalization.
39+
// TODO(fishythefish): Update this for NNBD.
4040
bool get isTop => false;
4141

42-
/// Is `true` if this type has no non-dynamic type arguments.
42+
/// Is `true` if this type has no non-top type arguments.
4343
bool get treatAsRaw => true;
4444

45-
/// Is `true` if this type should be treated as the dynamic type.
46-
bool get treatAsDynamic => false;
47-
4845
/// Whether this type contains a type variable.
4946
bool get containsTypeVariables => false;
5047

@@ -248,7 +245,7 @@ class InterfaceType extends DartType {
248245
@override
249246
bool get treatAsRaw {
250247
for (DartType type in typeArguments) {
251-
if (!type.treatAsDynamic) return false;
248+
if (!type.isTop) return false;
252249
}
253250
return true;
254251
}
@@ -310,7 +307,7 @@ class TypedefType extends DartType {
310307
@override
311308
bool get treatAsRaw {
312309
for (DartType type in typeArguments) {
313-
if (!type.treatAsDynamic) return false;
310+
if (!type.isTop) return false;
314311
}
315312
return true;
316313
}
@@ -482,9 +479,6 @@ class DynamicType extends DartType {
482479
@override
483480
bool get isTop => true;
484481

485-
@override
486-
bool get treatAsDynamic => true;
487-
488482
@override
489483
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
490484
visitor.visitDynamicType(this, argument);
@@ -506,9 +500,6 @@ class ErasedType extends DartType {
506500
@override
507501
bool get isTop => true;
508502

509-
@override
510-
bool get treatAsDynamic => true;
511-
512503
@override
513504
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
514505
visitor.visitErasedType(this, argument);
@@ -1741,13 +1732,13 @@ abstract class MoreSpecificVisitor<T extends DartType>
17411732
if (identical(t, s) ||
17421733
t is AnyType ||
17431734
s is AnyType ||
1744-
s.treatAsDynamic ||
1735+
s.isTop ||
17451736
s is VoidType ||
17461737
s == commonElements.objectType ||
17471738
t == commonElements.nullType) {
17481739
return true;
17491740
}
1750-
if (t.treatAsDynamic) {
1741+
if (t.isTop) {
17511742
return false;
17521743
}
17531744

@@ -1764,7 +1755,7 @@ abstract class MoreSpecificVisitor<T extends DartType>
17641755

17651756
@override
17661757
bool invalidFunctionReturnTypes(T t, T s) {
1767-
if (s.treatAsDynamic && t is VoidType) return true;
1758+
if (s.isTop && t is VoidType) return true;
17681759
return s is! VoidType && !isMoreSpecific(t, s);
17691760
}
17701761

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,7 @@ AbstractValue _narrowType(
22692269
{bool isNullable: true}) {
22702270
AbstractValueDomain abstractValueDomain = closedWorld.abstractValueDomain;
22712271
AbstractValue otherType;
2272-
if (annotation.treatAsDynamic) {
2272+
if (annotation.isTop) {
22732273
return type;
22742274
} else if (annotation is InterfaceType) {
22752275
if (annotation.element == closedWorld.commonElements.objectClass) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class TypeSystem {
319319
{bool isNullable: true}) {
320320
AbstractValue otherType;
321321
if (annotation is VoidType) return type;
322-
if (annotation.treatAsDynamic) {
322+
if (annotation.isTop) {
323323
if (isNullable) return type;
324324
// If the input is already narrowed to be not-null, there is no value
325325
// in adding another narrowing node.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ class TypeRepresentationGenerator
11641164
visitList(type.typeVariables.map((v) => v.bound).toList(), emitter));
11651165
}
11661166

1167-
if (!type.returnType.treatAsDynamic) {
1167+
if (type.returnType is! DynamicType) {
11681168
addProperty(
11691169
_rtiTags.functionTypeReturnTypeTag, visit(type.returnType, emitter));
11701170
}
@@ -1270,7 +1270,7 @@ class TypeRepresentationGenerator
12701270
// Type representations for FutureOr have a property which is a tag marking
12711271
// them as FutureOr types. The value is not used, so '1' is just a dummy.
12721272
addProperty(_rtiTags.futureOrTag, js.number(1));
1273-
if (!type.typeArgument.treatAsDynamic) {
1273+
if (type.typeArgument is! DynamicType) {
12741274
addProperty(_rtiTags.futureOrTypeTag, visit(type.typeArgument, emitter));
12751275
}
12761276

pkg/compiler/lib/src/js_emitter/program_builder/field_visitor.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ typedef void AcceptField(FieldEntity member, js.Name name, js.Name accessorName,
2525

2626
class FieldVisitor {
2727
final JElementEnvironment _elementEnvironment;
28-
final JCommonElements _commonElements;
2928
final CodegenWorld _codegenWorld;
3029
final NativeData _nativeData;
3130
final Namer _namer;
3231
final JClosedWorld _closedWorld;
3332

34-
FieldVisitor(this._elementEnvironment, this._commonElements,
35-
this._codegenWorld, this._nativeData, this._namer, this._closedWorld);
33+
FieldVisitor(this._elementEnvironment, this._codegenWorld, this._nativeData,
34+
this._namer, this._closedWorld);
3635

3736
/// Invokes [f] for each of the fields of [element].
3837
///
@@ -159,6 +158,6 @@ class FieldVisitor {
159158
// We never generate accessors for top-level/static fields.
160159
if (!member.isInstanceMember) return true;
161160
DartType type = _elementEnvironment.getFieldType(member);
162-
return type.treatAsDynamic || type == _commonElements.objectType;
161+
return type.isTop;
163162
}
164163
}

pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,8 @@ class ProgramBuilder {
11711171
fieldData.isElided));
11721172
}
11731173

1174-
FieldVisitor visitor = new FieldVisitor(_elementEnvironment,
1175-
_commonElements, _codegenWorld, _nativeData, _namer, _closedWorld);
1174+
FieldVisitor visitor = new FieldVisitor(
1175+
_elementEnvironment, _codegenWorld, _nativeData, _namer, _closedWorld);
11761176
visitor.visitFields(visitField,
11771177
visitStatics: visitStatics, library: library, cls: cls);
11781178

pkg/compiler/lib/src/ssa/builder_kernel.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5418,7 +5418,7 @@ class KernelSsaGraphBuilder extends ir.Visitor {
54185418
DartType typeValue =
54195419
localsHandler.substInContext(_elementMap.getDartType(type));
54205420

5421-
if (typeValue.treatAsDynamic) {
5421+
if (typeValue.isTop) {
54225422
stack.add(graph.addConstantBool(true, closedWorld));
54235423
return;
54245424
}
@@ -5550,7 +5550,7 @@ class KernelSsaGraphBuilder extends ir.Visitor {
55505550
List<DartType> bounds = thisType.typeArguments;
55515551
for (int i = 0; i < bounds.length; i++) {
55525552
DartType arg = type.typeArguments[i];
5553-
if (arg.treatAsDynamic) continue;
5553+
if (arg.isTop) continue;
55545554
TypeVariableType typeVariable = bounds[i];
55555555
DartType bound =
55565556
_elementEnvironment.getTypeVariableBound(typeVariable.element);

pkg/compiler/lib/src/ssa/codegen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,8 +3065,7 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
30653065
} else {
30663066
checkNull(input);
30673067
}
3068-
} else if (element ==
3069-
_commonElements.objectClass /* || type.treatAsDynamic*/) {
3068+
} else if (element == _commonElements.objectClass /* || type.isTop*/) {
30703069
// The constant folder also does this optimization, but we make
30713070
// it safe by assuming it may have not run.
30723071
push(newLiteralBool(!negative, sourceInformation));

pkg/compiler/lib/src/ssa/optimize.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
11011101
return node;
11021102
}
11031103

1104-
if (type == commonElements.objectType || type.treatAsDynamic) {
1104+
if (type.isTop) {
11051105
return _graph.addConstantBool(true, _closedWorld);
11061106
}
11071107
InterfaceType interfaceType = type;

pkg/compiler/lib/src/ssa/type_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ abstract class TypeBuilder {
256256
sourceInformation: sourceInformation);
257257
}
258258
argument = argument.unaliased;
259-
if (argument.treatAsDynamic) {
259+
if (argument is DynamicType) {
260260
// Represent [dynamic] as [null].
261261
return builder.graph.addConstantNull(_closedWorld);
262262
}

0 commit comments

Comments
 (0)