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