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

Unified Diff: pkg/compiler/lib/src/js_emitter/program_builder.dart

Issue 882713008: Move computation of method flags into model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: use unused api Created 5 years, 11 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
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart ('k') | pkg/compiler/lib/src/use_unused_api.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/program_builder.dart
diff --git a/pkg/compiler/lib/src/js_emitter/program_builder.dart b/pkg/compiler/lib/src/js_emitter/program_builder.dart
index 4e2f55577e1f5162fdeb4978ad9e506d378751da..f7aec0e1511d3f549b15245794be4292ab4f38a4 100644
--- a/pkg/compiler/lib/src/js_emitter/program_builder.dart
+++ b/pkg/compiler/lib/src/js_emitter/program_builder.dart
@@ -266,6 +266,7 @@ class ProgramBuilder {
///
/// Returns a class that contains the fields of a class.
Class buildClassWithFieldsForTry(ClassElement element) {
+ assert(_compiler.hasIncrementalSupport);
bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element);
List<Field> instanceFields =
@@ -296,8 +297,9 @@ class ProgramBuilder {
if (Elements.isNonAbstractInstanceMember(member)) {
js.Expression code = backend.generatedCode[member];
- // TODO(kasperl): Figure out under which conditions code is null.
- if (code != null) methods.add(_buildMethod(member, code));
+ // TODO(herhut): Remove once _buildMethod can no longer return null.
+ Method method = _buildMethod(member);
+ if (method != null) methods.add(method);
}
if (member.isGetter || member.isField) {
Set<Selector> selectors =
@@ -374,10 +376,75 @@ class ProgramBuilder {
return result;
}
- Method _buildMethod(FunctionElement element, js.Expression code) {
+ bool _methodNeedsStubs(FunctionElement method) {
+ return !method.functionSignature.optionalParameters.isEmpty;
+ }
+
+ bool _methodCanBeReflected(FunctionElement method) {
+ return backend.isAccessibleByReflection(method) ||
+ // During incremental compilation, we have to assume that reflection
+ // *might* get enabled.
+ _compiler.hasIncrementalSupport;
+ }
+
+ bool _methodCanBeApplied(FunctionElement method) {
+ return _compiler.enabledFunctionApply &&
+ _compiler.world.getMightBePassedToApply(method);
+ }
+
+ // TODO(herhut): Refactor incremental compilation and remove method.
+ Method buildMethodHackForIncrementalCompilation(FunctionElement element) {
+ assert(_compiler.hasIncrementalSupport);
+ if (element.isInstanceMember) {
+ return _buildMethod(element);
+ } else {
+ return _buildStaticMethod(element);
+ }
+ }
+
+ DartMethod _buildMethod(FunctionElement element) {
String name = namer.getNameOfInstanceMember(element);
- // TODO(floitsch): compute `needsTearOff`.
- return new Method(element, name, code, needsTearOff: false);
+ js.Expression code = backend.generatedCode[element];
+
+ // TODO(kasperl): Figure out under which conditions code is null.
+ if (code == null) return null;
+
+ bool canTearOff = false;
+ String tearOffName;
+ bool isClosure = false;
+ bool isNotApplyTarget = !element.isFunction || element.isAccessor;
+
+ final bool needsStubs = _methodNeedsStubs(element);
+ final bool canBeReflected = _methodCanBeReflected(element);
+ final bool canBeApplied = _methodCanBeApplied(element);
+ final bool hasSuperAlias = backend.isAliasedSuperMember(element);
+
+ if (isNotApplyTarget) {
+ canTearOff = false;
+ } else {
+ if (element.enclosingClass.isClosure) {
+ canTearOff = false;
+ isClosure = true;
+ } else {
+ // Careful with operators.
+ canTearOff = universe.hasInvokedGetter(element, _compiler.world) ||
+ (canBeReflected && !element.isOperator);
+ assert(canTearOff ||
+ !universe.methodsNeedingSuperGetter.contains(element));
+ tearOffName = namer.getterName(element);
+ }
+ }
+
+ if (canTearOff) {
+ assert(invariant(element, !element.isGenerativeConstructor));
+ assert(invariant(element, !element.isGenerativeConstructorBody));
+ assert(invariant(element, !element.isConstructor));
+ }
+
+ return new InstanceMethod(element, name, code, needsTearOff: canTearOff,
+ tearOffName: tearOffName, isClosure: isClosure,
+ hasSuperAlias: hasSuperAlias, canBeApplied: canBeApplied,
+ canBeReflected: canBeReflected, needsStubs: needsStubs);
}
/// Builds a stub method.
@@ -386,8 +453,7 @@ class ProgramBuilder {
/// attribution.
Method _buildStubMethod(String name, js.Expression code,
{Element element}) {
- // TODO(floitsch): compute `needsTearOff`.
- return new StubMethod(name, code, needsTearOff: false, element: element);
+ return new StubMethod(name, code, element: element);
}
// The getInterceptor methods directly access the prototype of classes.
@@ -417,8 +483,7 @@ class ProgramBuilder {
return names.map((String name) {
Set<ClassElement> classes = specializedGetInterceptors[name];
js.Expression code = stubGenerator.generateGetInterceptorMethod(classes);
- // TODO(floitsch): compute `needsTearOff`.
- return new StaticStubMethod(name, holder, code, needsTearOff: false);
+ return new StaticStubMethod(name, holder, code);
});
}
@@ -478,7 +543,7 @@ class ProgramBuilder {
List<String> names = backend.oneShotInterceptors.keys.toList()..sort();
return names.map((String name) {
js.Expression code = stubGenerator.generateOneShotInterceptor(name);
- return new StaticStubMethod(name, holder, code, needsTearOff: false);
+ return new StaticStubMethod(name, holder, code);
});
}
@@ -486,12 +551,25 @@ class ProgramBuilder {
String name = namer.getNameOfMember(element);
String holder = namer.globalObjectFor(element);
js.Expression code = backend.generatedCode[element];
- bool needsTearOff =
- universe.staticFunctionsNeedingGetter.contains(element);
- // TODO(floitsch): add tear-off name: namer.getStaticClosureName(element).
+
+ final bool isNotApplyTarget = !element.isConstructor && !element.isAccessor;
+ final bool needsStubs = _methodNeedsStubs(element);
+ final bool canBeApplied = _methodCanBeApplied(element);
+ final bool canBeReflected = _methodCanBeReflected(element);
+
+ final bool needsTearOff = isNotApplyTarget && (canBeReflected ||
+ universe.staticFunctionsNeedingGetter.contains(element));
+
+ final String tearOffName =
+ needsTearOff ? namer.getStaticClosureName(element) : null;
+
return new StaticMethod(element,
name, _registry.registerHolder(holder), code,
- needsTearOff: needsTearOff);
+ needsTearOff: needsTearOff,
+ tearOffName: tearOffName,
+ canBeApplied: canBeApplied,
+ canBeReflected: canBeReflected,
+ needsStubs: needsStubs);
}
void _registerConstants(OutputUnit outputUnit,
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart ('k') | pkg/compiler/lib/src/use_unused_api.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698