Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1157)

Unified Diff: pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart

Issue 2916893002: Handle int constant (Closed)
Patch Set: Updated cf. comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cedeeedb1164b843fc28e20f05a1d27c01c19575 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,11 @@
// 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_elements.dart';
import '../constants/constant_system.dart';
import '../constants/values.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 +53,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 +86,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 +103,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 +123,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 +138,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 +163,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 +175,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 +185,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 +207,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 +217,30 @@ 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;
-
- void selectGenerativeConstructors(ClassElement enclosing, Element member) {
- if (member.isGenerativeConstructor) {
+ if (_nativeData.isNativeClass(cls)) return result;
+
+ _elementEnvironment.forEachConstructor(cls,
+ (ConstructorEntity constructor) {
+ if (constructor.isGenerativeConstructor) {
+ // Ensure that parameter structure has been computed by querying the
+ // function type.
+ _elementEnvironment.getFunctionType(constructor);
// Ignore constructors that cannot be called with zero arguments.
- ConstructorElement constructor = member;
- constructor.computeType(_resolution);
- 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;
}
}

Powered by Google App Engine
This is Rietveld 408576698