Skip to content

Commit

Permalink
[dart2js] Remove treatAsDynamic.
Browse files Browse the repository at this point in the history
Change-Id: I361de27bcd61b18e0bf1ea07516e71a84a1c3807
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126604
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
  • Loading branch information
fishythefish authored and commit-bot@chromium.org committed Dec 6, 2019
1 parent de53a2c commit 4c442cd
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 36 deletions.
23 changes: 7 additions & 16 deletions pkg/compiler/lib/src/elements/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ abstract class DartType {
DartType get unaliased => this;

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

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

/// Is `true` if this type should be treated as the dynamic type.
bool get treatAsDynamic => false;

/// Whether this type contains a type variable.
bool get containsTypeVariables => false;

Expand Down Expand Up @@ -248,7 +245,7 @@ class InterfaceType extends DartType {
@override
bool get treatAsRaw {
for (DartType type in typeArguments) {
if (!type.treatAsDynamic) return false;
if (!type.isTop) return false;
}
return true;
}
Expand Down Expand Up @@ -310,7 +307,7 @@ class TypedefType extends DartType {
@override
bool get treatAsRaw {
for (DartType type in typeArguments) {
if (!type.treatAsDynamic) return false;
if (!type.isTop) return false;
}
return true;
}
Expand Down Expand Up @@ -482,9 +479,6 @@ class DynamicType extends DartType {
@override
bool get isTop => true;

@override
bool get treatAsDynamic => true;

@override
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
visitor.visitDynamicType(this, argument);
Expand All @@ -506,9 +500,6 @@ class ErasedType extends DartType {
@override
bool get isTop => true;

@override
bool get treatAsDynamic => true;

@override
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
visitor.visitErasedType(this, argument);
Expand Down Expand Up @@ -1741,13 +1732,13 @@ abstract class MoreSpecificVisitor<T extends DartType>
if (identical(t, s) ||
t is AnyType ||
s is AnyType ||
s.treatAsDynamic ||
s.isTop ||
s is VoidType ||
s == commonElements.objectType ||
t == commonElements.nullType) {
return true;
}
if (t.treatAsDynamic) {
if (t.isTop) {
return false;
}

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

@override
bool invalidFunctionReturnTypes(T t, T s) {
if (s.treatAsDynamic && t is VoidType) return true;
if (s.isTop && t is VoidType) return true;
return s is! VoidType && !isMoreSpecific(t, s);
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/inferrer/type_graph_nodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2269,7 +2269,7 @@ AbstractValue _narrowType(
{bool isNullable: true}) {
AbstractValueDomain abstractValueDomain = closedWorld.abstractValueDomain;
AbstractValue otherType;
if (annotation.treatAsDynamic) {
if (annotation.isTop) {
return type;
} else if (annotation is InterfaceType) {
if (annotation.element == closedWorld.commonElements.objectClass) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/inferrer/type_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class TypeSystem {
{bool isNullable: true}) {
AbstractValue otherType;
if (annotation is VoidType) return type;
if (annotation.treatAsDynamic) {
if (annotation.isTop) {
if (isNullable) return type;
// If the input is already narrowed to be not-null, there is no value
// in adding another narrowing node.
Expand Down
4 changes: 2 additions & 2 deletions pkg/compiler/lib/src/js_backend/runtime_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ class TypeRepresentationGenerator
visitList(type.typeVariables.map((v) => v.bound).toList(), emitter));
}

if (!type.returnType.treatAsDynamic) {
if (type.returnType is! DynamicType) {
addProperty(
_rtiTags.functionTypeReturnTypeTag, visit(type.returnType, emitter));
}
Expand Down Expand Up @@ -1270,7 +1270,7 @@ class TypeRepresentationGenerator
// Type representations for FutureOr have a property which is a tag marking
// them as FutureOr types. The value is not used, so '1' is just a dummy.
addProperty(_rtiTags.futureOrTag, js.number(1));
if (!type.typeArgument.treatAsDynamic) {
if (type.typeArgument is! DynamicType) {
addProperty(_rtiTags.futureOrTypeTag, visit(type.typeArgument, emitter));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ typedef void AcceptField(FieldEntity member, js.Name name, js.Name accessorName,

class FieldVisitor {
final JElementEnvironment _elementEnvironment;
final JCommonElements _commonElements;
final CodegenWorld _codegenWorld;
final NativeData _nativeData;
final Namer _namer;
final JClosedWorld _closedWorld;

FieldVisitor(this._elementEnvironment, this._commonElements,
this._codegenWorld, this._nativeData, this._namer, this._closedWorld);
FieldVisitor(this._elementEnvironment, this._codegenWorld, this._nativeData,
this._namer, this._closedWorld);

/// Invokes [f] for each of the fields of [element].
///
Expand Down Expand Up @@ -159,6 +158,6 @@ class FieldVisitor {
// We never generate accessors for top-level/static fields.
if (!member.isInstanceMember) return true;
DartType type = _elementEnvironment.getFieldType(member);
return type.treatAsDynamic || type == _commonElements.objectType;
return type.isTop;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,8 @@ class ProgramBuilder {
fieldData.isElided));
}

FieldVisitor visitor = new FieldVisitor(_elementEnvironment,
_commonElements, _codegenWorld, _nativeData, _namer, _closedWorld);
FieldVisitor visitor = new FieldVisitor(
_elementEnvironment, _codegenWorld, _nativeData, _namer, _closedWorld);
visitor.visitFields(visitField,
visitStatics: visitStatics, library: library, cls: cls);

Expand Down
4 changes: 2 additions & 2 deletions pkg/compiler/lib/src/ssa/builder_kernel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5418,7 +5418,7 @@ class KernelSsaGraphBuilder extends ir.Visitor {
DartType typeValue =
localsHandler.substInContext(_elementMap.getDartType(type));

if (typeValue.treatAsDynamic) {
if (typeValue.isTop) {
stack.add(graph.addConstantBool(true, closedWorld));
return;
}
Expand Down Expand Up @@ -5550,7 +5550,7 @@ class KernelSsaGraphBuilder extends ir.Visitor {
List<DartType> bounds = thisType.typeArguments;
for (int i = 0; i < bounds.length; i++) {
DartType arg = type.typeArguments[i];
if (arg.treatAsDynamic) continue;
if (arg.isTop) continue;
TypeVariableType typeVariable = bounds[i];
DartType bound =
_elementEnvironment.getTypeVariableBound(typeVariable.element);
Expand Down
3 changes: 1 addition & 2 deletions pkg/compiler/lib/src/ssa/codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3065,8 +3065,7 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
} else {
checkNull(input);
}
} else if (element ==
_commonElements.objectClass /* || type.treatAsDynamic*/) {
} else if (element == _commonElements.objectClass /* || type.isTop*/) {
// The constant folder also does this optimization, but we make
// it safe by assuming it may have not run.
push(newLiteralBool(!negative, sourceInformation));
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/ssa/optimize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
return node;
}

if (type == commonElements.objectType || type.treatAsDynamic) {
if (type.isTop) {
return _graph.addConstantBool(true, _closedWorld);
}
InterfaceType interfaceType = type;
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/ssa/type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ abstract class TypeBuilder {
sourceInformation: sourceInformation);
}
argument = argument.unaliased;
if (argument.treatAsDynamic) {
if (argument is DynamicType) {
// Represent [dynamic] as [null].
return builder.graph.addConstantNull(_closedWorld);
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/compiler/lib/src/ssa/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ class AbstractValueFactory {
.createNonNullExact(commonElements.objectClass);
} else if (type is VoidType) {
return abstractValueDomain.nullType;
} else if (type is DynamicType) {
} else if (type.isTop) {
return abstractValueDomain.dynamicType;
} else if (type == commonElements.nullType) {
return abstractValueDomain.nullType;
} else if (type.treatAsDynamic) {
return abstractValueDomain.dynamicType;
} else {
return abstractValueDomain.createNonNullSubtype(type.element);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/dart2js/analyses/dart2js_allowed.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
"Dynamic invocation of 'addSuccessor'.": 1
},
"pkg/compiler/lib/src/ssa/types.dart": {
"Dynamic access of 'treatAsDynamic'.": 1,
"Dynamic access of 'isTop'.": 1,
"Dynamic access of 'element'.": 1
},
"pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart": {
Expand Down

0 comments on commit 4c442cd

Please sign in to comment.