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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart

Issue 102833009: Redo "Dummy receiver optimization" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
index 9151b71b64d9c5716c39bb68541acdd54f0cf6f0..6ec876a3ebc3a8beb2e32e02c022c8247aef544d 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
@@ -164,11 +164,17 @@ class JavaScriptBackend extends Backend {
* know whether a send must be intercepted or not.
*/
final Map<String, Set<Element>> interceptedElements;
- // TODO(sra): Not all methods in the Set always require an interceptor. A
- // method may be mixed into a true interceptor *and* a plain class. For the
- // method to work on the interceptor class it needs to use the explicit
- // receiver. This constrains the call on a known plain receiver to pass the
- // explicit receiver. https://code.google.com/p/dart/issues/detail?id=8942
+
+ /**
+ * The members of mixin classes that are mixed into an instantiated
+ * interceptor class. This is a cached subset of [interceptedElements].
+ * These members must be invoked with a correct explicit receiver even when
+ * the receiver is not an intercepted class because the function uses the
+ * explicit interceptor parameter since it may be called on an intercepted
+ * class.
+ */
+ final Map<String, Set<Element>> interceptedMixinElements =
+ new Map<String, Set<Element>>();
/**
* A map of specialized versions of the [getInterceptorMethod].
@@ -367,6 +373,29 @@ class JavaScriptBackend extends Backend {
return interceptedElements[selector.name] != null;
}
+ /**
+ * Returns `true` iff [selector] matches an element defined in a class mixed
+ * into an intercepted class. These selectors are not eligible for the 'dummy
+ * explicit receiver' optimization.
+ */
+ bool isInterceptedMixinSelector(Selector selector) {
+ Set<Element> elements = interceptedMixinElements.putIfAbsent(
+ selector.name,
+ () {
+ Set<Element> elements = interceptedElements[selector.name];
+ if (elements == null) return null;
+ return elements
+ .where((element) =>
+ classesMixedIntoNativeClasses.contains(
+ element.getEnclosingClass()))
+ .toSet();
+ });
+
+ if (elements == null) return false;
+ if (elements.isEmpty) return false;
+ return elements.any((element) => selector.applies(element, compiler));
+ }
+
final Map<String, Set<ClassElement>> interceptedClassesCache =
new Map<String, Set<ClassElement>>();
@@ -1853,6 +1882,8 @@ class ConstantCopier implements ConstantVisitor {
void visitInterceptor(InterceptorConstant constant) => copy(constant);
+ void visitDummyReceiver(DummyReceiverConstant constant) => copy(constant);
+
void visitList(ListConstant constant) {
copy(constant.entries);
copy(constant);

Powered by Google App Engine
This is Rietveld 408576698