Chromium Code Reviews| Index: pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart |
| diff --git a/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart b/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart |
| index 1ca595e0714c8c7f8334962e25c13aeee9cbd1ed..96ec60efaa0d0b7a9646bb6fb54b2af587d961d7 100644 |
| --- a/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart |
| +++ b/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart |
| @@ -2,13 +2,13 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| -import '../common/resolution.dart'; |
| +//import '../common/resolution.dart'; |
|
Siggi Cherem (dart-lang)
2017/06/01 22:28:43
delete (and below)
Johnni Winther
2017/06/02 11:17:24
Done.
|
| import '../common_elements.dart'; |
| import '../constants/constant_system.dart'; |
| import '../constants/values.dart'; |
| -import '../elements/elements.dart'; |
| +//import '../elements/elements.dart'; |
| import '../elements/entities.dart'; |
| -import '../elements/resolution_types.dart'; |
| +import '../elements/types.dart'; |
| import '../universe/call_structure.dart'; |
| import '../universe/use.dart' show ConstantUse, StaticUse; |
| import '../universe/world_impact.dart' |
| @@ -55,23 +55,22 @@ import 'native_data.dart'; |
| */ |
| abstract class CustomElementsAnalysisBase { |
| final NativeBasicData _nativeData; |
| - final Resolution _resolution; |
| + final ElementEnvironment _elementEnvironment; |
| final CommonElements _commonElements; |
| CustomElementsAnalysisBase( |
| - this._resolution, this._commonElements, this._nativeData); |
| + this._elementEnvironment, this._commonElements, this._nativeData); |
| CustomElementsAnalysisJoin get join; |
| - void registerInstantiatedClass(ClassElement classElement) { |
| - classElement.ensureResolved(_resolution); |
| - if (!_nativeData.isNativeOrExtendsNative(classElement)) return; |
| - if (classElement.isMixinApplication) return; |
| - if (classElement.isAbstract) return; |
| + void registerInstantiatedClass(ClassEntity cls) { |
| + if (!_nativeData.isNativeOrExtendsNative(cls)) return; |
| + if (_elementEnvironment.isUnnamedMixinApplication(cls)) return; |
| + if (cls.isAbstract) return; |
| // JsInterop classes are opaque interfaces without a concrete |
| // implementation. |
| - if (_nativeData.isJsInteropClass(classElement)) return; |
| - join.instantiatedClasses.add(classElement); |
| + if (_nativeData.isJsInteropClass(cls)) return; |
| + join.instantiatedClasses.add(cls); |
| } |
| void registerStaticUse(MemberEntity element) { |
| @@ -89,15 +88,15 @@ class CustomElementsResolutionAnalysis extends CustomElementsAnalysisBase { |
| final CustomElementsAnalysisJoin join; |
| CustomElementsResolutionAnalysis( |
| - Resolution resolution, |
| ConstantSystem constantSystem, |
| + ElementEnvironment elementEnvironment, |
| CommonElements commonElements, |
| NativeBasicData nativeData, |
| BackendUsageBuilder backendUsageBuilder) |
| : join = new CustomElementsAnalysisJoin( |
| - resolution, constantSystem, commonElements, nativeData, |
| + constantSystem, elementEnvironment, commonElements, nativeData, |
| backendUsageBuilder: backendUsageBuilder), |
| - super(resolution, commonElements, nativeData) { |
| + super(elementEnvironment, commonElements, nativeData) { |
| // TODO(sra): Remove this work-around. We should mark allClassesSelected in |
| // both joins only when we see a construct generating an unknown [Type] but |
| // we can't currently recognize all cases. In particular, the work-around |
| @@ -106,12 +105,13 @@ class CustomElementsResolutionAnalysis extends CustomElementsAnalysisBase { |
| join.allClassesSelected = true; |
| } |
| - void registerTypeLiteral(ResolutionDartType type) { |
| + void registerTypeLiteral(DartType type) { |
| if (type.isInterfaceType) { |
| // TODO(sra): If we had a flow query from the type literal expression to |
| // the Type argument of the metadata lookup, we could tell if this type |
| // literal is really a demand for the metadata. |
| - join.selectedClasses.add(type.element); |
| + InterfaceType interfaceType = type; |
| + join.selectedClasses.add(interfaceType.element); |
| } else if (type.isTypeVariable) { |
| // This is a type parameter of a parameterized class. |
| // TODO(sra): Is there a way to determine which types are bound to the |
| @@ -125,13 +125,13 @@ class CustomElementsCodegenAnalysis extends CustomElementsAnalysisBase { |
| final CustomElementsAnalysisJoin join; |
| CustomElementsCodegenAnalysis( |
| - Resolution resolution, |
| ConstantSystem constantSystem, |
| CommonElements commonElements, |
| + ElementEnvironment elementEnvironment, |
| NativeBasicData nativeData) |
| : join = new CustomElementsAnalysisJoin( |
| - resolution, constantSystem, commonElements, nativeData), |
| - super(resolution, commonElements, nativeData) { |
| + constantSystem, elementEnvironment, commonElements, nativeData), |
| + super(elementEnvironment, commonElements, nativeData) { |
| // TODO(sra): Remove this work-around. We should mark allClassesSelected in |
| // both joins only when we see a construct generating an unknown [Type] but |
| // we can't currently recognize all cases. In particular, the work-around |
| @@ -140,23 +140,21 @@ class CustomElementsCodegenAnalysis extends CustomElementsAnalysisBase { |
| join.allClassesSelected = true; |
| } |
| - void registerTypeConstant(ClassElement element) { |
| - assert(element.isClass); |
| - join.selectedClasses.add(element); |
| + void registerTypeConstant(ClassEntity cls) { |
| + join.selectedClasses.add(cls); |
| } |
| bool get needsTable => join.demanded; |
| - bool needsClass(ClassElement classElement) => |
| - join.activeClasses.contains(classElement); |
| + bool needsClass(ClassEntity cls) => join.activeClasses.contains(cls); |
| - List<ConstructorElement> constructors(ClassElement classElement) => |
| - join.computeEscapingConstructors(classElement); |
| + List<ConstructorEntity> constructors(ClassEntity cls) => |
| + join.computeEscapingConstructors(cls); |
| } |
| class CustomElementsAnalysisJoin { |
| - final Resolution _resolution; |
| final ConstantSystem _constantSystem; |
| + final ElementEnvironment _elementEnvironment; |
| final CommonElements _commonElements; |
| final NativeBasicData _nativeData; |
| final BackendUsageBuilder _backendUsageBuilder; |
| @@ -167,10 +165,10 @@ class CustomElementsAnalysisJoin { |
| // Classes that are candidates for needing constructors. Classes are moved to |
| // [activeClasses] when we know they need constructors. |
| - final instantiatedClasses = new Set<ClassElement>(); |
| + final Set<ClassEntity> instantiatedClasses = new Set<ClassEntity>(); |
| // Classes explicitly named. |
| - final selectedClasses = new Set<ClassElement>(); |
| + final Set<ClassEntity> selectedClasses = new Set<ClassEntity>(); |
| // True if we must conservatively include all extension classes. |
| bool allClassesSelected = false; |
| @@ -179,9 +177,9 @@ class CustomElementsAnalysisJoin { |
| bool demanded = false; |
| // ClassesOutput: classes requiring metadata. |
| - final activeClasses = new Set<ClassElement>(); |
| + final Set<ClassEntity> activeClasses = new Set<ClassEntity>(); |
| - CustomElementsAnalysisJoin(this._resolution, this._constantSystem, |
| + CustomElementsAnalysisJoin(this._constantSystem, this._elementEnvironment, |
| this._commonElements, this._nativeData, |
| {BackendUsageBuilder backendUsageBuilder}) |
| : this._backendUsageBuilder = backendUsageBuilder, |
| @@ -189,20 +187,19 @@ class CustomElementsAnalysisJoin { |
| WorldImpact flush() { |
| if (!demanded) return const WorldImpact(); |
| - var newActiveClasses = new Set<ClassElement>(); |
| - for (ClassElement classElement in instantiatedClasses) { |
| - bool isNative = _nativeData.isNativeClass(classElement); |
| - bool isExtension = |
| - !isNative && _nativeData.isNativeOrExtendsNative(classElement); |
| + var newActiveClasses = new Set<ClassEntity>(); |
| + for (ClassEntity cls in instantiatedClasses) { |
| + bool isNative = _nativeData.isNativeClass(cls); |
| + bool isExtension = !isNative && _nativeData.isNativeOrExtendsNative(cls); |
| // Generate table entries for native classes that are explicitly named and |
| // extensions that fix our criteria. |
| - if ((isNative && selectedClasses.contains(classElement)) || |
| + if ((isNative && selectedClasses.contains(cls)) || |
| (isExtension && |
| - (allClassesSelected || selectedClasses.contains(classElement)))) { |
| - newActiveClasses.add(classElement); |
| - Iterable<ConstructorElement> escapingConstructors = |
| - computeEscapingConstructors(classElement); |
| - for (ConstructorElement constructor in escapingConstructors) { |
| + (allClassesSelected || selectedClasses.contains(cls)))) { |
| + newActiveClasses.add(cls); |
| + Iterable<ConstructorEntity> escapingConstructors = |
| + computeEscapingConstructors(cls); |
| + for (ConstructorEntity constructor in escapingConstructors) { |
| impactBuilder.registerStaticUse(new StaticUse.constructorInvoke( |
| constructor, CallStructure.NO_ARGS)); |
| } |
| @@ -212,7 +209,7 @@ class CustomElementsAnalysisJoin { |
| } |
| // Force the generaton of the type constant that is the key to an entry |
| // in the generated table. |
| - ConstantValue constant = _makeTypeConstant(classElement); |
| + ConstantValue constant = _makeTypeConstant(cls); |
| impactBuilder |
| .registerConstantUse(new ConstantUse.customElements(constant)); |
| } |
| @@ -222,33 +219,27 @@ class CustomElementsAnalysisJoin { |
| return impactBuilder.flush(); |
| } |
| - TypeConstantValue _makeTypeConstant(ClassElement element) { |
| - ResolutionDartType elementType = element.rawType; |
| - return _constantSystem.createType(_commonElements, elementType); |
| + TypeConstantValue _makeTypeConstant(ClassEntity cls) { |
| + DartType type = _elementEnvironment.getRawType(cls); |
| + return _constantSystem.createType(_commonElements, type); |
| } |
| - List<ConstructorElement> computeEscapingConstructors( |
| - ClassElement classElement) { |
| - List<ConstructorElement> result = <ConstructorElement>[]; |
| + List<ConstructorEntity> computeEscapingConstructors(ClassEntity cls) { |
| + List<ConstructorEntity> result = <ConstructorEntity>[]; |
| // Only classes that extend native classes have constructors in the table. |
| // We could refine this to classes that extend Element, but that would break |
| // the tests and there is no sane reason to subclass other native classes. |
| - if (_nativeData.isNativeClass(classElement)) return result; |
| + if (_nativeData.isNativeClass(cls)) return result; |
| - void selectGenerativeConstructors(ClassElement enclosing, Element member) { |
| - if (member.isGenerativeConstructor) { |
| + _elementEnvironment.forEachConstructor(cls, |
| + (ConstructorEntity constructor) { |
| + if (constructor.isGenerativeConstructor) { |
| // Ignore constructors that cannot be called with zero arguments. |
| - ConstructorElement constructor = member; |
| - constructor.computeType(_resolution); |
|
Siggi Cherem (dart-lang)
2017/06/01 22:28:43
is computeType not needed anymore?
Johnni Winther
2017/06/02 11:17:24
Good call, it might.
|
| - FunctionSignature parameters = constructor.functionSignature; |
| - if (parameters.requiredParameterCount == 0) { |
| - result.add(member); |
| + if (constructor.parameterStructure.requiredParameters == 0) { |
| + result.add(constructor); |
| } |
| } |
| - } |
| - |
| - classElement.forEachMember(selectGenerativeConstructors, |
| - includeBackendMembers: false, includeSuperAndInjectedMembers: false); |
| + }); |
| return result; |
| } |
| } |