| 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 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 assert(interceptorMember.enclosingClass == interceptorClass); | 895 assert(interceptorMember.enclosingClass == interceptorClass); |
| 896 }); | 896 }); |
| 897 } | 897 } |
| 898 | 898 |
| 899 void addInterceptorsForNativeClassMembers( | 899 void addInterceptorsForNativeClassMembers( |
| 900 ClassElement cls, Enqueuer enqueuer) { | 900 ClassElement cls, Enqueuer enqueuer) { |
| 901 if (enqueuer.isResolutionQueue) { | 901 if (enqueuer.isResolutionQueue) { |
| 902 cls.ensureResolved(compiler); | 902 cls.ensureResolved(compiler); |
| 903 cls.forEachMember((ClassElement classElement, Element member) { | 903 cls.forEachMember((ClassElement classElement, Element member) { |
| 904 if (member.name == Identifiers.call) { | 904 if (member.name == Identifiers.call) { |
| 905 compiler.reportError( | 905 compiler.reportErrorMessage( |
| 906 member, | 906 member, |
| 907 MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS); | 907 MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS); |
| 908 return; | 908 return; |
| 909 } | 909 } |
| 910 if (member.isSynthesized) return; | 910 if (member.isSynthesized) return; |
| 911 // All methods on [Object] are shadowed by [Interceptor]. | 911 // All methods on [Object] are shadowed by [Interceptor]. |
| 912 if (classElement == compiler.objectClass) return; | 912 if (classElement == compiler.objectClass) return; |
| 913 Set<Element> set = interceptedElements.putIfAbsent( | 913 Set<Element> set = interceptedElements.putIfAbsent( |
| 914 member.name, () => new Set<Element>()); | 914 member.name, () => new Set<Element>()); |
| 915 set.add(member); | 915 set.add(member); |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 return jsAst.prettyPrint(generatedCode[element], compiler).getText(); | 1507 return jsAst.prettyPrint(generatedCode[element], compiler).getText(); |
| 1508 } | 1508 } |
| 1509 | 1509 |
| 1510 int assembleProgram() { | 1510 int assembleProgram() { |
| 1511 int programSize = emitter.assembleProgram(); | 1511 int programSize = emitter.assembleProgram(); |
| 1512 noSuchMethodRegistry.emitDiagnostic(); | 1512 noSuchMethodRegistry.emitDiagnostic(); |
| 1513 int totalMethodCount = generatedCode.length; | 1513 int totalMethodCount = generatedCode.length; |
| 1514 if (totalMethodCount != preMirrorsMethodCount) { | 1514 if (totalMethodCount != preMirrorsMethodCount) { |
| 1515 int mirrorCount = totalMethodCount - preMirrorsMethodCount; | 1515 int mirrorCount = totalMethodCount - preMirrorsMethodCount; |
| 1516 double percentage = (mirrorCount / totalMethodCount) * 100; | 1516 double percentage = (mirrorCount / totalMethodCount) * 100; |
| 1517 compiler.reportHint( | 1517 DiagnosticMessage hint = compiler.createMessage( |
| 1518 compiler.mainApp, MessageKind.MIRROR_BLOAT, | 1518 compiler.mainApp, MessageKind.MIRROR_BLOAT, |
| 1519 {'count': mirrorCount, | 1519 {'count': mirrorCount, |
| 1520 'total': totalMethodCount, | 1520 'total': totalMethodCount, |
| 1521 'percentage': percentage.round()}); | 1521 'percentage': percentage.round()}); |
| 1522 |
| 1523 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; |
| 1522 for (LibraryElement library in compiler.libraryLoader.libraries) { | 1524 for (LibraryElement library in compiler.libraryLoader.libraries) { |
| 1523 if (library.isInternalLibrary) continue; | 1525 if (library.isInternalLibrary) continue; |
| 1524 for (ImportElement import in library.imports) { | 1526 for (ImportElement import in library.imports) { |
| 1525 LibraryElement importedLibrary = import.importedLibrary; | 1527 LibraryElement importedLibrary = import.importedLibrary; |
| 1526 if (importedLibrary != compiler.mirrorsLibrary) continue; | 1528 if (importedLibrary != compiler.mirrorsLibrary) continue; |
| 1527 MessageKind kind = | 1529 MessageKind kind = |
| 1528 compiler.mirrorUsageAnalyzerTask.hasMirrorUsage(library) | 1530 compiler.mirrorUsageAnalyzerTask.hasMirrorUsage(library) |
| 1529 ? MessageKind.MIRROR_IMPORT | 1531 ? MessageKind.MIRROR_IMPORT |
| 1530 : MessageKind.MIRROR_IMPORT_NO_USAGE; | 1532 : MessageKind.MIRROR_IMPORT_NO_USAGE; |
| 1531 compiler.withCurrentElement(library, () { | 1533 compiler.withCurrentElement(library, () { |
| 1532 compiler.reportInfo(import, kind); | 1534 infos.add(compiler.createMessage(import, kind)); |
| 1533 }); | 1535 }); |
| 1534 } | 1536 } |
| 1535 } | 1537 } |
| 1538 compiler.reportHint(hint, infos); |
| 1536 } | 1539 } |
| 1537 return programSize; | 1540 return programSize; |
| 1538 } | 1541 } |
| 1539 | 1542 |
| 1540 Element getDartClass(Element element) { | 1543 Element getDartClass(Element element) { |
| 1541 for (ClassElement dartClass in implementationClasses.keys) { | 1544 for (ClassElement dartClass in implementationClasses.keys) { |
| 1542 if (element == implementationClasses[dartClass]) { | 1545 if (element == implementationClasses[dartClass]) { |
| 1543 return dartClass; | 1546 return dartClass; |
| 1544 } | 1547 } |
| 1545 } | 1548 } |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2627 for (MetadataAnnotation metadata in element.implementation.metadata) { | 2630 for (MetadataAnnotation metadata in element.implementation.metadata) { |
| 2628 metadata.ensureResolved(compiler); | 2631 metadata.ensureResolved(compiler); |
| 2629 ConstantValue constantValue = | 2632 ConstantValue constantValue = |
| 2630 compiler.constants.getConstantValue(metadata.constant); | 2633 compiler.constants.getConstantValue(metadata.constant); |
| 2631 if (!constantValue.isConstructedObject) continue; | 2634 if (!constantValue.isConstructedObject) continue; |
| 2632 ObjectConstantValue value = constantValue; | 2635 ObjectConstantValue value = constantValue; |
| 2633 ClassElement cls = value.type.element; | 2636 ClassElement cls = value.type.element; |
| 2634 if (cls == forceInlineClass) { | 2637 if (cls == forceInlineClass) { |
| 2635 hasForceInline = true; | 2638 hasForceInline = true; |
| 2636 if (VERBOSE_OPTIMIZER_HINTS) { | 2639 if (VERBOSE_OPTIMIZER_HINTS) { |
| 2637 compiler.reportHint(element, | 2640 compiler.reportHintMessage( |
| 2641 element, |
| 2638 MessageKind.GENERIC, | 2642 MessageKind.GENERIC, |
| 2639 {'text': "Must inline"}); | 2643 {'text': "Must inline"}); |
| 2640 } | 2644 } |
| 2641 inlineCache.markAsMustInline(element); | 2645 inlineCache.markAsMustInline(element); |
| 2642 } else if (cls == noInlineClass) { | 2646 } else if (cls == noInlineClass) { |
| 2643 hasNoInline = true; | 2647 hasNoInline = true; |
| 2644 if (VERBOSE_OPTIMIZER_HINTS) { | 2648 if (VERBOSE_OPTIMIZER_HINTS) { |
| 2645 compiler.reportHint(element, | 2649 compiler.reportHintMessage( |
| 2650 element, |
| 2646 MessageKind.GENERIC, | 2651 MessageKind.GENERIC, |
| 2647 {'text': "Cannot inline"}); | 2652 {'text': "Cannot inline"}); |
| 2648 } | 2653 } |
| 2649 inlineCache.markAsNonInlinable(element); | 2654 inlineCache.markAsNonInlinable(element); |
| 2650 } else if (cls == noThrowsClass) { | 2655 } else if (cls == noThrowsClass) { |
| 2651 hasNoThrows = true; | 2656 hasNoThrows = true; |
| 2652 if (!Elements.isStaticOrTopLevelFunction(element)) { | 2657 if (!Elements.isStaticOrTopLevelFunction(element)) { |
| 2653 compiler.internalError(element, | 2658 compiler.internalError(element, |
| 2654 "@NoThrows() is currently limited to top-level" | 2659 "@NoThrows() is currently limited to top-level" |
| 2655 " or static functions"); | 2660 " or static functions"); |
| 2656 } | 2661 } |
| 2657 if (VERBOSE_OPTIMIZER_HINTS) { | 2662 if (VERBOSE_OPTIMIZER_HINTS) { |
| 2658 compiler.reportHint(element, | 2663 compiler.reportHintMessage( |
| 2664 element, |
| 2659 MessageKind.GENERIC, | 2665 MessageKind.GENERIC, |
| 2660 {'text': "Cannot throw"}); | 2666 {'text': "Cannot throw"}); |
| 2661 } | 2667 } |
| 2662 compiler.world.registerCannotThrow(element); | 2668 compiler.world.registerCannotThrow(element); |
| 2663 } else if (cls == noSideEffectsClass) { | 2669 } else if (cls == noSideEffectsClass) { |
| 2664 hasNoSideEffects = true; | 2670 hasNoSideEffects = true; |
| 2665 if (VERBOSE_OPTIMIZER_HINTS) { | 2671 if (VERBOSE_OPTIMIZER_HINTS) { |
| 2666 compiler.reportHint(element, | 2672 compiler.reportHintMessage( |
| 2673 element, |
| 2667 MessageKind.GENERIC, | 2674 MessageKind.GENERIC, |
| 2668 {'text': "Has no side effects"}); | 2675 {'text': "Has no side effects"}); |
| 2669 } | 2676 } |
| 2670 compiler.world.registerSideEffectsFree(element); | 2677 compiler.world.registerSideEffectsFree(element); |
| 2671 } | 2678 } |
| 2672 } | 2679 } |
| 2673 if (hasForceInline && hasNoInline) { | 2680 if (hasForceInline && hasNoInline) { |
| 2674 compiler.internalError(element, | 2681 compiler.internalError(element, |
| 2675 "@ForceInline() must not be used with @NoInline."); | 2682 "@ForceInline() must not be used with @NoInline."); |
| 2676 } | 2683 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2762 | 2769 |
| 2763 @override | 2770 @override |
| 2764 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) { | 2771 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) { |
| 2765 registerCheckDeferredIsLoaded(registry); | 2772 registerCheckDeferredIsLoaded(registry); |
| 2766 return true; | 2773 return true; |
| 2767 } | 2774 } |
| 2768 | 2775 |
| 2769 @override | 2776 @override |
| 2770 bool enableCodegenWithErrorsIfSupported(Spannable node) { | 2777 bool enableCodegenWithErrorsIfSupported(Spannable node) { |
| 2771 if (compiler.useCpsIr) { | 2778 if (compiler.useCpsIr) { |
| 2772 compiler.reportHint( | 2779 compiler.reportHintMessage( |
| 2773 node, | 2780 node, |
| 2774 MessageKind.GENERIC, | 2781 MessageKind.GENERIC, |
| 2775 {'text': "Generation of code with compile time errors is currently " | 2782 {'text': "Generation of code with compile time errors is currently " |
| 2776 "not supported with the CPS IR."}); | 2783 "not supported with the CPS IR."}); |
| 2777 return false; | 2784 return false; |
| 2778 } | 2785 } |
| 2779 return true; | 2786 return true; |
| 2780 } | 2787 } |
| 2781 | 2788 |
| 2782 jsAst.Expression rewriteAsync(FunctionElement element, | 2789 jsAst.Expression rewriteAsync(FunctionElement element, |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3173 } | 3180 } |
| 3174 } | 3181 } |
| 3175 | 3182 |
| 3176 /// Records that [constant] is used by the element behind [registry]. | 3183 /// Records that [constant] is used by the element behind [registry]. |
| 3177 class Dependency { | 3184 class Dependency { |
| 3178 final ConstantValue constant; | 3185 final ConstantValue constant; |
| 3179 final Element annotatedElement; | 3186 final Element annotatedElement; |
| 3180 | 3187 |
| 3181 const Dependency(this.constant, this.annotatedElement); | 3188 const Dependency(this.constant, this.annotatedElement); |
| 3182 } | 3189 } |
| OLD | NEW |