Index: pkg/compiler/lib/src/universe/codegen_world_builder.dart |
diff --git a/pkg/compiler/lib/src/universe/codegen_world_builder.dart b/pkg/compiler/lib/src/universe/codegen_world_builder.dart |
index 05bcca7e314b7879357f48941c20e3572a5fe596..c135e726d8d9370123c8e60255f980831f032c15 100644 |
--- a/pkg/compiler/lib/src/universe/codegen_world_builder.dart |
+++ b/pkg/compiler/lib/src/universe/codegen_world_builder.dart |
@@ -28,9 +28,9 @@ abstract class CodegenWorldBuilder implements WorldBuilder { |
f(String name, Map<Selector, SelectorConstraints> selectors)); |
/// Returns `true` if [member] is invoked as a setter. |
- bool hasInvokedSetter(Element member, ClosedWorld world); |
+ bool hasInvokedSetter(MemberEntity member, ClosedWorld world); |
- bool hasInvokedGetter(Element member, ClosedWorld world); |
+ bool hasInvokedGetter(MemberEntity member, ClosedWorld world); |
Map<Selector, SelectorConstraints> invocationsByName(String name); |
@@ -50,10 +50,10 @@ abstract class CodegenWorldBuilder implements WorldBuilder { |
Iterable<FunctionEntity> get closurizedMembers; |
} |
-class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
- final NativeBasicData _nativeData; |
+abstract class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
+ final ElementEnvironment _elementEnvironment; |
+ final NativeBasicData _nativeBasicData; |
final ClosedWorld _world; |
- final JavaScriptConstantCompiler _constants; |
/// The set of all directly instantiated classes, that is, classes with a |
/// generative constructor that has been called directly and not only through |
@@ -62,8 +62,7 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
/// Invariant: Elements are declaration elements. |
// TODO(johnniwinther): [_directlyInstantiatedClasses] and |
// [_instantiatedTypes] sets should be merged. |
- final Set<ClassElement> _directlyInstantiatedClasses = |
- new Set<ClassElement>(); |
+ final Set<ClassEntity> _directlyInstantiatedClasses = new Set<ClassEntity>(); |
/// The set of all directly instantiated types, that is, the types of the |
/// directly instantiated classes. |
@@ -72,12 +71,12 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
final Set<InterfaceType> _instantiatedTypes = new Set<InterfaceType>(); |
/// Classes implemented by directly instantiated classes. |
- final Set<ClassElement> _implementedClasses = new Set<ClassElement>(); |
+ final Set<ClassEntity> _implementedClasses = new Set<ClassEntity>(); |
/// The set of all referenced static fields. |
/// |
/// Invariant: Elements are declaration elements. |
- final Set<FieldElement> allReferencedStaticFields = new Set<FieldElement>(); |
+ final Set<FieldEntity> allReferencedStaticFields = new Set<FieldEntity>(); |
/** |
* Documentation wanted -- johnniwinther |
@@ -95,8 +94,8 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
final Map<String, Map<Selector, SelectorConstraints>> _invokedSetters = |
<String, Map<Selector, SelectorConstraints>>{}; |
- final Map<ClassElement, _ClassUsage> _processedClasses = |
- <ClassElement, _ClassUsage>{}; |
+ final Map<ClassEntity, _ClassUsage> _processedClasses = |
+ <ClassEntity, _ClassUsage>{}; |
/// Map of registered usage of static members of live classes. |
final Map<Entity, _StaticMemberUsage> _staticMemberUsage = |
@@ -116,7 +115,7 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = |
<String, Set<_MemberUsage>>{}; |
- final Set<ResolutionDartType> isChecks = new Set<ResolutionDartType>(); |
+ final Set<DartType> isChecks = new Set<DartType>(); |
final SelectorConstraintsStrategy selectorConstraintsStrategy; |
@@ -125,34 +124,17 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
/// Set of methods in instantiated classes that are potentially closurized. |
final Set<FunctionEntity> closurizedMembers = new Set<FunctionEntity>(); |
- CodegenWorldBuilderImpl(this._nativeData, this._world, this._constants, |
- this.selectorConstraintsStrategy); |
- |
- /// Calls [f] with every instance field, together with its declarer, in an |
- /// instance of [cls]. |
- void forEachInstanceField( |
- ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) { |
- cls.implementation |
- .forEachInstanceField(f, includeSuperAndInjectedMembers: true); |
- } |
+ CodegenWorldBuilderImpl(this._elementEnvironment, this._nativeBasicData, |
+ this._world, this.selectorConstraintsStrategy); |
- @override |
- void forEachParameter( |
- MethodElement function, void f(DartType type, String name)) { |
- FunctionSignature parameters = function.functionSignature; |
- parameters.forEachParameter((ParameterElement parameter) { |
- f(parameter.type, parameter.name); |
- }); |
- } |
- |
- Iterable<ClassElement> get processedClasses => _processedClasses.keys |
+ Iterable<ClassEntity> get processedClasses => _processedClasses.keys |
.where((cls) => _processedClasses[cls].isInstantiated); |
/// All directly instantiated classes, that is, classes with a generative |
/// constructor that has been called directly and not only through a |
/// super-call. |
// TODO(johnniwinther): Improve semantic precision. |
- Iterable<ClassElement> get directlyInstantiatedClasses { |
+ Iterable<ClassEntity> get directlyInstantiatedClasses { |
return _directlyInstantiatedClasses; |
} |
@@ -170,10 +152,10 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
// subclass and through subtype instantiated types/classes. |
// TODO(johnniwinther): Support unknown type arguments for generic types. |
void registerTypeInstantiation( |
- ResolutionInterfaceType type, ClassUsedCallback classUsed, |
+ InterfaceType type, ClassUsedCallback classUsed, |
{bool byMirrors: false}) { |
- ClassElement cls = type.element; |
- bool isNative = _nativeData.isNativeClass(cls); |
+ ClassEntity cls = type.element; |
+ bool isNative = _nativeBasicData.isNativeClass(cls); |
_instantiatedTypes.add(type); |
if (!cls.isAbstract |
// We can't use the closed-world assumption with native abstract |
@@ -195,7 +177,7 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
// include the type arguments. |
if (_implementedClasses.add(cls)) { |
classUsed(cls, _getClassUsage(cls).implement()); |
- cls.allSupertypes.forEach((ResolutionInterfaceType supertype) { |
+ _elementEnvironment.forEachSupertype(cls, (InterfaceType supertype) { |
if (_implementedClasses.add(supertype.element)) { |
classUsed( |
supertype.element, _getClassUsage(supertype.element).implement()); |
@@ -205,7 +187,7 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
} |
bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors, |
- MemberElement member, ClosedWorld world) { |
+ MemberEntity member, ClosedWorld world) { |
if (selectors == null) return false; |
for (Selector selector in selectors.keys) { |
if (selector.appliesUnnamed(member)) { |
@@ -218,16 +200,16 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
return false; |
} |
- bool hasInvocation(Element member, ClosedWorld world) { |
+ bool hasInvocation(MemberEntity member, ClosedWorld world) { |
return _hasMatchingSelector(_invokedNames[member.name], member, world); |
} |
- bool hasInvokedGetter(Element member, ClosedWorld world) { |
+ bool hasInvokedGetter(MemberEntity member, ClosedWorld world) { |
return _hasMatchingSelector(_invokedGetters[member.name], member, world) || |
member.isFunction && methodsNeedingSuperGetter.contains(member); |
} |
- bool hasInvokedSetter(Element member, ClosedWorld world) { |
+ bool hasInvokedSetter(MemberEntity member, ClosedWorld world) { |
return _hasMatchingSelector(_invokedSetters[member.name], member, world); |
} |
@@ -318,28 +300,23 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
_invokedSetters.forEach(f); |
} |
- void registerIsCheck(ResolutionDartType type) { |
- type = type.unaliased; |
- // Even in checked mode, type annotations for return type and argument |
- // types do not imply type checks, so there should never be a check |
- // against the type variable of a typedef. |
- assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef); |
- isChecks.add(type); |
+ void registerIsCheck(DartType type) { |
+ isChecks.add(type.unaliased); |
} |
void _registerStaticUse(StaticUse staticUse) { |
- Element element = staticUse.element; |
- if (Elements.isStaticOrTopLevel(element) && element.isField) { |
- allReferencedStaticFields.add(element); |
+ if (staticUse.element is FieldEntity) { |
+ FieldEntity field = staticUse.element; |
+ if (field.isTopLevel || field.isStatic) { |
+ allReferencedStaticFields.add(field); |
+ } |
} |
switch (staticUse.kind) { |
case StaticUseKind.STATIC_TEAR_OFF: |
- MethodElement method = element; |
- staticFunctionsNeedingGetter.add(method); |
+ staticFunctionsNeedingGetter.add(staticUse.element); |
break; |
case StaticUseKind.SUPER_TEAR_OFF: |
- MethodElement method = element; |
- methodsNeedingSuperGetter.add(method); |
+ methodsNeedingSuperGetter.add(staticUse.element); |
break; |
case StaticUseKind.SUPER_FIELD_SET: |
case StaticUseKind.FIELD_SET: |
@@ -357,12 +334,12 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
} |
void registerStaticUse(StaticUse staticUse, MemberUsedCallback memberUsed) { |
- Element element = staticUse.element; |
- assert(invariant(element, element.isDeclaration, |
- message: "Element ${element} is not the declaration.")); |
+ Entity element = staticUse.element; |
_registerStaticUse(staticUse); |
_StaticMemberUsage usage = _staticMemberUsage.putIfAbsent(element, () { |
- if ((element.isStatic || element.isTopLevel) && element.isFunction) { |
+ if (element is MemberEntity && |
+ (element.isStatic || element.isTopLevel) && |
+ element.isFunction) { |
return new _StaticFunctionUsage(element); |
} else { |
return new _GeneralStaticMemberUsage(element); |
@@ -413,22 +390,25 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
closurizedMembers.add(element); |
} |
- void processClassMembers(ClassElement cls, MemberUsedCallback memberUsed) { |
- cls.implementation.forEachMember((_, MemberElement member) { |
- assert(invariant(member, member.isDeclaration)); |
- if (!member.isInstanceMember) return; |
- if (member.isMalformed) return; |
- _getMemberUsage(member, memberUsed); |
+ void processClassMembers(ClassEntity cls, MemberUsedCallback memberUsed) { |
+ _elementEnvironment.forEachClassMember(cls, |
+ (ClassEntity cls, MemberEntity member) { |
+ _processInstantiatedClassMember(cls, member, memberUsed); |
}); |
} |
+ void _processInstantiatedClassMember( |
+ ClassEntity cls, MemberEntity member, MemberUsedCallback memberUsed) { |
+ if (!member.isInstanceMember) return; |
+ _getMemberUsage(member, memberUsed); |
+ } |
+ |
_MemberUsage _getMemberUsage( |
- MemberElement member, MemberUsedCallback memberUsed) { |
- assert(invariant(member, member.isDeclaration)); |
+ MemberEntity member, MemberUsedCallback memberUsed) { |
return _instanceMemberUsage.putIfAbsent(member, () { |
String memberName = member.name; |
- ClassElement cls = member.enclosingClass; |
- bool isNative = _nativeData.isNativeClass(cls); |
+ ClassEntity cls = member.enclosingClass; |
+ bool isNative = _nativeBasicData.isNativeClass(cls); |
_MemberUsage usage = new _MemberUsage(member, isNative: isNative); |
EnumSet<MemberUse> useSet = new EnumSet<MemberUse>(); |
useSet.addAll(usage.appliedUse); |
@@ -477,16 +457,15 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
} |
/// Return the canonical [_ClassUsage] for [cls]. |
- _ClassUsage _getClassUsage(ClassElement cls) { |
+ _ClassUsage _getClassUsage(ClassEntity cls) { |
return _processedClasses.putIfAbsent(cls, () => new _ClassUsage(cls)); |
} |
- void _processInstantiatedClass( |
- ClassElement cls, ClassUsedCallback classUsed) { |
+ void _processInstantiatedClass(ClassEntity cls, ClassUsedCallback classUsed) { |
// Registers [superclass] as instantiated. Returns `true` if it wasn't |
// already instantiated and we therefore have to process its superclass as |
// well. |
- bool processClass(ClassElement superclass) { |
+ bool processClass(ClassEntity superclass) { |
_ClassUsage usage = _getClassUsage(superclass); |
if (!usage.isInstantiated) { |
classUsed(usage.cls, usage.instantiate()); |
@@ -496,16 +475,108 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
} |
while (cls != null && processClass(cls)) { |
- cls = cls.superclass; |
+ cls = _elementEnvironment.getSuperClass(cls); |
} |
} |
+ bool registerConstantUse(ConstantUse use); |
+} |
+ |
+class ElementCodegenWorldBuilderImpl extends CodegenWorldBuilderImpl { |
+ final JavaScriptConstantCompiler _constants; |
+ |
+ ElementCodegenWorldBuilderImpl( |
+ ElementEnvironment elementEnvironment, |
+ NativeBasicData nativeBasicData, |
+ ClosedWorld world, |
+ this._constants, |
+ SelectorConstraintsStrategy selectorConstraintsStrategy) |
+ : super(elementEnvironment, nativeBasicData, world, |
+ selectorConstraintsStrategy); |
+ |
+ /// Calls [f] with every instance field, together with its declarer, in an |
+ /// instance of [cls]. |
+ void forEachInstanceField( |
+ ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) { |
+ cls.implementation |
+ .forEachInstanceField(f, includeSuperAndInjectedMembers: true); |
+ } |
+ |
+ @override |
+ void forEachParameter( |
+ MethodElement function, void f(DartType type, String name)) { |
+ FunctionSignature parameters = function.functionSignature; |
+ parameters.forEachParameter((ParameterElement parameter) { |
+ f(parameter.type, parameter.name); |
+ }); |
+ } |
+ |
+ @override |
+ void _processInstantiatedClassMember( |
+ ClassEntity cls, MemberElement member, MemberUsedCallback memberUsed) { |
+ assert(invariant(member, member.isDeclaration)); |
+ if (member.isMalformed) return; |
+ super._processInstantiatedClassMember(cls, member, memberUsed); |
+ } |
+ |
+ @override |
+ _MemberUsage _getMemberUsage( |
+ MemberElement member, MemberUsedCallback memberUsed) { |
+ assert(invariant(member, member.isDeclaration)); |
+ return super._getMemberUsage(member, memberUsed); |
+ } |
+ |
+ void registerStaticUse(StaticUse staticUse, MemberUsedCallback memberUsed) { |
+ Element element = staticUse.element; |
+ assert(invariant(element, element.isDeclaration, |
+ message: "Element ${element} is not the declaration.")); |
+ super.registerStaticUse(staticUse, memberUsed); |
+ } |
+ |
/// Register the constant [use] with this world builder. Returns `true` if |
/// the constant use was new to the world. |
+ @override |
bool registerConstantUse(ConstantUse use) { |
if (use.kind == ConstantUseKind.DIRECT) { |
_constants.addCompileTimeConstantForEmission(use.value); |
} |
return _constantValues.add(use.value); |
} |
+ |
+ void registerIsCheck(ResolutionDartType type) { |
+ // Even in checked mode, type annotations for return type and argument |
+ // types do not imply type checks, so there should never be a check |
+ // against the type variable of a typedef. |
+ assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef); |
+ super.registerIsCheck(type); |
+ } |
+} |
+ |
+class KernelCodegenWorldBuilder extends CodegenWorldBuilderImpl { |
+ KernelCodegenWorldBuilder( |
+ ElementEnvironment elementEnvironment, |
+ NativeBasicData nativeBasicData, |
+ ClosedWorld world, |
+ SelectorConstraintsStrategy selectorConstraintsStrategy) |
+ : super(elementEnvironment, nativeBasicData, world, |
+ selectorConstraintsStrategy); |
+ |
+ @override |
+ bool registerConstantUse(ConstantUse use) { |
+ throw new UnimplementedError( |
+ 'KernelCodegenWorldBuilder.registerConstantUse'); |
+ } |
+ |
+ @override |
+ void forEachParameter( |
+ FunctionEntity function, void f(DartType type, String name)) { |
+ throw new UnimplementedError('KernelCodegenWorldBuilder.forEachParameter'); |
+ } |
+ |
+ @override |
+ void forEachInstanceField( |
+ ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)) { |
+ throw new UnimplementedError( |
+ 'KernelCodegenWorldBuilder.forEachInstanceField'); |
+ } |
} |