| 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 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 targetsUsed.contains(element) || | 2306 targetsUsed.contains(element) || |
| 2307 (enclosing != null && referencedFromMirrorSystem(enclosing)); | 2307 (enclosing != null && referencedFromMirrorSystem(enclosing)); |
| 2308 } | 2308 } |
| 2309 | 2309 |
| 2310 /** | 2310 /** |
| 2311 * Returns `true` if the element is needed because it has an annotation | 2311 * Returns `true` if the element is needed because it has an annotation |
| 2312 * of a type that is used as a meta target for reflection. | 2312 * of a type that is used as a meta target for reflection. |
| 2313 */ | 2313 */ |
| 2314 bool matchesMirrorsMetaTarget(Element element) { | 2314 bool matchesMirrorsMetaTarget(Element element) { |
| 2315 if (metaTargetsUsed.isEmpty) return false; | 2315 if (metaTargetsUsed.isEmpty) return false; |
| 2316 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { | 2316 for (MetadataAnnotation metadata in element.metadata) { |
| 2317 MetadataAnnotation metadata = link.head; | |
| 2318 // TODO(kasperl): It would be nice if we didn't have to resolve | 2317 // TODO(kasperl): It would be nice if we didn't have to resolve |
| 2319 // all metadata but only stuff that potentially would match one | 2318 // all metadata but only stuff that potentially would match one |
| 2320 // of the used meta targets. | 2319 // of the used meta targets. |
| 2321 metadata.ensureResolved(compiler); | 2320 metadata.ensureResolved(compiler); |
| 2322 ConstantValue value = | 2321 ConstantValue value = |
| 2323 compiler.constants.getConstantValue(metadata.constant); | 2322 compiler.constants.getConstantValue(metadata.constant); |
| 2324 if (value == null) continue; | 2323 if (value == null) continue; |
| 2325 DartType type = value.getType(compiler.coreTypes); | 2324 DartType type = value.getType(compiler.coreTypes); |
| 2326 if (metaTargetsUsed.contains(type.element)) return true; | 2325 if (metaTargetsUsed.contains(type.element)) return true; |
| 2327 } | 2326 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 annotations.noInline(element)) { | 2617 annotations.noInline(element)) { |
| 2619 inlineCache.markAsNonInlinable(element); | 2618 inlineCache.markAsNonInlinable(element); |
| 2620 } | 2619 } |
| 2621 | 2620 |
| 2622 LibraryElement library = element.library; | 2621 LibraryElement library = element.library; |
| 2623 if (!library.isPlatformLibrary && !library.canUseNative) return; | 2622 if (!library.isPlatformLibrary && !library.canUseNative) return; |
| 2624 bool hasNoInline = false; | 2623 bool hasNoInline = false; |
| 2625 bool hasForceInline = false; | 2624 bool hasForceInline = false; |
| 2626 bool hasNoThrows = false; | 2625 bool hasNoThrows = false; |
| 2627 bool hasNoSideEffects = false; | 2626 bool hasNoSideEffects = false; |
| 2628 for (MetadataAnnotation metadata in element.metadata) { | 2627 for (MetadataAnnotation metadata in element.implementation.metadata) { |
| 2629 metadata.ensureResolved(compiler); | 2628 metadata.ensureResolved(compiler); |
| 2630 ConstantValue constantValue = | 2629 ConstantValue constantValue = |
| 2631 compiler.constants.getConstantValue(metadata.constant); | 2630 compiler.constants.getConstantValue(metadata.constant); |
| 2632 if (!constantValue.isConstructedObject) continue; | 2631 if (!constantValue.isConstructedObject) continue; |
| 2633 ObjectConstantValue value = constantValue; | 2632 ObjectConstantValue value = constantValue; |
| 2634 ClassElement cls = value.type.element; | 2633 ClassElement cls = value.type.element; |
| 2635 if (cls == forceInlineClass) { | 2634 if (cls == forceInlineClass) { |
| 2636 hasForceInline = true; | 2635 hasForceInline = true; |
| 2637 if (VERBOSE_OPTIMIZER_HINTS) { | 2636 if (VERBOSE_OPTIMIZER_HINTS) { |
| 2638 compiler.reportHint(element, | 2637 compiler.reportHint(element, |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2887 } | 2886 } |
| 2888 | 2887 |
| 2889 /// Returns `true` if inference of parameter types is disabled for [element]. | 2888 /// Returns `true` if inference of parameter types is disabled for [element]. |
| 2890 bool assumeDynamic(Element element) { | 2889 bool assumeDynamic(Element element) { |
| 2891 return _hasAnnotation(element, expectAssumeDynamicClass); | 2890 return _hasAnnotation(element, expectAssumeDynamicClass); |
| 2892 } | 2891 } |
| 2893 | 2892 |
| 2894 /// Returns `true` if [element] is annotated with [annotationClass]. | 2893 /// Returns `true` if [element] is annotated with [annotationClass]. |
| 2895 bool _hasAnnotation(Element element, ClassElement annotationClass) { | 2894 bool _hasAnnotation(Element element, ClassElement annotationClass) { |
| 2896 if (annotationClass == null) return false; | 2895 if (annotationClass == null) return false; |
| 2897 for (Link<MetadataAnnotation> link = element.metadata; | 2896 return compiler.withCurrentElement(element, () { |
| 2898 !link.isEmpty; | 2897 for (MetadataAnnotation metadata in element.metadata) { |
| 2899 link = link.tail) { | 2898 assert(invariant(metadata, metadata.constant != null, |
| 2900 ConstantValue value = | 2899 message: "Unevaluated metadata constant.")); |
| 2901 compiler.constants.getConstantValue(link.head.constant); | 2900 ConstantValue value = |
| 2902 if (value.isConstructedObject) { | 2901 compiler.constants.getConstantValue(metadata.constant); |
| 2903 ConstructedConstantValue constructedConstant = value; | 2902 if (value.isConstructedObject) { |
| 2904 if (constructedConstant.type.element == annotationClass) { | 2903 ConstructedConstantValue constructedConstant = value; |
| 2905 return true; | 2904 if (constructedConstant.type.element == annotationClass) { |
| 2905 return true; |
| 2906 } |
| 2906 } | 2907 } |
| 2907 } | 2908 } |
| 2908 } | 2909 return false; |
| 2909 return false; | 2910 }); |
| 2910 } | 2911 } |
| 2911 } | 2912 } |
| 2912 | 2913 |
| 2913 class JavaScriptResolutionCallbacks extends ResolutionCallbacks { | 2914 class JavaScriptResolutionCallbacks extends ResolutionCallbacks { |
| 2914 final JavaScriptBackend backend; | 2915 final JavaScriptBackend backend; |
| 2915 | 2916 |
| 2916 JavaScriptResolutionCallbacks(this.backend); | 2917 JavaScriptResolutionCallbacks(this.backend); |
| 2917 | 2918 |
| 2918 void registerBackendStaticInvocation(Element element, Registry registry) { | 2919 void registerBackendStaticInvocation(Element element, Registry registry) { |
| 2919 registry.registerStaticInvocation(backend.registerBackendUse(element)); | 2920 registry.registerStaticInvocation(backend.registerBackendUse(element)); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3134 } | 3135 } |
| 3135 } | 3136 } |
| 3136 | 3137 |
| 3137 /// Records that [constant] is used by the element behind [registry]. | 3138 /// Records that [constant] is used by the element behind [registry]. |
| 3138 class Dependency { | 3139 class Dependency { |
| 3139 final ConstantValue constant; | 3140 final ConstantValue constant; |
| 3140 final Element annotatedElement; | 3141 final Element annotatedElement; |
| 3141 | 3142 |
| 3142 const Dependency(this.constant, this.annotatedElement); | 3143 const Dependency(this.constant, this.annotatedElement); |
| 3143 } | 3144 } |
| OLD | NEW |