| 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 dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
| 9 * compiled. | 9 * compiled. |
| 10 */ | 10 */ |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 | 822 |
| 823 /// Document class from dart:mirrors. | 823 /// Document class from dart:mirrors. |
| 824 ClassElement documentClass; | 824 ClassElement documentClass; |
| 825 Element identicalFunction; | 825 Element identicalFunction; |
| 826 Element loadLibraryFunction; | 826 Element loadLibraryFunction; |
| 827 Element functionApplyMethod; | 827 Element functionApplyMethod; |
| 828 Element intEnvironment; | 828 Element intEnvironment; |
| 829 Element boolEnvironment; | 829 Element boolEnvironment; |
| 830 Element stringEnvironment; | 830 Element stringEnvironment; |
| 831 | 831 |
| 832 /// Tracks elements with compile-time errors. |
| 833 final Set<Element> elementsWithCompileTimeErrors = new Set<Element>(); |
| 834 |
| 832 fromEnvironment(String name) => null; | 835 fromEnvironment(String name) => null; |
| 833 | 836 |
| 834 Element get currentElement => _currentElement; | 837 Element get currentElement => _currentElement; |
| 835 | 838 |
| 836 String tryToString(object) { | 839 String tryToString(object) { |
| 837 try { | 840 try { |
| 838 return object.toString(); | 841 return object.toString(); |
| 839 } catch (_) { | 842 } catch (_) { |
| 840 return '<exception in toString()>'; | 843 return '<exception in toString()>'; |
| 841 } | 844 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 bool get shouldPrintProgress { | 942 bool get shouldPrintProgress { |
| 940 return verbose && progress.elapsedMilliseconds > 500; | 943 return verbose && progress.elapsedMilliseconds > 500; |
| 941 } | 944 } |
| 942 | 945 |
| 943 static const int PHASE_SCANNING = 0; | 946 static const int PHASE_SCANNING = 0; |
| 944 static const int PHASE_RESOLVING = 1; | 947 static const int PHASE_RESOLVING = 1; |
| 945 static const int PHASE_DONE_RESOLVING = 2; | 948 static const int PHASE_DONE_RESOLVING = 2; |
| 946 static const int PHASE_COMPILING = 3; | 949 static const int PHASE_COMPILING = 3; |
| 947 int phase; | 950 int phase; |
| 948 | 951 |
| 949 bool compilationFailed = false; | 952 bool compilationFailedInternal = false; |
| 953 |
| 954 bool get compilationFailed => compilationFailedInternal; |
| 955 |
| 956 void set compilationFailed(bool value) { |
| 957 if (value) { |
| 958 elementsWithCompileTimeErrors.add(currentElement); |
| 959 } |
| 960 compilationFailedInternal = value; |
| 961 } |
| 950 | 962 |
| 951 bool hasCrashed = false; | 963 bool hasCrashed = false; |
| 952 | 964 |
| 953 /// Set by the backend if real reflection is detected in use of dart:mirrors. | 965 /// Set by the backend if real reflection is detected in use of dart:mirrors. |
| 954 bool disableTypeInferenceForMirrors = false; | 966 bool disableTypeInferenceForMirrors = false; |
| 955 | 967 |
| 956 Compiler({this.enableTypeAssertions: false, | 968 Compiler({this.enableTypeAssertions: false, |
| 957 this.enableUserAssertions: false, | 969 this.enableUserAssertions: false, |
| 958 this.trustTypeAnnotations: false, | 970 this.trustTypeAnnotations: false, |
| 959 this.trustPrimitives: false, | 971 this.trustPrimitives: false, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 | 1068 |
| 1057 Universe get resolverWorld => enqueuer.resolution.universe; | 1069 Universe get resolverWorld => enqueuer.resolution.universe; |
| 1058 Universe get codegenWorld => enqueuer.codegen.universe; | 1070 Universe get codegenWorld => enqueuer.codegen.universe; |
| 1059 | 1071 |
| 1060 bool get hasBuildId => buildId != UNDETERMINED_BUILD_ID; | 1072 bool get hasBuildId => buildId != UNDETERMINED_BUILD_ID; |
| 1061 | 1073 |
| 1062 bool get analyzeAll => analyzeAllFlag || compileAll; | 1074 bool get analyzeAll => analyzeAllFlag || compileAll; |
| 1063 | 1075 |
| 1064 bool get compileAll => false; | 1076 bool get compileAll => false; |
| 1065 | 1077 |
| 1066 bool get disableTypeInference => disableTypeInferenceFlag; | 1078 bool get disableTypeInference { |
| 1079 return disableTypeInferenceFlag || compilationFailed; |
| 1080 } |
| 1067 | 1081 |
| 1068 int getNextFreeClassId() => nextFreeClassId++; | 1082 int getNextFreeClassId() => nextFreeClassId++; |
| 1069 | 1083 |
| 1070 void unimplemented(Spannable spannable, String methodName) { | 1084 void unimplemented(Spannable spannable, String methodName) { |
| 1071 internalError(spannable, "$methodName not implemented."); | 1085 internalError(spannable, "$methodName not implemented."); |
| 1072 } | 1086 } |
| 1073 | 1087 |
| 1074 void internalError(Spannable node, reason) { | 1088 void internalError(Spannable node, reason) { |
| 1075 String message = tryToString(reason); | 1089 String message = tryToString(reason); |
| 1076 reportDiagnosticInternal( | 1090 reportDiagnosticInternal( |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 fullyEnqueueLibrary(mainApp, enqueuer.resolution); | 1542 fullyEnqueueLibrary(mainApp, enqueuer.resolution); |
| 1529 } | 1543 } |
| 1530 // Elements required by enqueueHelpers are global dependencies | 1544 // Elements required by enqueueHelpers are global dependencies |
| 1531 // that are not pulled in by a particular element. | 1545 // that are not pulled in by a particular element. |
| 1532 backend.enqueueHelpers(enqueuer.resolution, globalDependencies); | 1546 backend.enqueueHelpers(enqueuer.resolution, globalDependencies); |
| 1533 resolveLibraryMetadata(); | 1547 resolveLibraryMetadata(); |
| 1534 log('Resolving...'); | 1548 log('Resolving...'); |
| 1535 processQueue(enqueuer.resolution, mainFunction); | 1549 processQueue(enqueuer.resolution, mainFunction); |
| 1536 enqueuer.resolution.logSummary(log); | 1550 enqueuer.resolution.logSummary(log); |
| 1537 | 1551 |
| 1538 if (compilationFailed) return; | |
| 1539 if (!showPackageWarnings && !suppressWarnings) { | 1552 if (!showPackageWarnings && !suppressWarnings) { |
| 1540 suppressedWarnings.forEach((Uri uri, SuppressionInfo info) { | 1553 suppressedWarnings.forEach((Uri uri, SuppressionInfo info) { |
| 1541 MessageKind kind = MessageKind.HIDDEN_WARNINGS_HINTS; | 1554 MessageKind kind = MessageKind.HIDDEN_WARNINGS_HINTS; |
| 1542 if (info.warnings == 0) { | 1555 if (info.warnings == 0) { |
| 1543 kind = MessageKind.HIDDEN_HINTS; | 1556 kind = MessageKind.HIDDEN_HINTS; |
| 1544 } else if (info.hints == 0) { | 1557 } else if (info.hints == 0) { |
| 1545 kind = MessageKind.HIDDEN_WARNINGS; | 1558 kind = MessageKind.HIDDEN_WARNINGS; |
| 1546 } | 1559 } |
| 1547 reportDiagnostic(null, | 1560 reportDiagnostic(null, |
| 1548 kind.message({'warnings': info.warnings, | 1561 kind.message({'warnings': info.warnings, |
| 1549 'hints': info.hints, | 1562 'hints': info.hints, |
| 1550 'uri': uri}, | 1563 'uri': uri}, |
| 1551 terseDiagnostics), | 1564 terseDiagnostics), |
| 1552 api.Diagnostic.HINT); | 1565 api.Diagnostic.HINT); |
| 1553 }); | 1566 }); |
| 1554 } | 1567 } |
| 1555 if (analyzeOnly) { | 1568 if (analyzeOnly) { |
| 1556 if (!analyzeAll) { | 1569 if (!analyzeAll && !compilationFailed) { |
| 1557 // No point in reporting unused code when [analyzeAll] is true: all | 1570 // No point in reporting unused code when [analyzeAll] is true: all |
| 1558 // code is artificially used. | 1571 // code is artificially used. |
| 1572 // If compilation failed, it is possible that the error prevents the |
| 1573 // compiler from analyzing all the code. |
| 1559 reportUnusedCode(); | 1574 reportUnusedCode(); |
| 1560 } | 1575 } |
| 1561 return; | 1576 return; |
| 1562 } | 1577 } |
| 1563 assert(mainFunction != null); | 1578 assert(mainFunction != null); |
| 1564 phase = PHASE_DONE_RESOLVING; | 1579 phase = PHASE_DONE_RESOLVING; |
| 1565 | 1580 |
| 1566 world.populate(); | 1581 world.populate(); |
| 1567 // Compute whole-program-knowledge that the backend needs. (This might | 1582 // Compute whole-program-knowledge that the backend needs. (This might |
| 1568 // require the information computed in [world.populate].) | 1583 // require the information computed in [world.populate].) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1590 backend.enableNoSuchMethod(null, enqueuer.codegen); | 1605 backend.enableNoSuchMethod(null, enqueuer.codegen); |
| 1591 } | 1606 } |
| 1592 if (compileAll) { | 1607 if (compileAll) { |
| 1593 libraryLoader.libraries.forEach((LibraryElement library) { | 1608 libraryLoader.libraries.forEach((LibraryElement library) { |
| 1594 fullyEnqueueLibrary(library, enqueuer.codegen); | 1609 fullyEnqueueLibrary(library, enqueuer.codegen); |
| 1595 }); | 1610 }); |
| 1596 } | 1611 } |
| 1597 processQueue(enqueuer.codegen, mainFunction); | 1612 processQueue(enqueuer.codegen, mainFunction); |
| 1598 enqueuer.codegen.logSummary(log); | 1613 enqueuer.codegen.logSummary(log); |
| 1599 | 1614 |
| 1600 if (compilationFailed) return; | |
| 1601 | |
| 1602 int programSize = backend.assembleProgram(); | 1615 int programSize = backend.assembleProgram(); |
| 1603 | 1616 |
| 1604 if (dumpInfo) { | 1617 if (dumpInfo) { |
| 1605 dumpInfoTask.reportSize(programSize); | 1618 dumpInfoTask.reportSize(programSize); |
| 1606 dumpInfoTask.dumpInfo(); | 1619 dumpInfoTask.dumpInfo(); |
| 1607 } | 1620 } |
| 1608 | 1621 |
| 1609 checkQueues(); | 1622 checkQueues(); |
| 1610 } | 1623 } |
| 1611 | 1624 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 } | 1668 } |
| 1656 world.addToWorkList(main); | 1669 world.addToWorkList(main); |
| 1657 } | 1670 } |
| 1658 if (verbose) { | 1671 if (verbose) { |
| 1659 progress.reset(); | 1672 progress.reset(); |
| 1660 } | 1673 } |
| 1661 world.forEach((WorkItem work) { | 1674 world.forEach((WorkItem work) { |
| 1662 withCurrentElement(work.element, () => work.run(this, world)); | 1675 withCurrentElement(work.element, () => work.run(this, world)); |
| 1663 }); | 1676 }); |
| 1664 world.queueIsClosed = true; | 1677 world.queueIsClosed = true; |
| 1665 if (compilationFailed) return; | 1678 assert(compilationFailed || world.checkNoEnqueuedInvokedInstanceMethods()); |
| 1666 assert(world.checkNoEnqueuedInvokedInstanceMethods()); | |
| 1667 } | 1679 } |
| 1668 | 1680 |
| 1669 /** | 1681 /** |
| 1670 * Perform various checks of the queues. This includes checking that | 1682 * Perform various checks of the queues. This includes checking that |
| 1671 * the queues are empty (nothing was added after we stopped | 1683 * the queues are empty (nothing was added after we stopped |
| 1672 * processing the queues). Also compute the number of methods that | 1684 * processing the queues). Also compute the number of methods that |
| 1673 * were resolved, but not compiled (aka excess resolution). | 1685 * were resolved, but not compiled (aka excess resolution). |
| 1674 */ | 1686 */ |
| 1675 checkQueues() { | 1687 checkQueues() { |
| 1676 for (Enqueuer world in [enqueuer.resolution, enqueuer.codegen]) { | 1688 for (Enqueuer world in [enqueuer.resolution, enqueuer.codegen]) { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 void forgetElement(Element element) { | 2079 void forgetElement(Element element) { |
| 2068 enqueuer.forgetElement(element); | 2080 enqueuer.forgetElement(element); |
| 2069 if (element is MemberElement) { | 2081 if (element is MemberElement) { |
| 2070 for (Element closure in element.nestedClosures) { | 2082 for (Element closure in element.nestedClosures) { |
| 2071 // TODO(ahe): It would be nice to reuse names of nested closures. | 2083 // TODO(ahe): It would be nice to reuse names of nested closures. |
| 2072 closureToClassMapper.forgetElement(closure); | 2084 closureToClassMapper.forgetElement(closure); |
| 2073 } | 2085 } |
| 2074 } | 2086 } |
| 2075 backend.forgetElement(element); | 2087 backend.forgetElement(element); |
| 2076 } | 2088 } |
| 2089 |
| 2090 bool elementHasCompileTimeError(Element element) { |
| 2091 return elementsWithCompileTimeErrors.contains(element); |
| 2092 } |
| 2077 } | 2093 } |
| 2078 | 2094 |
| 2079 class CompilerTask { | 2095 class CompilerTask { |
| 2080 final Compiler compiler; | 2096 final Compiler compiler; |
| 2081 final Stopwatch watch; | 2097 final Stopwatch watch; |
| 2082 UserTag profilerTag; | 2098 UserTag profilerTag; |
| 2083 | 2099 |
| 2084 CompilerTask(Compiler compiler) | 2100 CompilerTask(Compiler compiler) |
| 2085 : this.compiler = compiler, | 2101 : this.compiler = compiler, |
| 2086 watch = (compiler.verbose) ? new Stopwatch() : null; | 2102 watch = (compiler.verbose) ? new Stopwatch() : null; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2358 InterfaceType get nullType => nullClass.computeType(compiler); | 2374 InterfaceType get nullType => nullClass.computeType(compiler); |
| 2359 | 2375 |
| 2360 @override | 2376 @override |
| 2361 InterfaceType get numType => numClass.computeType(compiler); | 2377 InterfaceType get numType => numClass.computeType(compiler); |
| 2362 | 2378 |
| 2363 @override | 2379 @override |
| 2364 InterfaceType get stringType => stringClass.computeType(compiler); | 2380 InterfaceType get stringType => stringClass.computeType(compiler); |
| 2365 } | 2381 } |
| 2366 | 2382 |
| 2367 typedef void InternalErrorFunction(Spannable location, String message); | 2383 typedef void InternalErrorFunction(Spannable location, String message); |
| OLD | NEW |