Chromium Code Reviews| 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 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 7 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
| 8 final Set<HInstruction> boundsChecked; | 8 final Set<HInstruction> boundsChecked; |
| 9 | 9 |
| 10 JavaScriptItemCompilationContext() | 10 JavaScriptItemCompilationContext() |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 final RuntimeTypes rti; | 149 final RuntimeTypes rti; |
| 150 | 150 |
| 151 /// Holds the method "disableTreeShaking" in js_mirrors when | 151 /// Holds the method "disableTreeShaking" in js_mirrors when |
| 152 /// dart:mirrors has been loaded. | 152 /// dart:mirrors has been loaded. |
| 153 FunctionElement disableTreeShakingMarker; | 153 FunctionElement disableTreeShakingMarker; |
| 154 | 154 |
| 155 /// Holds the method "preserveNames" in js_mirrors when | 155 /// Holds the method "preserveNames" in js_mirrors when |
| 156 /// dart:mirrors has been loaded. | 156 /// dart:mirrors has been loaded. |
| 157 FunctionElement preserveNamesMarker; | 157 FunctionElement preserveNamesMarker; |
| 158 | 158 |
| 159 /// Holds the method "preserveMetadata" in js_mirrors when | |
| 160 /// dart:mirrors has been loaded. | |
| 161 FunctionElement preserveMetadataMarker; | |
| 162 | |
| 163 bool mustRetainMetadata = false; | |
| 164 bool retainedMetadata = false; | |
|
kasperl
2013/06/20 07:16:46
Add a comment that explains the difference between
ahe
2013/06/21 12:24:39
Done.
| |
| 165 bool mustPreserveNames = false; | |
| 166 bool isTreeShakingDisabled = false; | |
| 167 | |
| 168 /// List of instantiated classes from metadata. If metadata must be | |
| 169 /// preserved, these classes must registered. | |
| 170 final List<List> metadataInstantiatedClasses = <List>[]; | |
|
Johnni Winther
2013/06/20 10:17:02
Add a comment of what the content of the list of l
ahe
2013/06/21 12:24:39
I added a class to represent this concept, a depen
| |
| 171 | |
| 172 /// List of elements used from metadata. If metadata must be preserved, | |
| 173 /// these elements must be compiled. | |
| 174 final List<Element> metadataStaticUse = <Element>[]; | |
| 175 | |
| 176 /// List of tear-off functions referenced from metadata. If metadata must be | |
| 177 /// preserved, these elements must be compiled. | |
| 178 final List<FunctionElement> metadataGetOfStaticFunction = <FunctionElement>[]; | |
| 179 | |
| 159 JavaScriptBackend(Compiler compiler, bool generateSourceMap, bool disableEval) | 180 JavaScriptBackend(Compiler compiler, bool generateSourceMap, bool disableEval) |
| 160 : namer = determineNamer(compiler), | 181 : namer = determineNamer(compiler), |
| 161 oneShotInterceptors = new Map<String, Selector>(), | 182 oneShotInterceptors = new Map<String, Selector>(), |
| 162 interceptedElements = new Map<SourceString, Set<Element>>(), | 183 interceptedElements = new Map<SourceString, Set<Element>>(), |
| 163 rti = new RuntimeTypes(compiler), | 184 rti = new RuntimeTypes(compiler), |
| 164 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), | 185 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), |
| 165 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { | 186 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { |
| 166 emitter = disableEval | 187 emitter = disableEval |
| 167 ? new CodeEmitterNoEvalTask(compiler, namer, generateSourceMap) | 188 ? new CodeEmitterNoEvalTask(compiler, namer, generateSourceMap) |
| 168 : new CodeEmitterTask(compiler, namer, generateSourceMap); | 189 : new CodeEmitterTask(compiler, namer, generateSourceMap); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 } | 611 } |
| 591 | 612 |
| 592 void registerThrowExpression(TreeElements elements) { | 613 void registerThrowExpression(TreeElements elements) { |
| 593 enqueueInResolution(getThrowExpressionHelper(), elements); | 614 enqueueInResolution(getThrowExpressionHelper(), elements); |
| 594 } | 615 } |
| 595 | 616 |
| 596 void registerLazyField(TreeElements elements) { | 617 void registerLazyField(TreeElements elements) { |
| 597 enqueueInResolution(getCyclicThrowHelper(), elements); | 618 enqueueInResolution(getCyclicThrowHelper(), elements); |
| 598 } | 619 } |
| 599 | 620 |
| 600 void registerTypeLiteral(TreeElements elements) { | 621 void registerTypeLiteral(Element element, TreeElements elements) { |
| 601 enqueueInResolution(getCreateRuntimeType(), elements); | 622 enqueueInResolution(getCreateRuntimeType(), elements); |
| 623 // TODO(ahe): Might want to register [element] as an instantiated class | |
| 624 // when reflection is used. However, as long as we disable tree-shaking | |
| 625 // eagerly it doesn't matter. | |
| 602 } | 626 } |
| 603 | 627 |
| 604 void registerStackTraceInCatch(TreeElements elements) { | 628 void registerStackTraceInCatch(TreeElements elements) { |
| 605 enqueueInResolution(getTraceFromException(), elements); | 629 enqueueInResolution(getTraceFromException(), elements); |
| 606 } | 630 } |
| 607 | 631 |
| 608 void registerSetRuntimeType(TreeElements elements) { | 632 void registerSetRuntimeType(TreeElements elements) { |
| 609 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 633 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 610 } | 634 } |
| 611 | 635 |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 ClassElement get listImplementation => jsArrayClass; | 1127 ClassElement get listImplementation => jsArrayClass; |
| 1104 ClassElement get constListImplementation => jsArrayClass; | 1128 ClassElement get constListImplementation => jsArrayClass; |
| 1105 ClassElement get fixedListImplementation => jsFixedArrayClass; | 1129 ClassElement get fixedListImplementation => jsFixedArrayClass; |
| 1106 ClassElement get growableListImplementation => jsExtendableArrayClass; | 1130 ClassElement get growableListImplementation => jsExtendableArrayClass; |
| 1107 ClassElement get mapImplementation => mapLiteralClass; | 1131 ClassElement get mapImplementation => mapLiteralClass; |
| 1108 ClassElement get constMapImplementation => constMapLiteralClass; | 1132 ClassElement get constMapImplementation => constMapLiteralClass; |
| 1109 ClassElement get typeImplementation => typeLiteralClass; | 1133 ClassElement get typeImplementation => typeLiteralClass; |
| 1110 ClassElement get boolImplementation => jsBoolClass; | 1134 ClassElement get boolImplementation => jsBoolClass; |
| 1111 ClassElement get nullImplementation => jsNullClass; | 1135 ClassElement get nullImplementation => jsNullClass; |
| 1112 | 1136 |
| 1113 void enableMirrors() { | |
| 1114 LibraryElement library = compiler.libraries['dart:_js_mirrors']; | |
| 1115 disableTreeShakingMarker = | |
| 1116 library.find(const SourceString('disableTreeShaking')); | |
| 1117 preserveNamesMarker = | |
| 1118 library.find(const SourceString('preserveNames')); | |
| 1119 } | |
| 1120 | |
| 1121 void registerStaticUse(Element element, Enqueuer enqueuer) { | 1137 void registerStaticUse(Element element, Enqueuer enqueuer) { |
| 1122 if (element == disableTreeShakingMarker) { | 1138 if (element == disableTreeShakingMarker) { |
| 1123 enqueuer.enqueueEverything(); | 1139 enqueuer.enqueueEverything(); |
| 1140 if (isTreeShakingDisabled) return; | |
| 1124 compiler.disableTypeInferenceForMirrors = true; | 1141 compiler.disableTypeInferenceForMirrors = true; |
| 1142 isTreeShakingDisabled = true; | |
| 1125 } else if (element == preserveNamesMarker) { | 1143 } else if (element == preserveNamesMarker) { |
| 1144 if (mustPreserveNames) return; | |
| 1145 mustPreserveNames = true; | |
| 1146 compiler.log('Preserving names.'); | |
| 1147 } else if (element == preserveMetadataMarker) { | |
| 1148 if (mustRetainMetadata) return; | |
| 1149 compiler.log('Retaining metadata.'); | |
| 1150 mustRetainMetadata = true; | |
| 1151 for (LibraryElement library in compiler.libraries.values) { | |
| 1152 if (retainMetadataOf(library)) { | |
| 1153 for (Link link = library.metadata; !link.isEmpty; link = link.tail) { | |
| 1154 link.head.ensureResolved(compiler); | |
| 1155 } | |
| 1156 } | |
| 1157 } | |
| 1158 for (List entries in metadataInstantiatedClasses) { | |
| 1159 registerMetadataInstantiatedClass(entries[0], entries[1]); | |
| 1160 } | |
| 1161 metadataInstantiatedClasses.clear(); | |
| 1162 for (Element e in metadataStaticUse) { | |
| 1163 registerMetadataStaticUse(e); | |
| 1164 } | |
| 1165 metadataStaticUse.clear(); | |
| 1166 for (Element e in metadataGetOfStaticFunction) { | |
| 1167 registerMetadataGetOfStaticFunction(e); | |
| 1168 } | |
| 1169 metadataGetOfStaticFunction.clear(); | |
| 1170 } | |
| 1171 } | |
| 1172 | |
| 1173 /// Called when [:const Symbol(name):] is seen. | |
| 1174 void registerConstSymbol(String name, TreeElements elements) { | |
| 1175 } | |
| 1176 | |
| 1177 /// Called when [:new Symbol(...):] is seen. | |
| 1178 void registerNewSymbol(TreeElements elements) { | |
| 1179 } | |
| 1180 | |
| 1181 bool retainGetter(Element element) => isTreeShakingDisabled; | |
| 1182 | |
| 1183 bool retainSetter(Element element) => isTreeShakingDisabled; | |
| 1184 | |
| 1185 bool retainName(SourceString name) => mustPreserveNames; | |
| 1186 | |
| 1187 bool retainMetadataOf(Element element) { | |
| 1188 if (mustRetainMetadata) retainedMetadata = true; | |
| 1189 return mustRetainMetadata; | |
| 1190 } | |
| 1191 | |
| 1192 void onLibraryScanned(LibraryElement library, Uri uri) { | |
| 1193 if (uri == Uri.parse('dart:_js_mirrors')) { | |
| 1194 disableTreeShakingMarker = | |
| 1195 library.find(const SourceString('disableTreeShaking')); | |
| 1196 preserveMetadataMarker = | |
| 1197 library.find(const SourceString('preserveMetadata')); | |
| 1198 } else if (uri == Uri.parse('dart:_js_names')) { | |
| 1199 preserveNamesMarker = | |
| 1200 library.find(const SourceString('preserveNames')); | |
| 1201 } | |
| 1202 } | |
| 1203 | |
| 1204 void registerMetadataInstantiatedClass(ClassElement element, | |
| 1205 TreeElements elements) { | |
| 1206 if (mustRetainMetadata) { | |
| 1207 compiler.constantHandler.registerInstantiatedClass(element, elements); | |
| 1208 } else { | |
| 1209 metadataInstantiatedClasses.add([element, elements]); | |
| 1210 } | |
| 1211 } | |
| 1212 | |
| 1213 void registerMetadataStaticUse(Element element) { | |
| 1214 if (mustRetainMetadata) { | |
| 1215 compiler.constantHandler.registerStaticUse(element); | |
| 1216 } else { | |
| 1217 metadataStaticUse.add(element); | |
| 1218 } | |
| 1219 } | |
| 1220 | |
| 1221 void registerMetadataGetOfStaticFunction(FunctionElement element) { | |
| 1222 if (mustRetainMetadata) { | |
| 1223 compiler.constantHandler.registerGetOfStaticFunction(element); | |
| 1224 } else { | |
| 1225 metadataGetOfStaticFunction.add(element); | |
| 1126 } | 1226 } |
| 1127 } | 1227 } |
| 1128 } | 1228 } |
| OLD | NEW |