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

Unified Diff: pkg/analyzer/lib/src/task/dart_work_manager.dart

Issue 1167483004: Invalidate resolution of analysisOptions/sourceFactory changes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
Index: pkg/analyzer/lib/src/task/dart_work_manager.dart
diff --git a/pkg/analyzer/lib/src/task/dart_work_manager.dart b/pkg/analyzer/lib/src/task/dart_work_manager.dart
index 6df4c7e68ef7a15ca3213da1d03b320e6c31583d..6700e1f56d397f06e52d425280ccd9197a750521 100644
--- a/pkg/analyzer/lib/src/task/dart_work_manager.dart
+++ b/pkg/analyzer/lib/src/task/dart_work_manager.dart
@@ -90,6 +90,13 @@ class DartWorkManager implements WorkManager {
AnalysisCache get analysisCache => context.analysisCache;
/**
+ * The partition that contains analysis results that are not shared with other
+ * contexts.
+ */
+ CachePartition get privateAnalysisCachePartition =>
+ context.privateAnalysisCachePartition;
+
+ /**
* Specifies that the client want the given [result] of the given [target]
* to be computed with priority.
*/
@@ -243,6 +250,20 @@ class DartWorkManager implements WorkManager {
return WorkOrderPriority.NONE;
}
+ /**
+ * Notifies the manager about analysis options changes.
+ */
+ void onAnalysisOptionsChanged() {
+ _invalidateAllLocalResolutionInformation(false);
+ }
+
+ /**
+ * Notifies the manager about [SourceFactory] changes.
+ */
+ void onSourceFactoryChanged() {
+ _invalidateAllLocalResolutionInformation(true);
+ }
+
@override
void resultsComputed(
AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) {
@@ -311,6 +332,49 @@ class DartWorkManager implements WorkManager {
}
/**
+ * Invalidate all of the resolution results computed by this context. The flag
+ * [invalidateUris] should be `true` if the cached results of converting URIs
+ * to source files should also be invalidated.
+ */
+ void _invalidateAllLocalResolutionInformation(bool invalidateUris) {
+ CachePartition partition = privateAnalysisCachePartition;
+ // Prepare targets and values to invalidate.
+ List<Source> dartSources = <Source>[];
+ List<LibrarySpecificUnit> unitTargets = <LibrarySpecificUnit>[];
+ MapIterator<AnalysisTarget, CacheEntry> iterator = partition.iterator();
+ while (iterator.moveNext()) {
+ AnalysisTarget target = iterator.key;
+ // Optionally gather Dart sources to invalidate URIs resolution.
+ if (invalidateUris && _isDartSource(target)) {
+ dartSources.add(target);
+ }
+ // LibrarySpecificUnit(s) are roots of Dart resolution.
+ // When one is invalidated, invalidation is propagated to all resolution.
+ if (target is LibrarySpecificUnit) {
+ unitTargets.add(target);
+ Source library = target.library;
+ if (context.exists(library)) {
+ librarySourceQueue.add(library);
+ }
+ }
+ }
+ // Invalidate targets and values.
+ unitTargets.forEach(partition.remove);
+ for (Source dartSource in dartSources) {
+ CacheEntry entry = partition.get(dartSource);
+ if (dartSource != null) {
+ // TODO(scheglov) we invalidate too much.
+ // Would be nice to invalidate just URLs resolution.
+ entry.setState(PARSED_UNIT, CacheState.INVALID);
+ entry.setState(IMPORTED_LIBRARIES, CacheState.INVALID);
+ entry.setState(EXPLICITLY_IMPORTED_LIBRARIES, CacheState.INVALID);
+ entry.setState(EXPORTED_LIBRARIES, CacheState.INVALID);
+ entry.setState(INCLUDED_PARTS, CacheState.INVALID);
+ }
+ }
+ }
+
+ /**
* Invalidate [CONTAINING_LIBRARIES] for the given [source].
* [CONTAINING_LIBRARIES] does not have dependencies, so we manage it here.
* The [source] may be a part, or a library whose contents is updated so

Powered by Google App Engine
This is Rietveld 408576698