Skip to content

Commit

Permalink
Further cleanup of element use in type_graph_nodes
Browse files Browse the repository at this point in the history
R=sigmund@google.com

Review-Url: https://codereview.chromium.org/2976483002 .
  • Loading branch information
johnniwinther committed Jul 10, 2017
1 parent 5dbd502 commit 3bd55a5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
45 changes: 24 additions & 21 deletions pkg/compiler/lib/src/inferrer/type_graph_nodes.dart
Expand Up @@ -10,10 +10,9 @@ import '../common.dart';
import '../common/names.dart' show Identifiers;
import '../compiler.dart' show Compiler;
import '../constants/values.dart';
import '../elements/elements.dart';
import '../elements/elements.dart'
show ConstructorElement, LocalElement, MemberElement;
import '../elements/entities.dart';
import '../elements/resolution_types.dart'
show ResolutionDartType, ResolutionInterfaceType;
import '../elements/types.dart';
import '../tree/tree.dart' as ast show Node, Send;
import '../types/masks.dart'
Expand Down Expand Up @@ -404,7 +403,6 @@ abstract class MemberTypeInformation extends ElementTypeInformation
String get debugName => '$member';

void addCall(MemberEntity caller, Spannable node) {
assert(node is ast.Node || node is Element);
_callers ??= <MemberEntity, Setlet<Spannable>>{};
_callers.putIfAbsent(caller, () => new Setlet()).add(node);
}
Expand Down Expand Up @@ -819,7 +817,7 @@ class ParameterTypeInformation extends ElementTypeInformation {
return visitor.visitParameterTypeInformation(this);
}

String toString() => 'ParameterElement $_parameter $type';
String toString() => 'Parameter $_parameter $type';

@override
String getInferredSignature(TypeSystem types) {
Expand Down Expand Up @@ -850,6 +848,9 @@ abstract class CallSiteTypeInformation extends TypeInformation
this.selector, this.mask, this.arguments, this.inLoop)
: super.noAssignments(context) {
assert(_checkCaller(caller));
// [call] is either an AST node or a constructor element in case of a
// a forwarding constructor call.
assert(call is ast.Node || call is ConstructorElement);
}

