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 377b470171758ba408a636c7d28eae9dd66b94b5..bf90c24439dc79fa222bd9b96e3c9fe8636ff8aa 100644 |
--- a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart |
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart |
@@ -56,6 +56,8 @@ class JavaScriptBackend extends Backend { |
static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); |
static final Uri DART_INTERCEPTORS = |
new Uri(scheme: 'dart', path: '_interceptors'); |
+ static final Uri DART_INTERNAL = |
+ new Uri(scheme: 'dart', path: '_internal'); |
static final Uri DART_FOREIGN_HELPER = |
new Uri(scheme: 'dart', path: '_foreign_helper'); |
static final Uri DART_JS_MIRRORS = |
@@ -70,6 +72,25 @@ class JavaScriptBackend extends Backend { |
static const String INVOKE_ON = '_getCachedInvocation'; |
static const String START_ROOT_ISOLATE = 'startRootIsolate'; |
+ |
+ /// The list of functions for classes in the [internalLibrary] that we want |
+ /// to inline always. Any function in this list must be inlinable with |
+ /// respect to the conditions used in [InlineWeeder.canInline], except for |
+ /// size/complexity heuristics. |
+ static const Map<String, List<String>> ALWAYS_INLINE = |
+ const <String, List<String>> { |
+ 'IterableMixinWorkaround': const <String>['forEach'], |
+ 'ListIterator': const <String>['moveNext'] |
+ }; |
+ |
+ /// List if [FunctionElement]s that we want to inline always. This list is |
Johnni Winther
2014/09/04 07:33:40
'List if' -> 'List of'.
karlklose
2014/09/04 07:54:04
Done.
|
+ /// filled when resolution is complete by looking up in [internalLibrary]. |
+ List<FunctionElement> functionsToAlwaysInline; |
+ |
+ /// Reference to the internal library to lookup functions to always inline. |
+ LibraryElement internalLibrary; |
+ |
+ |
/// Set of classes that need to be considered for reflection although not |
/// otherwise visible during resolution. |
Iterable<ClassElement> get classesRequiredForReflection { |
@@ -885,6 +906,26 @@ class JavaScriptBackend extends Backend { |
super.onResolutionComplete(); |
computeMembersNeededForReflection(); |
rti.computeClassesNeedingRti(); |
+ computeFunctionsToAlwaysInline(); |
+ } |
+ |
+ void computeFunctionsToAlwaysInline() { |
+ functionsToAlwaysInline = <FunctionElement>[]; |
+ if (internalLibrary == null) return; |
+ |
+ // Try to find all functions intended to always inline. If their enclosing |
+ // class is not resolved we skip the methods, but it is an error to mention |
+ // a function or class that cannot be found. |
+ for (String className in ALWAYS_INLINE.keys) { |
+ ClassElement cls = find(internalLibrary, className); |
+ if (cls.resolutionState != STATE_DONE) continue; |
+ for (String functionName in ALWAYS_INLINE[className]) { |
+ Element function = cls.lookupMember(functionName); |
+ assert(invariant(cls, function is FunctionElement, |
+ message: 'unable to find function $functionName in $className')); |
+ functionsToAlwaysInline.add(function); |
+ } |
+ } |
} |
void registerGetRuntimeTypeArgument(Registry registry) { |
@@ -1656,6 +1697,8 @@ class JavaScriptBackend extends Backend { |
jsIndexableClass = findClass('JSIndexable'); |
jsMutableIndexableClass = findClass('JSMutableIndexable'); |
+ } else if (uri == DART_INTERNAL) { |
+ internalLibrary = library; |
Johnni Winther
2014/09/04 07:33:40
Put this in [onLibraryCreated] instead.
karlklose
2014/09/04 07:54:04
Done.
|
} else if (uri == DART_JS_HELPER) { |
initializeHelperClasses(); |
assertMethod = findHelper('assertHelper'); |