| 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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 // helper so we register a use of that. | 744 // helper so we register a use of that. |
| 745 registry.registerStaticInvocation(getCreateRuntimeType()); | 745 registry.registerStaticInvocation(getCreateRuntimeType()); |
| 746 } | 746 } |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 | 749 |
| 750 void registerMetadataConstant(MetadataAnnotation metadata, | 750 void registerMetadataConstant(MetadataAnnotation metadata, |
| 751 Element annotatedElement, | 751 Element annotatedElement, |
| 752 Registry registry) { | 752 Registry registry) { |
| 753 assert(registry.isForResolution); | 753 assert(registry.isForResolution); |
| 754 Constant constant = constants.getConstantForMetadata(metadata); | 754 Constant constant = constants.getConstantForMetadata(metadata).value; |
| 755 registerCompileTimeConstant(constant, registry); | 755 registerCompileTimeConstant(constant, registry); |
| 756 metadataConstants.add(new Dependency(constant, annotatedElement)); | 756 metadataConstants.add(new Dependency(constant, annotatedElement)); |
| 757 } | 757 } |
| 758 | 758 |
| 759 void registerInstantiatedClass(ClassElement cls, | 759 void registerInstantiatedClass(ClassElement cls, |
| 760 Enqueuer enqueuer, | 760 Enqueuer enqueuer, |
| 761 Registry registry) { | 761 Registry registry) { |
| 762 if (!cls.typeVariables.isEmpty) { | 762 if (!cls.typeVariables.isEmpty) { |
| 763 typeVariableHandler.registerClassWithTypeVariables(cls); | 763 typeVariableHandler.registerClassWithTypeVariables(cls); |
| 764 } | 764 } |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 | 1147 |
| 1148 void codegen(CodegenWorkItem work) { | 1148 void codegen(CodegenWorkItem work) { |
| 1149 Element element = work.element; | 1149 Element element = work.element; |
| 1150 var kind = element.kind; | 1150 var kind = element.kind; |
| 1151 if (kind == ElementKind.TYPEDEF) return; | 1151 if (kind == ElementKind.TYPEDEF) return; |
| 1152 if (element.isConstructor && element.enclosingClass == jsNullClass) { | 1152 if (element.isConstructor && element.enclosingClass == jsNullClass) { |
| 1153 // Work around a problem compiling JSNull's constructor. | 1153 // Work around a problem compiling JSNull's constructor. |
| 1154 return; | 1154 return; |
| 1155 } | 1155 } |
| 1156 if (kind.category == ElementCategory.VARIABLE) { | 1156 if (kind.category == ElementCategory.VARIABLE) { |
| 1157 Constant initialValue = constants.getConstantForVariable(element); | 1157 ConstExp initialValue = constants.getConstantForVariable(element); |
| 1158 if (initialValue != null) { | 1158 if (initialValue != null) { |
| 1159 registerCompileTimeConstant(initialValue, work.registry); | 1159 registerCompileTimeConstant(initialValue.value, work.registry); |
| 1160 constants.addCompileTimeConstantForEmission(initialValue); | 1160 constants.addCompileTimeConstantForEmission(initialValue.value); |
| 1161 // We don't need to generate code for static or top-level | 1161 // We don't need to generate code for static or top-level |
| 1162 // variables. For instance variables, we may need to generate | 1162 // variables. For instance variables, we may need to generate |
| 1163 // the checked setter. | 1163 // the checked setter. |
| 1164 if (Elements.isStaticOrTopLevel(element)) return; | 1164 if (Elements.isStaticOrTopLevel(element)) return; |
| 1165 } else { | 1165 } else { |
| 1166 // If the constant-handler was not able to produce a result we have to | 1166 // If the constant-handler was not able to produce a result we have to |
| 1167 // go through the builder (below) to generate the lazy initializer for | 1167 // go through the builder (below) to generate the lazy initializer for |
| 1168 // the static variable. | 1168 // the static variable. |
| 1169 // We also need to register the use of the cyclic-error helper. | 1169 // We also need to register the use of the cyclic-error helper. |
| 1170 compiler.enqueuer.codegen.registerStaticUse(getCyclicThrowHelper()); | 1170 compiler.enqueuer.codegen.registerStaticUse(getCyclicThrowHelper()); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 if (hasInsufficientMirrorsUsed) return mustPreserveNames; | 1604 if (hasInsufficientMirrorsUsed) return mustPreserveNames; |
| 1605 if (name == '') return false; | 1605 if (name == '') return false; |
| 1606 return symbolsUsed.contains(name); | 1606 return symbolsUsed.contains(name); |
| 1607 } | 1607 } |
| 1608 | 1608 |
| 1609 bool retainMetadataOf(Element element) { | 1609 bool retainMetadataOf(Element element) { |
| 1610 if (mustRetainMetadata) hasRetainedMetadata = true; | 1610 if (mustRetainMetadata) hasRetainedMetadata = true; |
| 1611 if (mustRetainMetadata && referencedFromMirrorSystem(element)) { | 1611 if (mustRetainMetadata && referencedFromMirrorSystem(element)) { |
| 1612 for (MetadataAnnotation metadata in element.metadata) { | 1612 for (MetadataAnnotation metadata in element.metadata) { |
| 1613 metadata.ensureResolved(compiler); | 1613 metadata.ensureResolved(compiler); |
| 1614 Constant constant = constants.getConstantForMetadata(metadata); | 1614 Constant constant = constants.getConstantForMetadata(metadata).value; |
| 1615 constants.addCompileTimeConstantForEmission(constant); | 1615 constants.addCompileTimeConstantForEmission(constant); |
| 1616 } | 1616 } |
| 1617 return true; | 1617 return true; |
| 1618 } | 1618 } |
| 1619 return false; | 1619 return false; |
| 1620 } | 1620 } |
| 1621 | 1621 |
| 1622 void onLibraryCreated(LibraryElement library) { | 1622 void onLibraryCreated(LibraryElement library) { |
| 1623 Uri uri = library.canonicalUri; | 1623 Uri uri = library.canonicalUri; |
| 1624 if (uri == DART_JS_HELPER) { | 1624 if (uri == DART_JS_HELPER) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1873 * of a type that is used as a meta target for reflection. | 1873 * of a type that is used as a meta target for reflection. |
| 1874 */ | 1874 */ |
| 1875 bool matchesMirrorsMetaTarget(Element element) { | 1875 bool matchesMirrorsMetaTarget(Element element) { |
| 1876 if (metaTargetsUsed.isEmpty) return false; | 1876 if (metaTargetsUsed.isEmpty) return false; |
| 1877 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { | 1877 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { |
| 1878 MetadataAnnotation metadata = link.head; | 1878 MetadataAnnotation metadata = link.head; |
| 1879 // TODO(kasperl): It would be nice if we didn't have to resolve | 1879 // TODO(kasperl): It would be nice if we didn't have to resolve |
| 1880 // all metadata but only stuff that potentially would match one | 1880 // all metadata but only stuff that potentially would match one |
| 1881 // of the used meta targets. | 1881 // of the used meta targets. |
| 1882 metadata.ensureResolved(compiler); | 1882 metadata.ensureResolved(compiler); |
| 1883 Constant value = metadata.value; | 1883 Constant value = metadata.constant.value; |
| 1884 if (value == null) continue; | 1884 if (value == null) continue; |
| 1885 DartType type = value.computeType(compiler); | 1885 DartType type = value.computeType(compiler); |
| 1886 if (metaTargetsUsed.contains(type.element)) return true; | 1886 if (metaTargetsUsed.contains(type.element)) return true; |
| 1887 } | 1887 } |
| 1888 return false; | 1888 return false; |
| 1889 } | 1889 } |
| 1890 | 1890 |
| 1891 /** | 1891 /** |
| 1892 * Visits all classes and computes whether its members are needed for | 1892 * Visits all classes and computes whether its members are needed for |
| 1893 * reflection. | 1893 * reflection. |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 } | 2141 } |
| 2142 | 2142 |
| 2143 void onElementResolved(Element element, TreeElements elements) { | 2143 void onElementResolved(Element element, TreeElements elements) { |
| 2144 LibraryElement library = element.library; | 2144 LibraryElement library = element.library; |
| 2145 if (!library.isPlatformLibrary && !library.canUseNative) return; | 2145 if (!library.isPlatformLibrary && !library.canUseNative) return; |
| 2146 bool hasNoInline = false; | 2146 bool hasNoInline = false; |
| 2147 bool hasNoThrows = false; | 2147 bool hasNoThrows = false; |
| 2148 bool hasNoSideEffects = false; | 2148 bool hasNoSideEffects = false; |
| 2149 for (MetadataAnnotation metadata in element.metadata) { | 2149 for (MetadataAnnotation metadata in element.metadata) { |
| 2150 metadata.ensureResolved(compiler); | 2150 metadata.ensureResolved(compiler); |
| 2151 if (!metadata.value.isConstructedObject) continue; | 2151 if (!metadata.constant.value.isConstructedObject) continue; |
| 2152 ObjectConstant value = metadata.value; | 2152 ObjectConstant value = metadata.constant.value; |
| 2153 ClassElement cls = value.type.element; | 2153 ClassElement cls = value.type.element; |
| 2154 if (cls == noInlineClass) { | 2154 if (cls == noInlineClass) { |
| 2155 hasNoInline = true; | 2155 hasNoInline = true; |
| 2156 if (VERBOSE_OPTIMIZER_HINTS) { | 2156 if (VERBOSE_OPTIMIZER_HINTS) { |
| 2157 compiler.reportHint(element, | 2157 compiler.reportHint(element, |
| 2158 MessageKind.GENERIC, | 2158 MessageKind.GENERIC, |
| 2159 {'text': "Cannot inline"}); | 2159 {'text': "Cannot inline"}); |
| 2160 } | 2160 } |
| 2161 inlineCache.markAsNonInlinable(element); | 2161 inlineCache.markAsNonInlinable(element); |
| 2162 } else if (cls == noThrowsClass) { | 2162 } else if (cls == noThrowsClass) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 } | 2407 } |
| 2408 } | 2408 } |
| 2409 | 2409 |
| 2410 /// Records that [constant] is used by the element behind [registry]. | 2410 /// Records that [constant] is used by the element behind [registry]. |
| 2411 class Dependency { | 2411 class Dependency { |
| 2412 final Constant constant; | 2412 final Constant constant; |
| 2413 final Element annotatedElement; | 2413 final Element annotatedElement; |
| 2414 | 2414 |
| 2415 const Dependency(this.constant, this.annotatedElement); | 2415 const Dependency(this.constant, this.annotatedElement); |
| 2416 } | 2416 } |
| OLD | NEW |