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

Side by Side 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 unified diff | Download patch
OLDNEW
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.task.dart_work_manager; 5 library analyzer.src.task.dart_work_manager;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/generated/engine.dart' 10 import 'package:analyzer/src/generated/engine.dart'
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 * Initialize a newly created manager. 83 * Initialize a newly created manager.
84 */ 84 */
85 DartWorkManager(this.context); 85 DartWorkManager(this.context);
86 86
87 /** 87 /**
88 * Returns the correctly typed result of `context.analysisCache`. 88 * Returns the correctly typed result of `context.analysisCache`.
89 */ 89 */
90 AnalysisCache get analysisCache => context.analysisCache; 90 AnalysisCache get analysisCache => context.analysisCache;
91 91
92 /** 92 /**
93 * The partition that contains analysis results that are not shared with other
94 * contexts.
95 */
96 CachePartition get privateAnalysisCachePartition =>
97 context.privateAnalysisCachePartition;
98
99 /**
93 * Specifies that the client want the given [result] of the given [target] 100 * Specifies that the client want the given [result] of the given [target]
94 * to be computed with priority. 101 * to be computed with priority.
95 */ 102 */
96 void addPriorityResult(AnalysisTarget target, ResultDescriptor result) { 103 void addPriorityResult(AnalysisTarget target, ResultDescriptor result) {
97 priorityResultQueue.add(new TargetedResult(target, result)); 104 priorityResultQueue.add(new TargetedResult(target, result));
98 } 105 }
99 106
100 /** 107 /**
101 * Notifies the manager about changes in the explicit source list. 108 * Notifies the manager about changes in the explicit source list.
102 */ 109 */
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 WorkOrderPriority getNextResultPriority() { 243 WorkOrderPriority getNextResultPriority() {
237 if (priorityResultQueue.isNotEmpty) { 244 if (priorityResultQueue.isNotEmpty) {
238 return WorkOrderPriority.PRIORITY; 245 return WorkOrderPriority.PRIORITY;
239 } 246 }
240 if (unknownSourceQueue.isNotEmpty || librarySourceQueue.isNotEmpty) { 247 if (unknownSourceQueue.isNotEmpty || librarySourceQueue.isNotEmpty) {
241 return WorkOrderPriority.NORMAL; 248 return WorkOrderPriority.NORMAL;
242 } 249 }
243 return WorkOrderPriority.NONE; 250 return WorkOrderPriority.NONE;
244 } 251 }
245 252
253 /**
254 * Notifies the manager about analysis options changes.
255 */
256 void onAnalysisOptionsChanged() {
257 _invalidateAllLocalResolutionInformation(false);
258 }
259
260 /**
261 * Notifies the manager about [SourceFactory] changes.
262 */
263 void onSourceFactoryChanged() {
264 _invalidateAllLocalResolutionInformation(true);
265 }
266
246 @override 267 @override
247 void resultsComputed( 268 void resultsComputed(
248 AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) { 269 AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) {
249 // Organize sources. 270 // Organize sources.
250 if (_isDartSource(target)) { 271 if (_isDartSource(target)) {
251 SourceKind kind = outputs[SOURCE_KIND]; 272 SourceKind kind = outputs[SOURCE_KIND];
252 if (kind != null) { 273 if (kind != null) {
253 unknownSourceQueue.remove(target); 274 unknownSourceQueue.remove(target);
254 if (kind == SourceKind.LIBRARY && 275 if (kind == SourceKind.LIBRARY &&
255 context.shouldErrorsBeAnalyzed(target, null)) { 276 context.shouldErrorsBeAnalyzed(target, null)) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 context.getNotice(source).setErrors(info.errors, info.lineInfo); 325 context.getNotice(source).setErrors(info.errors, info.lineInfo);
305 } 326 }
306 } 327 }
307 } 328 }
308 329
309 void unitIncrementallyResolved(Source librarySource, Source unitSource) { 330 void unitIncrementallyResolved(Source librarySource, Source unitSource) {
310 librarySourceQueue.add(librarySource); 331 librarySourceQueue.add(librarySource);
311 } 332 }
312 333
313 /** 334 /**
335 * Invalidate all of the resolution results computed by this context. The flag
336 * [invalidateUris] should be `true` if the cached results of converting URIs
337 * to source files should also be invalidated.
338 */
339 void _invalidateAllLocalResolutionInformation(bool invalidateUris) {
340 CachePartition partition = privateAnalysisCachePartition;
341 // Prepare targets and values to invalidate.
342 List<Source> dartSources = <Source>[];
343 List<LibrarySpecificUnit> unitTargets = <LibrarySpecificUnit>[];
344 MapIterator<AnalysisTarget, CacheEntry> iterator = partition.iterator();
345 while (iterator.moveNext()) {
346 AnalysisTarget target = iterator.key;
347 // Optionally gather Dart sources to invalidate URIs resolution.
348 if (invalidateUris && _isDartSource(target)) {
349 dartSources.add(target);
350 }
351 // LibrarySpecificUnit(s) are roots of Dart resolution.
352 // When one is invalidated, invalidation is propagated to all resolution.
353 if (target is LibrarySpecificUnit) {
354 unitTargets.add(target);
355 Source library = target.library;
356 if (context.exists(library)) {
357 librarySourceQueue.add(library);
358 }
359 }
360 }
361 // Invalidate targets and values.
362 unitTargets.forEach(partition.remove);
363 for (Source dartSource in dartSources) {
364 CacheEntry entry = partition.get(dartSource);
365 if (dartSource != null) {
366 // TODO(scheglov) we invalidate too much.
367 // Would be nice to invalidate just URLs resolution.
368 entry.setState(PARSED_UNIT, CacheState.INVALID);
369 entry.setState(IMPORTED_LIBRARIES, CacheState.INVALID);
370 entry.setState(EXPLICITLY_IMPORTED_LIBRARIES, CacheState.INVALID);
371 entry.setState(EXPORTED_LIBRARIES, CacheState.INVALID);
372 entry.setState(INCLUDED_PARTS, CacheState.INVALID);
373 }
374 }
375 }
376
377 /**
314 * Invalidate [CONTAINING_LIBRARIES] for the given [source]. 378 * Invalidate [CONTAINING_LIBRARIES] for the given [source].
315 * [CONTAINING_LIBRARIES] does not have dependencies, so we manage it here. 379 * [CONTAINING_LIBRARIES] does not have dependencies, so we manage it here.
316 * The [source] may be a part, or a library whose contents is updated so 380 * The [source] may be a part, or a library whose contents is updated so
317 * will be a part. 381 * will be a part.
318 */ 382 */
319 void _invalidateContainingLibraries(Source source) { 383 void _invalidateContainingLibraries(Source source) {
320 CacheEntry entry = analysisCache.get(source); 384 CacheEntry entry = analysisCache.get(source);
321 if (entry != null) { 385 if (entry != null) {
322 entry.setState(CONTAINING_LIBRARIES, CacheState.INVALID); 386 entry.setState(CONTAINING_LIBRARIES, CacheState.INVALID);
323 } 387 }
(...skipping 23 matching lines...) Expand all
347 } 411 }
348 } 412 }
349 } 413 }
350 _invalidateContainingLibraries(library); 414 _invalidateContainingLibraries(library);
351 } 415 }
352 416
353 static bool _isDartSource(AnalysisTarget target) { 417 static bool _isDartSource(AnalysisTarget target) {
354 return target is Source && AnalysisEngine.isDartFileName(target.fullName); 418 return target is Source && AnalysisEngine.isDartFileName(target.fullName);
355 } 419 }
356 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698