| Index: pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart
|
| diff --git a/pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart b/pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart
|
| index cb0c6182cf1da65a81595901a158a98d1aa40259..ed1eea9ff7c4aa2d9819d36c70ffd2e1ee995a30 100644
|
| --- a/pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart
|
| +++ b/pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart
|
| @@ -12,7 +12,7 @@ import '../elements/entities.dart';
|
| import '../tree/tree.dart' as ast show Node;
|
| import '../types/masks.dart'
|
| show CommonMasks, ContainerTypeMask, MapTypeMask, TypeMask;
|
| -import '../types/types.dart' show TypesInferrer;
|
| +import '../types/types.dart';
|
| import '../universe/selector.dart' show Selector;
|
| import '../world.dart' show ClosedWorld, ClosedWorldRefiner;
|
| import 'ast_inferrer_engine.dart';
|
| @@ -50,13 +50,15 @@ class WorkQueue {
|
| int get length => queue.length;
|
| }
|
|
|
| -class TypeGraphInferrer implements TypesInferrer {
|
| - InferrerEngine inferrer;
|
| - final Compiler compiler;
|
| +abstract class TypeGraphInferrer<T> implements TypesInferrer<T> {
|
| + InferrerEngine<T> inferrer;
|
| + final bool _disableTypeInference;
|
| final ClosedWorld closedWorld;
|
| final ClosedWorldRefiner closedWorldRefiner;
|
|
|
| - TypeGraphInferrer(this.compiler, this.closedWorld, this.closedWorldRefiner);
|
| + TypeGraphInferrer(this.closedWorld, this.closedWorldRefiner,
|
| + {bool disableTypeInference: false})
|
| + : this._disableTypeInference = disableTypeInference;
|
|
|
| String get name => 'Graph inferrer';
|
|
|
| @@ -65,51 +67,52 @@ class TypeGraphInferrer implements TypesInferrer {
|
| TypeMask get _dynamicType => commonMasks.dynamicType;
|
|
|
| void analyzeMain(FunctionEntity main) {
|
| - inferrer =
|
| - new AstInferrerEngine(compiler, closedWorld, closedWorldRefiner, main);
|
| + inferrer = createInferrerEngineFor(main);
|
| inferrer.runOverAllElements();
|
| }
|
|
|
| - TypeMask getReturnTypeOfMember(MemberElement element) {
|
| - if (compiler.disableTypeInference) return _dynamicType;
|
| + InferrerEngine<T> createInferrerEngineFor(FunctionEntity main);
|
| +
|
| + TypeMask getReturnTypeOfMember(MemberEntity element) {
|
| + if (_disableTypeInference) return _dynamicType;
|
| // Currently, closure calls return dynamic.
|
| - if (element is! MethodElement) return _dynamicType;
|
| + if (element is! FunctionElement) return _dynamicType;
|
| return inferrer.types.getInferredTypeOfMember(element).type;
|
| }
|
|
|
| - TypeMask getReturnTypeOfParameter(ParameterElement element) {
|
| - if (compiler.disableTypeInference) return _dynamicType;
|
| + TypeMask getReturnTypeOfParameter(Local element) {
|
| + if (_disableTypeInference) return _dynamicType;
|
| return _dynamicType;
|
| }
|
|
|
| - TypeMask getTypeOfMember(MemberElement element) {
|
| - if (compiler.disableTypeInference) return _dynamicType;
|
| + TypeMask getTypeOfMember(MemberEntity element) {
|
| + if (_disableTypeInference) return _dynamicType;
|
| // The inferrer stores the return type for a function, so we have to
|
| // be careful to not return it here.
|
| - if (element is MethodElement) return commonMasks.functionType;
|
| + if (element is FunctionEntity) return commonMasks.functionType;
|
| return inferrer.types.getInferredTypeOfMember(element).type;
|
| }
|
|
|
| - TypeMask getTypeOfParameter(ParameterElement element) {
|
| - if (compiler.disableTypeInference) return _dynamicType;
|
| + TypeMask getTypeOfParameter(Local element) {
|
| + if (_disableTypeInference) return _dynamicType;
|
| // The inferrer stores the return type for a function, so we have to
|
| // be careful to not return it here.
|
| return inferrer.types.getInferredTypeOfParameter(element).type;
|
| }
|
|
|
| - TypeMask getTypeForNewList(ast.Node node) {
|
| - if (compiler.disableTypeInference) return _dynamicType;
|
| + TypeMask getTypeForNewList(T node) {
|
| + if (_disableTypeInference) return _dynamicType;
|
| return inferrer.types.allocatedLists[node].type;
|
| }
|
|
|
| - bool isFixedArrayCheckedForGrowable(ast.Node node) {
|
| - if (compiler.disableTypeInference) return true;
|
| + bool isFixedArrayCheckedForGrowable(T node) {
|
| + if (_disableTypeInference) return true;
|
| ListTypeInformation info = inferrer.types.allocatedLists[node];
|
| return info.checksGrowable;
|
| }
|
|
|
| TypeMask getTypeOfSelector(Selector selector, TypeMask mask) {
|
| - if (compiler.disableTypeInference) return _dynamicType;
|
| + if (_disableTypeInference) return _dynamicType;
|
| // Bailout for closure calls. We're not tracking types of
|
| // closures.
|
| if (selector.isClosureCall) return _dynamicType;
|
| @@ -137,16 +140,16 @@ class TypeGraphInferrer implements TypesInferrer {
|
| return result;
|
| }
|
|
|
| - Iterable<MemberEntity> getCallersOf(MemberElement element) {
|
| - if (compiler.disableTypeInference) {
|
| + Iterable<MemberEntity> getCallersOf(MemberEntity element) {
|
| + if (_disableTypeInference) {
|
| throw new UnsupportedError(
|
| "Cannot query the type inferrer when type inference is disabled.");
|
| }
|
| return inferrer.getCallersOf(element);
|
| }
|
|
|
| - bool isMemberCalledOnce(MemberElement element) {
|
| - if (compiler.disableTypeInference) return false;
|
| + bool isMemberCalledOnce(MemberEntity element) {
|
| + if (_disableTypeInference) return false;
|
| MemberTypeInformation info =
|
| inferrer.types.getInferredTypeOfMember(element);
|
| return info.isCalledOnce();
|
| @@ -156,3 +159,24 @@ class TypeGraphInferrer implements TypesInferrer {
|
| inferrer.clear();
|
| }
|
| }
|
| +
|
| +class AstTypeGraphInferrer extends TypeGraphInferrer<ast.Node> {
|
| + final Compiler _compiler;
|
| +
|
| + AstTypeGraphInferrer(
|
| + this._compiler, ClosedWorld closedWorld, closedWorldRefiner,
|
| + {bool disableTypeInference: false})
|
| + : super(closedWorld, closedWorldRefiner,
|
| + disableTypeInference: disableTypeInference);
|
| +
|
| + @override
|
| + InferrerEngine<ast.Node> createInferrerEngineFor(FunctionEntity main) {
|
| + return new AstInferrerEngine(
|
| + _compiler, closedWorld, closedWorldRefiner, main);
|
| + }
|
| +
|
| + @override
|
| + GlobalTypeInferenceResults createResults() {
|
| + return new AstGlobalTypeInferenceResults(this, closedWorld);
|
| + }
|
| +}
|
|
|