OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 } else { | 49 } else { |
50 canBeInlined[element] = false; | 50 canBeInlined[element] = false; |
51 } | 51 } |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 class JavaScriptBackend extends Backend { | 55 class JavaScriptBackend extends Backend { |
56 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); | 56 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); |
57 static final Uri DART_INTERCEPTORS = | 57 static final Uri DART_INTERCEPTORS = |
58 new Uri(scheme: 'dart', path: '_interceptors'); | 58 new Uri(scheme: 'dart', path: '_interceptors'); |
59 static final Uri DART_INTERNAL = | |
60 new Uri(scheme: 'dart', path: '_internal'); | |
59 static final Uri DART_FOREIGN_HELPER = | 61 static final Uri DART_FOREIGN_HELPER = |
60 new Uri(scheme: 'dart', path: '_foreign_helper'); | 62 new Uri(scheme: 'dart', path: '_foreign_helper'); |
61 static final Uri DART_JS_MIRRORS = | 63 static final Uri DART_JS_MIRRORS = |
62 new Uri(scheme: 'dart', path: '_js_mirrors'); | 64 new Uri(scheme: 'dart', path: '_js_mirrors'); |
63 static final Uri DART_JS_NAMES = | 65 static final Uri DART_JS_NAMES = |
64 new Uri(scheme: 'dart', path: '_js_names'); | 66 new Uri(scheme: 'dart', path: '_js_names'); |
65 static final Uri DART_ISOLATE_HELPER = | 67 static final Uri DART_ISOLATE_HELPER = |
66 new Uri(scheme: 'dart', path: '_isolate_helper'); | 68 new Uri(scheme: 'dart', path: '_isolate_helper'); |
67 static final Uri DART_HTML = | 69 static final Uri DART_HTML = |
68 new Uri(scheme: 'dart', path: 'html'); | 70 new Uri(scheme: 'dart', path: 'html'); |
69 | 71 |
70 static const String INVOKE_ON = '_getCachedInvocation'; | 72 static const String INVOKE_ON = '_getCachedInvocation'; |
71 static const String START_ROOT_ISOLATE = 'startRootIsolate'; | 73 static const String START_ROOT_ISOLATE = 'startRootIsolate'; |
72 | 74 |
75 | |
76 /// The list of functions for classes in the [internalLibrary] that we want | |
77 /// to inline always. Any function in this list must be inlinable with | |
78 /// respect to the conditions used in [InlineWeeder.canInline], except for | |
79 /// size/complexity heuristics. | |
80 static const Map<String, List<String>> ALWAYS_INLINE = | |
81 const <String, List<String>> { | |
82 'IterableMixinWorkaround': const <String>['forEach'], | |
83 'ListIterator': const <String>['moveNext'] | |
84 }; | |
85 | |
86 /// 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.
| |
87 /// filled when resolution is complete by looking up in [internalLibrary]. | |
88 List<FunctionElement> functionsToAlwaysInline; | |
89 | |
90 /// Reference to the internal library to lookup functions to always inline. | |
91 LibraryElement internalLibrary; | |
92 | |
93 | |
73 /// Set of classes that need to be considered for reflection although not | 94 /// Set of classes that need to be considered for reflection although not |
74 /// otherwise visible during resolution. | 95 /// otherwise visible during resolution. |
75 Iterable<ClassElement> get classesRequiredForReflection { | 96 Iterable<ClassElement> get classesRequiredForReflection { |
76 // TODO(herhut): Clean this up when classes needed for rti are tracked. | 97 // TODO(herhut): Clean this up when classes needed for rti are tracked. |
77 return [closureClass, jsIndexableClass]; | 98 return [closureClass, jsIndexableClass]; |
78 } | 99 } |
79 | 100 |
80 SsaBuilderTask builder; | 101 SsaBuilderTask builder; |
81 SsaOptimizerTask optimizer; | 102 SsaOptimizerTask optimizer; |
82 SsaCodeGeneratorTask generator; | 103 SsaCodeGeneratorTask generator; |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
878 assert(traceHelper != null); | 899 assert(traceHelper != null); |
879 enqueueInResolution(traceHelper, registry); | 900 enqueueInResolution(traceHelper, registry); |
880 } | 901 } |
881 registerCheckedModeHelpers(registry); | 902 registerCheckedModeHelpers(registry); |
882 } | 903 } |
883 | 904 |
884 onResolutionComplete() { | 905 onResolutionComplete() { |
885 super.onResolutionComplete(); | 906 super.onResolutionComplete(); |
886 computeMembersNeededForReflection(); | 907 computeMembersNeededForReflection(); |
887 rti.computeClassesNeedingRti(); | 908 rti.computeClassesNeedingRti(); |
909 computeFunctionsToAlwaysInline(); | |
910 } | |
911 | |
912 void computeFunctionsToAlwaysInline() { | |
913 functionsToAlwaysInline = <FunctionElement>[]; | |
914 if (internalLibrary == null) return; | |
915 | |
916 // Try to find all functions intended to always inline. If their enclosing | |
917 // class is not resolved we skip the methods, but it is an error to mention | |
918 // a function or class that cannot be found. | |
919 for (String className in ALWAYS_INLINE.keys) { | |
920 ClassElement cls = find(internalLibrary, className); | |
921 if (cls.resolutionState != STATE_DONE) continue; | |
922 for (String functionName in ALWAYS_INLINE[className]) { | |
923 Element function = cls.lookupMember(functionName); | |
924 assert(invariant(cls, function is FunctionElement, | |
925 message: 'unable to find function $functionName in $className')); | |
926 functionsToAlwaysInline.add(function); | |
927 } | |
928 } | |
888 } | 929 } |
889 | 930 |
890 void registerGetRuntimeTypeArgument(Registry registry) { | 931 void registerGetRuntimeTypeArgument(Registry registry) { |
891 enqueueInResolution(getGetRuntimeTypeArgument(), registry); | 932 enqueueInResolution(getGetRuntimeTypeArgument(), registry); |
892 enqueueInResolution(getGetTypeArgumentByIndex(), registry); | 933 enqueueInResolution(getGetTypeArgumentByIndex(), registry); |
893 enqueueInResolution(getCopyTypeArguments(), registry); | 934 enqueueInResolution(getCopyTypeArguments(), registry); |
894 } | 935 } |
895 | 936 |
896 void registerCallMethodWithFreeTypeVariables( | 937 void registerCallMethodWithFreeTypeVariables( |
897 Element callMethod, | 938 Element callMethod, |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1649 jsBoolClass = findClass('JSBool'), | 1690 jsBoolClass = findClass('JSBool'), |
1650 jsMutableArrayClass = findClass('JSMutableArray'), | 1691 jsMutableArrayClass = findClass('JSMutableArray'), |
1651 jsFixedArrayClass = findClass('JSFixedArray'), | 1692 jsFixedArrayClass = findClass('JSFixedArray'), |
1652 jsExtendableArrayClass = findClass('JSExtendableArray'), | 1693 jsExtendableArrayClass = findClass('JSExtendableArray'), |
1653 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'), | 1694 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'), |
1654 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'), | 1695 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'), |
1655 ]; | 1696 ]; |
1656 | 1697 |
1657 jsIndexableClass = findClass('JSIndexable'); | 1698 jsIndexableClass = findClass('JSIndexable'); |
1658 jsMutableIndexableClass = findClass('JSMutableIndexable'); | 1699 jsMutableIndexableClass = findClass('JSMutableIndexable'); |
1700 } else if (uri == DART_INTERNAL) { | |
1701 internalLibrary = library; | |
Johnni Winther
2014/09/04 07:33:40
Put this in [onLibraryCreated] instead.
karlklose
2014/09/04 07:54:04
Done.
| |
1659 } else if (uri == DART_JS_HELPER) { | 1702 } else if (uri == DART_JS_HELPER) { |
1660 initializeHelperClasses(); | 1703 initializeHelperClasses(); |
1661 assertMethod = findHelper('assertHelper'); | 1704 assertMethod = findHelper('assertHelper'); |
1662 | 1705 |
1663 typeLiteralClass = findClass('TypeImpl'); | 1706 typeLiteralClass = findClass('TypeImpl'); |
1664 constMapLiteralClass = findClass('ConstantMap'); | 1707 constMapLiteralClass = findClass('ConstantMap'); |
1665 typeVariableClass = findClass('TypeVariable'); | 1708 typeVariableClass = findClass('TypeVariable'); |
1666 | 1709 |
1667 jsIndexingBehaviorInterface = findClass('JavaScriptIndexingBehavior'); | 1710 jsIndexingBehaviorInterface = findClass('JavaScriptIndexingBehavior'); |
1668 | 1711 |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2363 } | 2406 } |
2364 } | 2407 } |
2365 | 2408 |
2366 /// Records that [constant] is used by the element behind [registry]. | 2409 /// Records that [constant] is used by the element behind [registry]. |
2367 class Dependency { | 2410 class Dependency { |
2368 final Constant constant; | 2411 final Constant constant; |
2369 final Element annotatedElement; | 2412 final Element annotatedElement; |
2370 | 2413 |
2371 const Dependency(this.constant, this.annotatedElement); | 2414 const Dependency(this.constant, this.annotatedElement); |
2372 } | 2415 } |
OLD | NEW |