Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: pkg/analyzer/lib/src/generated/engine.dart

Issue 909493004: Stop re-analyzing everything when adding a file (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/engine.dart
diff --git a/pkg/analyzer/lib/src/generated/engine.dart b/pkg/analyzer/lib/src/generated/engine.dart
index 67a7a2309d2abe3fb053a2c1faf7df135e2b0609..454f07113111c750b3daa38b78e9038a9e33aec4 100644
--- a/pkg/analyzer/lib/src/generated/engine.dart
+++ b/pkg/analyzer/lib/src/generated/engine.dart
@@ -1537,11 +1537,8 @@ class AnalysisContextImpl implements InternalAnalysisContext {
//
// Then determine which cached results are no longer valid.
//
- bool addedDartSource = false;
for (Source source in changeSet.addedSources) {
- if (_sourceAvailable(source)) {
- addedDartSource = true;
- }
+ _sourceAvailable(source);
}
for (Source source in changeSet.changedSources) {
if (_contentCache.getContents(source) != null) {
@@ -1570,36 +1567,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
for (Source source in removedSources) {
_sourceRemoved(source);
}
- if (addedDartSource) {
- // TODO(brianwilkerson) This is hugely inefficient, but we need to
- // re-analyze any libraries that might have been referencing the
- // not-yet-existing source that was just added. Longer term we need to
- // keep track of which libraries are referencing non-existing sources and
- // only re-analyze those libraries.
-// logInformation("Added Dart sources, invalidating all resolution information");
- List<Source> sourcesToInvalidate = new List<Source>();
- MapIterator<Source, SourceEntry> iterator = _cache.iterator();
- while (iterator.moveNext()) {
- Source source = iterator.key;
- SourceEntry sourceEntry = iterator.value;
- if (!source.isInSystemLibrary &&
- (sourceEntry is DartEntry || sourceEntry is HtmlEntry)) {
- sourcesToInvalidate.add(source);
- }
- }
- int count = sourcesToInvalidate.length;
- for (int i = 0; i < count; i++) {
- Source source = sourcesToInvalidate[i];
- SourceEntry entry = _getReadableSourceEntry(source);
- if (entry is DartEntry) {
- entry.invalidateParseInformation();
- _workManager.add(source, _computePriority(entry));
- } else if (entry is HtmlEntry) {
- entry.invalidateParseInformation();
- _workManager.add(source, SourcePriority.HTML);
- }
- }
- }
_onSourcesChangedController.add(new SourcesChangedEvent(changeSet));
}
@@ -4441,27 +4408,46 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
/**
- * Record the results produced by performing a [task] and return the cache
- * entry associated with the results.
+ * Given that the given [source] (with the corresponding [sourceEntry]) has
+ * been invalidated, invalidate all of the libraries that depend on it.
*/
- DartEntry _recordBuildUnitElementTask(BuildUnitElementTask task) {
- Source source = task.source;
- Source library = task.library;
- DartEntry dartEntry = _cache.get(source);
- CaughtException thrownException = task.exception;
- if (thrownException != null) {
- dartEntry.recordBuildElementErrorInLibrary(library, thrownException);
- throw new AnalysisException('<rethrow>', thrownException);
+ void _propagateInvalidation(Source source, SourceEntry sourceEntry) {
+ if (sourceEntry is HtmlEntry) {
+ HtmlEntry htmlEntry = sourceEntry;
+ htmlEntry.modificationTime = getModificationStamp(source);
+ htmlEntry.invalidateAllInformation();
+ _cache.removedAst(source);
+ _workManager.add(source, SourcePriority.HTML);
+ } else if (sourceEntry is DartEntry) {
+ List<Source> containingLibraries = getLibrariesContaining(source);
+ List<Source> dependentLibraries = getLibrariesDependingOn(source);
+ HashSet<Source> librariesToInvalidate = new HashSet<Source>();
+ for (Source containingLibrary in containingLibraries) {
+ _computeAllLibrariesDependingOn(
+ containingLibrary,
+ librariesToInvalidate);
+ }
+ for (Source dependentLibrary in dependentLibraries) {
+ _computeAllLibrariesDependingOn(
+ dependentLibrary,
+ librariesToInvalidate);
+ }
+ for (Source library in librariesToInvalidate) {
+ _invalidateLibraryResolution(library);
+ }
+ DartEntry dartEntry = _cache.get(source);
+ _removeFromParts(source, dartEntry);
+ dartEntry.modificationTime = getModificationStamp(source);
+ dartEntry.invalidateAllInformation();
+ _cache.removedAst(source);
+ _workManager.add(source, SourcePriority.UNKNOWN);
+ }
+ // reset unit in the notification, it is out of date now
+ ChangeNoticeImpl notice = _pendingNotices[source];
+ if (notice != null) {
+ notice.resolvedDartUnit = null;
+ notice.resolvedHtmlUnit = null;
}
- dartEntry.setValueInLibrary(DartEntry.BUILT_UNIT, library, task.unit);
- dartEntry.setValueInLibrary(
- DartEntry.BUILT_ELEMENT,
- library,
- task.unitElement);
- ChangeNoticeImpl notice = _getNotice(source);
- LineInfo lineInfo = dartEntry.getValue(SourceEntry.LINE_INFO);
- notice.setErrors(dartEntry.allErrors, lineInfo);
- return dartEntry;
}
// /**
@@ -4543,6 +4529,30 @@ class AnalysisContextImpl implements InternalAnalysisContext {
// }
/**
+ * Record the results produced by performing a [task] and return the cache
+ * entry associated with the results.
+ */
+ DartEntry _recordBuildUnitElementTask(BuildUnitElementTask task) {
+ Source source = task.source;
+ Source library = task.library;
+ DartEntry dartEntry = _cache.get(source);
+ CaughtException thrownException = task.exception;
+ if (thrownException != null) {
+ dartEntry.recordBuildElementErrorInLibrary(library, thrownException);
+ throw new AnalysisException('<rethrow>', thrownException);
+ }
+ dartEntry.setValueInLibrary(DartEntry.BUILT_UNIT, library, task.unit);
+ dartEntry.setValueInLibrary(
+ DartEntry.BUILT_ELEMENT,
+ library,
+ task.unitElement);
+ ChangeNoticeImpl notice = _getNotice(source);
+ LineInfo lineInfo = dartEntry.getValue(SourceEntry.LINE_INFO);
+ notice.setErrors(dartEntry.allErrors, lineInfo);
+ return dartEntry;
+ }
+
+ /**
* Given a cache entry and a library element, record the library element and other information
* gleaned from the element in the cache entry.
*
@@ -4956,12 +4966,12 @@ class AnalysisContextImpl implements InternalAnalysisContext {
* @param source the source that has been added
* @return `true` if the new source is a Dart file
*/
- bool _sourceAvailable(Source source) {
+ void _sourceAvailable(Source source) {
SourceEntry sourceEntry = _cache.get(source);
if (sourceEntry == null) {
sourceEntry = _createSourceEntry(source, true);
} else {
- _sourceChanged(source);
+ _propagateInvalidation(source, sourceEntry);
sourceEntry = _cache.get(source);
}
if (sourceEntry is HtmlEntry) {
@@ -4969,7 +4979,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
} else if (sourceEntry is DartEntry) {
_workManager.add(source, _computePriority(sourceEntry as DartEntry));
}
- return sourceEntry is DartEntry;
}
/**
@@ -4986,36 +4995,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
// to invalidate it again.
return;
}
- if (sourceEntry is HtmlEntry) {
- HtmlEntry htmlEntry = sourceEntry;
- htmlEntry.modificationTime = getModificationStamp(source);
- htmlEntry.invalidateAllInformation();
- _cache.removedAst(source);
- _workManager.add(source, SourcePriority.HTML);
- } else if (sourceEntry is DartEntry) {
- List<Source> containingLibraries = getLibrariesContaining(source);
- HashSet<Source> librariesToInvalidate = new HashSet<Source>();
- for (Source containingLibrary in containingLibraries) {
- _computeAllLibrariesDependingOn(
- containingLibrary,
- librariesToInvalidate);
- }
- for (Source library in librariesToInvalidate) {
- _invalidateLibraryResolution(library);
- }
- DartEntry dartEntry = _cache.get(source);
- _removeFromParts(source, dartEntry);
- dartEntry.modificationTime = getModificationStamp(source);
- dartEntry.invalidateAllInformation();
- _cache.removedAst(source);
- _workManager.add(source, SourcePriority.UNKNOWN);
- }
- // reset unit in the notification, it is out of date now
- ChangeNoticeImpl notice = _pendingNotices[source];
- if (notice != null) {
- notice.resolvedDartUnit = null;
- notice.resolvedHtmlUnit = null;
- }
+ _propagateInvalidation(source, sourceEntry);
}
/**
@@ -11844,18 +11824,6 @@ abstract class SourceEntry {
result.value = value == null ? descriptor.defaultValue : value;
}
- /**
- * Increment the count of the number of times that data represented by the
- * given [descriptor] was transitioned from the current state (as found in the
- * given [result] to a valid state.
- */
- static void countTransition(DataDescriptor descriptor, CachedResult result) {
- Map<CacheState, int> countMap =
- transitionMap.putIfAbsent(descriptor, () => new HashMap<CacheState, int>());
- int count = countMap[result.state];
- countMap[result.state] = count == null ? 1 : count + 1;
- }
-
@override
String toString() {
StringBuffer buffer = new StringBuffer();
@@ -12006,6 +11974,18 @@ abstract class SourceEntry {
buffer.write(" = ");
buffer.write(result == null ? CacheState.INVALID : result.state);
}
+
+ /**
+ * Increment the count of the number of times that data represented by the
+ * given [descriptor] was transitioned from the current state (as found in the
+ * given [result] to a valid state.
+ */
+ static void countTransition(DataDescriptor descriptor, CachedResult result) {
+ Map<CacheState, int> countMap =
+ transitionMap.putIfAbsent(descriptor, () => new HashMap<CacheState, int>());
+ int count = countMap[result.state];
+ countMap[result.state] = count == null ? 1 : count + 1;
+ }
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698