OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.src.context.context; | 5 library analyzer.src.context.context; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/instrumentation/instrumentation.dart'; | 10 import 'package:analyzer/instrumentation/instrumentation.dart'; |
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 // model. | 1044 // model. |
1045 throw new UnimplementedError( | 1045 throw new UnimplementedError( |
1046 'Not supported in the new task model; use parseHtmlDocument instead.'); | 1046 'Not supported in the new task model; use parseHtmlDocument instead.'); |
1047 } | 1047 } |
1048 | 1048 |
1049 @override | 1049 @override |
1050 AnalysisResult performAnalysisTask() { | 1050 AnalysisResult performAnalysisTask() { |
1051 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() { | 1051 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() { |
1052 _evaluatePendingFutures(); | 1052 _evaluatePendingFutures(); |
1053 bool done = !driver.performAnalysisTask(); | 1053 bool done = !driver.performAnalysisTask(); |
1054 if (done) { | |
1055 done = !_validateCacheConsistency(); | |
1056 } | |
1057 List<ChangeNotice> notices = _getChangeNotices(done); | 1054 List<ChangeNotice> notices = _getChangeNotices(done); |
1058 if (notices != null) { | 1055 if (notices != null) { |
1059 int noticeCount = notices.length; | 1056 int noticeCount = notices.length; |
1060 for (int i = 0; i < noticeCount; i++) { | 1057 for (int i = 0; i < noticeCount; i++) { |
1061 ChangeNotice notice = notices[i]; | 1058 ChangeNotice notice = notices[i]; |
1062 _notifyErrors(notice.source, notice.errors, notice.lineInfo); | 1059 _notifyErrors(notice.source, notice.errors, notice.lineInfo); |
1063 } | 1060 } |
1064 } | 1061 } |
1065 return new AnalysisResult(notices, -1, '', -1); | 1062 return new AnalysisResult(notices, -1, '', -1); |
1066 }); | 1063 }); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 if (source.isInSystemLibrary) { | 1177 if (source.isInSystemLibrary) { |
1181 return _options.generateSdkErrors; | 1178 return _options.generateSdkErrors; |
1182 } else if (!entry.explicitlyAdded) { | 1179 } else if (!entry.explicitlyAdded) { |
1183 return _options.generateImplicitErrors; | 1180 return _options.generateImplicitErrors; |
1184 } else { | 1181 } else { |
1185 return true; | 1182 return true; |
1186 } | 1183 } |
1187 } | 1184 } |
1188 | 1185 |
1189 @override | 1186 @override |
| 1187 bool validateSourceCacheConsistency(Source source) { |
| 1188 CacheEntry entry = _cache.get(source); |
| 1189 if (entry != null) { |
| 1190 int sourceTime = getModificationStamp(source); |
| 1191 if (sourceTime != entry.modificationTime) { |
| 1192 _sourceChanged(source); |
| 1193 return true; |
| 1194 } |
| 1195 if (entry.exception != null) { |
| 1196 if (!exists(source)) { |
| 1197 if (getLibrariesContaining(source).isEmpty && |
| 1198 getLibrariesDependingOn(source).isEmpty) { |
| 1199 _cache.remove(source); |
| 1200 } |
| 1201 } |
| 1202 } |
| 1203 } |
| 1204 return false; |
| 1205 } |
| 1206 |
| 1207 @override |
1190 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, | 1208 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, |
1191 DataDescriptor rowDesc, CacheState state)) { | 1209 DataDescriptor rowDesc, CacheState state)) { |
1192 // TODO(brianwilkerson) Figure out where this is used and either remove it | 1210 // TODO(brianwilkerson) Figure out where this is used and either remove it |
1193 // or adjust the call sites to use CacheEntry's. | 1211 // or adjust the call sites to use CacheEntry's. |
1194 // bool hintsEnabled = _options.hint; | 1212 // bool hintsEnabled = _options.hint; |
1195 // bool lintsEnabled = _options.lint; | 1213 // bool lintsEnabled = _options.lint; |
1196 // MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator()
; | 1214 // MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator()
; |
1197 // while (iterator.moveNext()) { | 1215 // while (iterator.moveNext()) { |
1198 // Source source = iterator.key; | 1216 // Source source = iterator.key; |
1199 // cache.CacheEntry entry = iterator.value; | 1217 // cache.CacheEntry entry = iterator.value; |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 // entry.getState(HtmlEntry.RESOLVED_UNIT); | 1594 // entry.getState(HtmlEntry.RESOLVED_UNIT); |
1577 // if (resolvedUnitState == CacheState.INVALID || | 1595 // if (resolvedUnitState == CacheState.INVALID || |
1578 // (isPriority && resolvedUnitState == CacheState.FLUSHED)) { | 1596 // (isPriority && resolvedUnitState == CacheState.FLUSHED)) { |
1579 // sources.add(source); | 1597 // sources.add(source); |
1580 // return; | 1598 // return; |
1581 // } | 1599 // } |
1582 } | 1600 } |
1583 } | 1601 } |
1584 | 1602 |
1585 /** | 1603 /** |
1586 * Log the given debugging [message]. | |
1587 */ | |
1588 void _logInformation(String message) { | |
1589 AnalysisEngine.instance.logger.logInformation(message); | |
1590 } | |
1591 | |
1592 /** | |
1593 * Notify all of the analysis listeners that the errors associated with the | 1604 * Notify all of the analysis listeners that the errors associated with the |
1594 * given [source] has been updated to the given [errors]. | 1605 * given [source] has been updated to the given [errors]. |
1595 */ | 1606 */ |
1596 void _notifyErrors( | 1607 void _notifyErrors( |
1597 Source source, List<AnalysisError> errors, LineInfo lineInfo) { | 1608 Source source, List<AnalysisError> errors, LineInfo lineInfo) { |
1598 int count = _listeners.length; | 1609 int count = _listeners.length; |
1599 for (int i = 0; i < count; i++) { | 1610 for (int i = 0; i < count; i++) { |
1600 _listeners[i].computedErrors(this, source, errors, lineInfo); | 1611 _listeners[i].computedErrors(this, source, errors, lineInfo); |
1601 } | 1612 } |
1602 } | 1613 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 notice.resolvedDartUnit = oldUnit; | 1774 notice.resolvedDartUnit = oldUnit; |
1764 AnalysisErrorInfo errorInfo = getErrors(unitSource); | 1775 AnalysisErrorInfo errorInfo = getErrors(unitSource); |
1765 notice.setErrors(errorInfo.errors, errorInfo.lineInfo); | 1776 notice.setErrors(errorInfo.errors, errorInfo.lineInfo); |
1766 } | 1777 } |
1767 // schedule | 1778 // schedule |
1768 dartWorkManager.unitIncrementallyResolved(librarySource, unitSource); | 1779 dartWorkManager.unitIncrementallyResolved(librarySource, unitSource); |
1769 // OK | 1780 // OK |
1770 return true; | 1781 return true; |
1771 }); | 1782 }); |
1772 } | 1783 } |
1773 | |
1774 /** | |
1775 * Check the cache for any invalid entries (entries whose modification time | |
1776 * does not match the modification time of the source associated with the | |
1777 * entry). Invalid entries will be marked as invalid so that the source will | |
1778 * be re-analyzed. Return `true` if at least one entry was invalid. | |
1779 */ | |
1780 bool _validateCacheConsistency() { | |
1781 int consistencyCheckStart = JavaSystem.nanoTime(); | |
1782 HashSet<Source> changedSources = new HashSet<Source>(); | |
1783 HashSet<Source> missingSources = new HashSet<Source>(); | |
1784 for (Source source in _cache.sources) { | |
1785 CacheEntry entry = _cache.get(source); | |
1786 int sourceTime = getModificationStamp(source); | |
1787 if (sourceTime != entry.modificationTime) { | |
1788 changedSources.add(source); | |
1789 } | |
1790 if (entry.exception != null) { | |
1791 if (!exists(source)) { | |
1792 missingSources.add(source); | |
1793 } | |
1794 } | |
1795 } | |
1796 for (Source source in changedSources) { | |
1797 _sourceChanged(source); | |
1798 } | |
1799 int removalCount = 0; | |
1800 for (Source source in missingSources) { | |
1801 if (getLibrariesContaining(source).isEmpty && | |
1802 getLibrariesDependingOn(source).isEmpty) { | |
1803 _cache.remove(source); | |
1804 removalCount++; | |
1805 } | |
1806 } | |
1807 int consistencyCheckEnd = JavaSystem.nanoTime(); | |
1808 if (changedSources.length > 0 || missingSources.length > 0) { | |
1809 StringBuffer buffer = new StringBuffer(); | |
1810 buffer.write("Consistency check took "); | |
1811 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0); | |
1812 buffer.writeln(" ms and found"); | |
1813 buffer.write(" "); | |
1814 buffer.write(changedSources.length); | |
1815 buffer.writeln(" inconsistent entries"); | |
1816 buffer.write(" "); | |
1817 buffer.write(missingSources.length); | |
1818 buffer.write(" missing sources ("); | |
1819 buffer.write(removalCount); | |
1820 buffer.writeln(" removed"); | |
1821 for (Source source in missingSources) { | |
1822 buffer.write(" "); | |
1823 buffer.writeln(source.fullName); | |
1824 } | |
1825 _logInformation(buffer.toString()); | |
1826 } | |
1827 return changedSources.length > 0; | |
1828 } | |
1829 } | 1784 } |
1830 | 1785 |
1831 /** | 1786 /** |
1832 * An object that manages the partitions that can be shared between analysis | 1787 * An object that manages the partitions that can be shared between analysis |
1833 * contexts. | 1788 * contexts. |
1834 */ | 1789 */ |
1835 class PartitionManager { | 1790 class PartitionManager { |
1836 /** | 1791 /** |
1837 * A table mapping SDK's to the partitions used for those SDK's. | 1792 * A table mapping SDK's to the partitions used for those SDK's. |
1838 */ | 1793 */ |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2007 new PendingFuture<T>(_context, target, computeValue); | 1962 new PendingFuture<T>(_context, target, computeValue); |
2008 if (!pendingFuture.evaluate(entry)) { | 1963 if (!pendingFuture.evaluate(entry)) { |
2009 _context._pendingFutureTargets | 1964 _context._pendingFutureTargets |
2010 .putIfAbsent(target, () => <PendingFuture>[]) | 1965 .putIfAbsent(target, () => <PendingFuture>[]) |
2011 .add(pendingFuture); | 1966 .add(pendingFuture); |
2012 scheduleComputation(); | 1967 scheduleComputation(); |
2013 } | 1968 } |
2014 return pendingFuture.future; | 1969 return pendingFuture.future; |
2015 } | 1970 } |
2016 } | 1971 } |
OLD | NEW |