From 3bd55a50242aabb839e218fd5bdd7695d2900ec2 Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Mon, 10 Jul 2017 13:04:59 +0200 Subject: [PATCH] Further cleanup of element use in type_graph_nodes R=sigmund@google.com Review-Url: https://codereview.chromium.org/2976483002 . --- .../lib/src/inferrer/type_graph_nodes.dart | 45 ++++++++++--------- .../lib/src/inferrer/type_system.dart | 4 +- .../lib/src/types/container_type_mask.dart | 2 +- .../lib/src/types/dictionary_type_mask.dart | 9 +++- pkg/compiler/lib/src/types/map_type_mask.dart | 4 +- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/pkg/compiler/lib/src/inferrer/type_graph_nodes.dart b/pkg/compiler/lib/src/inferrer/type_graph_nodes.dart index 0301f36c9245..b07171b08dbd 100644 --- a/pkg/compiler/lib/src/inferrer/type_graph_nodes.dart +++ b/pkg/compiler/lib/src/inferrer/type_graph_nodes.dart @@ -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' @@ -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 ??= >{}; _callers.putIfAbsent(caller, () => new Setlet()).add(node); } @@ -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) { @@ -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) { @@ -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; @@ -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) { @@ -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 @@ -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) @@ -1898,20 +1896,25 @@ abstract class TypeInformationVisitor { } 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; diff --git a/pkg/compiler/lib/src/inferrer/type_system.dart b/pkg/compiler/lib/src/inferrer/type_system.dart index a7a98423f432..5779c5805d9b 100644 --- a/pkg/compiler/lib/src/inferrer/type_system.dart +++ b/pkg/compiler/lib/src/inferrer/type_system.dart @@ -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 && @@ -489,7 +489,7 @@ class TypeSystem { } TypeInformation allocateMap( - ConcreteTypeInformation type, ast.Node node, Element element, + ConcreteTypeInformation type, ast.Node node, MemberElement element, [List keyTypes, List valueTypes]) { assert(keyTypes.length == valueTypes.length); bool isFixed = (type.type == commonMasks.constMapType); diff --git a/pkg/compiler/lib/src/types/container_type_mask.dart b/pkg/compiler/lib/src/types/container_type_mask.dart index cd5697aaf00c..bbdfe1a221e5 100644 --- a/pkg/compiler/lib/src/types/container_type_mask.dart +++ b/pkg/compiler/lib/src/types/container_type_mask.dart @@ -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; diff --git a/pkg/compiler/lib/src/types/dictionary_type_mask.dart b/pkg/compiler/lib/src/types/dictionary_type_mask.dart index 0c4bd8090dcd..7784fe1a225f 100644 --- a/pkg/compiler/lib/src/types/dictionary_type_mask.dart +++ b/pkg/compiler/lib/src/types/dictionary_type_mask.dart @@ -16,8 +16,13 @@ class DictionaryTypeMask extends MapTypeMask { // The underlying key/value map of this dictionary. final Map 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() { diff --git a/pkg/compiler/lib/src/types/map_type_mask.dart b/pkg/compiler/lib/src/types/map_type_mask.dart index 4fe6a79393d8..5152b9d217b3 100644 --- a/pkg/compiler/lib/src/types/map_type_mask.dart +++ b/pkg/compiler/lib/src/types/map_type_mask.dart @@ -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;