bool _checkCaller(MemberEntity caller) {
Expand Down Expand Up @@ -1016,8 +1017,6 @@ class DynamicCallSiteTypeInformation extends CallSiteTypeInformation {
TypeInformation handleIntrisifiedSelector(
Selector selector, TypeMask mask, InferrerEngine inferrer) {
ClosedWorld closedWorld = inferrer.closedWorld;
ClassElement intClass = closedWorld.commonElements.jsIntClass;
if (!intClass.isResolved) return null;
if (mask == null) return null;
if (!mask.containsOnlyInt(closedWorld)) {
return null;
Expand All @@ -1026,8 +1025,7 @@ class DynamicCallSiteTypeInformation extends CallSiteTypeInformation {
if (!arguments.named.isEmpty) return null;
if (arguments.positional.length > 1) return null;

ClassElement uint31Implementation =
closedWorld.commonElements.jsUInt31Class;
ClassEntity uint31Implementation = closedWorld.commonElements.jsUInt31Class;
bool isInt(info) => info.type.containsOnlyInt(closedWorld);
bool isEmpty(info) => info.type.isEmpty;
bool isUInt31(info) {
Expand Down Expand Up @@ -1163,8 +1161,8 @@ class DynamicCallSiteTypeInformation extends CallSiteTypeInformation {

// Walk over the found targets, and compute the joined union type mask
// for all these targets.
TypeMask result = inferrer.types.joinTypeMasks(targets.map((_element) {
MemberElement element = _element;
TypeMask result =
inferrer.types.joinTypeMasks(targets.map((MemberEntity element) {
// If [canReachAll] is true, then we are iterating over all
// targets that satisfy the untyped selector. We skip the return
// type of the targets that can only be reached through
Expand Down Expand Up @@ -1779,7 +1777,7 @@ class PhiElementTypeInformation extends TypeInformation {
class ClosureTypeInformation extends TypeInformation
with ApplyableTypeInformation {
final ast.Node node;
final MethodElement _element;
final FunctionEntity _element;

ClosureTypeInformation(
MemberTypeInformation context, this.node, this._element)
Expand Down Expand Up @@ -1898,20 +1896,25 @@ abstract class TypeInformationVisitor<T> {
}

TypeMask _narrowType(
ClosedWorld closedWorld, TypeMask type, ResolutionDartType annotation,
ClosedWorld closedWorld, TypeMask type, DartType annotation,
{bool isNullable: true}) {
if (annotation.treatAsDynamic) return type;
if (annotation.isObject) return type;
if (annotation.isVoid) return type;
TypeMask otherType;
if (annotation.isTypedef || annotation.isFunctionType) {
if (annotation.treatAsDynamic) {
return type;
} else if (annotation.isInterfaceType) {
InterfaceType interfaceType = annotation;
if (interfaceType.element == closedWorld.commonElements.objectClass) {
return type;
}
otherType = new TypeMask.nonNullSubtype(interfaceType.element, closedWorld);
} else if (annotation.isVoid) {
return type;
} else if (annotation.isTypedef || annotation.isFunctionType) {
otherType = closedWorld.commonMasks.functionType;
} else if (annotation.isTypeVariable) {
} else {
assert(annotation.isTypeVariable);
// TODO(ngeoffray): Narrow to bound.
return type;
} else {
ResolutionInterfaceType interfaceType = annotation;
otherType = new TypeMask.nonNullSubtype(interfaceType.element, closedWorld);
}
if (isNullable) otherType = otherType.nullable();
if (type == null) return otherType;
Expand Down
4 changes: 2 additions & 2 deletions pkg/compiler/lib/src/inferrer/type_system.dart
Expand Up @@ -453,7 +453,7 @@ class TypeSystem {
}

TypeInformation allocateList(
TypeInformation type, ast.Node node, Element enclosing,
TypeInformation type, ast.Node node, MemberElement enclosing,
[TypeInformation elementType, int length]) {
ClassElement typedDataClass = closedWorld.commonElements.typedDataClass;
bool isTypedArray = typedDataClass != null &&
Expand Down Expand Up @@ -489,7 +489,7 @@ class TypeSystem {
}

TypeInformation allocateMap(
ConcreteTypeInformation type, ast.Node node, Element element,
ConcreteTypeInformation type, ast.Node node, MemberElement element,
[List<TypeInformation> keyTypes, List<TypeInformation> valueTypes]) {
assert(keyTypes.length == valueTypes.length);
bool isFixed = (type.type == commonMasks.constMapType);
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/types/container_type_mask.dart
Expand Up @@ -14,7 +14,7 @@ class ContainerTypeMask extends ForwardingTypeMask {
final Node allocationNode;

// The [Entity] where this type mask was created.
final Entity allocationElement;
final MemberEntity allocationElement;

// The element type of this container.
final TypeMask elementType;
Expand Down
9 changes: 7 additions & 2 deletions pkg/compiler/lib/src/types/dictionary_type_mask.dart
Expand Up @@ -16,8 +16,13 @@ class DictionaryTypeMask extends MapTypeMask {
// The underlying key/value map of this dictionary.
final Map<String, TypeMask> typeMap;

DictionaryTypeMask(forwardTo, allocationNode, allocationElement, keyType,
valueType, this.typeMap)
DictionaryTypeMask(
TypeMask forwardTo,
Node allocationNode,
MemberEntity allocationElement,
TypeMask keyType,
TypeMask valueType,
this.typeMap)
: super(forwardTo, allocationNode, allocationElement, keyType, valueType);

TypeMask nullable() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/compiler/lib/src/types/map_type_mask.dart
Expand Up @@ -15,8 +15,8 @@ class MapTypeMask extends ForwardingTypeMask {
// The [Node] where this type mask was created.
final Node allocationNode;

// The [Entity] where this type mask was created.
final Entity allocationElement;
// The [MemberEntity] where this type mask was created.
final MemberEntity allocationElement;

// The value type of this map.
final TypeMask valueType;
Expand Down

0 comments on commit 3bd55a5

Please sign in to comment.