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

Side by Side Diff: pkg/analyzer/lib/src/task/dart_work_manager.dart

Issue 1152773002: Manage 'libraries containing part' in DartWorkManager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 * The sources whose kind we don't know yet. 60 * The sources whose kind we don't know yet.
61 */ 61 */
62 final LinkedHashSet<Source> unknownSourceQueue = new LinkedHashSet<Source>(); 62 final LinkedHashSet<Source> unknownSourceQueue = new LinkedHashSet<Source>();
63 63
64 /** 64 /**
65 * The queue of library sources to process. 65 * The queue of library sources to process.
66 */ 66 */
67 final LinkedHashSet<Source> librarySourceQueue = new LinkedHashSet<Source>(); 67 final LinkedHashSet<Source> librarySourceQueue = new LinkedHashSet<Source>();
68 68
69 /** 69 /**
70 * A table mapping library sources to the part sources they include.
71 */
72 final HashMap<Source, List<Source>> libraryPartsMap =
Brian Wilkerson 2015/05/22 16:05:42 Aren't we already keeping this in the cache? Why w
73 new HashMap<Source, List<Source>>();
74
75 /**
76 * A table mapping part sources to the library sources that include them.
77 */
78 final HashMap<Source, List<Source>> partLibrariesMap =
79 new HashMap<Source, List<Source>>();
80
81 /**
70 * Initialize a newly created manager. 82 * Initialize a newly created manager.
71 */ 83 */
72 DartWorkManager(this.context); 84 DartWorkManager(this.context);
73 85
74 /** 86 /**
75 * Returns the correctly typed result of `context.analysisCache`. 87 * Returns the correctly typed result of `context.analysisCache`.
76 */ 88 */
77 AnalysisCache get analysisCache => context.analysisCache; 89 AnalysisCache get analysisCache => context.analysisCache;
78 90
79 /** 91 /**
(...skipping 12 matching lines...) Expand all
92 addedSources = addedSources.where(_isDartSource).toList(); 104 addedSources = addedSources.where(_isDartSource).toList();
93 changedSources = changedSources.where(_isDartSource).toList(); 105 changedSources = changedSources.where(_isDartSource).toList();
94 removedSources = removedSources.where(_isDartSource).toList(); 106 removedSources = removedSources.where(_isDartSource).toList();
95 // unknown queue 107 // unknown queue
96 unknownSourceQueue.addAll(addedSources); 108 unknownSourceQueue.addAll(addedSources);
97 unknownSourceQueue.addAll(changedSources); 109 unknownSourceQueue.addAll(changedSources);
98 unknownSourceQueue.removeAll(removedSources); 110 unknownSourceQueue.removeAll(removedSources);
99 // library queue 111 // library queue
100 librarySourceQueue.removeAll(changedSources); 112 librarySourceQueue.removeAll(changedSources);
101 librarySourceQueue.removeAll(removedSources); 113 librarySourceQueue.removeAll(removedSources);
114 // parts in libraries
115 for (Source changedSource in changedSources) {
116 _onLibrarySourceChangedOrRemoved(changedSource);
117 _onPartSourceChangedOrRemoved(changedSource);
118 }
119 for (Source removedSource in removedSources) {
120 _onLibrarySourceChangedOrRemoved(removedSource);
121 _onPartSourceChangedOrRemoved(removedSource);
122 }
102 // Some of the libraries might have been invalidated, reschedule them. 123 // Some of the libraries might have been invalidated, reschedule them.
103 { 124 {
104 MapIterator<AnalysisTarget, CacheEntry> iterator = 125 MapIterator<AnalysisTarget, CacheEntry> iterator =
105 analysisCache.iterator(); 126 analysisCache.iterator();
106 while (iterator.moveNext()) { 127 while (iterator.moveNext()) {
107 AnalysisTarget target = iterator.key; 128 AnalysisTarget target = iterator.key;
108 if (_isDartSource(target)) { 129 if (_isDartSource(target)) {
109 CacheEntry entry = iterator.value; 130 CacheEntry entry = iterator.value;
110 if (entry.getValue(SOURCE_KIND) == SourceKind.LIBRARY && 131 if (entry.getValue(SOURCE_KIND) == SourceKind.LIBRARY &&
111 entry.getValue(LIBRARY_ERRORS_READY) != true) { 132 entry.getValue(LIBRARY_ERRORS_READY) != true) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 for (Source library in context.getLibrariesContaining(source)) { 177 for (Source library in context.getLibrariesContaining(source)) {
157 LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source); 178 LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source);
158 for (ResultDescriptor descriptor in _UNIT_ERRORS) { 179 for (ResultDescriptor descriptor in _UNIT_ERRORS) {
159 errors.addAll(analysisCache.getValue(unit, descriptor)); 180 errors.addAll(analysisCache.getValue(unit, descriptor));
160 } 181 }
161 } 182 }
162 LineInfo lineInfo = analysisCache.getValue(source, LINE_INFO); 183 LineInfo lineInfo = analysisCache.getValue(source, LINE_INFO);
163 return new AnalysisErrorInfoImpl(errors, lineInfo); 184 return new AnalysisErrorInfoImpl(errors, lineInfo);
164 } 185 }
165 186
187 /**
188 * Returns libraries containing the given [part].
189 * Maybe empty, but not null.
190 */
191 List<Source> getLibrariesContainingPart(Source part) {
192 List<Source> libraries = partLibrariesMap[part];
193 return libraries != null ? libraries : Source.EMPTY_LIST;
194 }
195
166 @override 196 @override
167 TargetedResult getNextResult() { 197 TargetedResult getNextResult() {
168 // Try to find a priority result to compute. 198 // Try to find a priority result to compute.
169 while (priorityResultQueue.isNotEmpty) { 199 while (priorityResultQueue.isNotEmpty) {
170 TargetedResult result = priorityResultQueue.first; 200 TargetedResult result = priorityResultQueue.first;
171 if (!_needsComputing(result.target, result.result)) { 201 if (!_needsComputing(result.target, result.result)) {
172 priorityResultQueue.remove(result); 202 priorityResultQueue.remove(result);
173 continue; 203 continue;
174 } 204 }
175 return result; 205 return result;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // Organize sources. 249 // Organize sources.
220 if (_isDartSource(target)) { 250 if (_isDartSource(target)) {
221 SourceKind kind = outputs[SOURCE_KIND]; 251 SourceKind kind = outputs[SOURCE_KIND];
222 if (kind != null) { 252 if (kind != null) {
223 unknownSourceQueue.remove(target); 253 unknownSourceQueue.remove(target);
224 if (kind == SourceKind.LIBRARY) { 254 if (kind == SourceKind.LIBRARY) {
225 librarySourceQueue.add(target); 255 librarySourceQueue.add(target);
226 } 256 }
227 } 257 }
228 } 258 }
259 // Update parts in libraries.
260 if (_isDartSource(target)) {
261 Source library = target;
262 List<Source> includedParts = outputs[INCLUDED_PARTS];
263 if (includedParts != null) {
264 libraryPartsMap[library] = includedParts.toList();
Brian Wilkerson 2015/05/22 16:05:42 "includedParts" is declared to be a List. Is the d
265 for (Source part in includedParts) {
266 List<Source> libraries =
267 partLibrariesMap.putIfAbsent(part, () => <Source>[]);
268 if (!libraries.contains(library)) {
269 libraries.add(library);
270 }
271 }
272 }
273 }
229 // Update notice. 274 // Update notice.
230 if (_isDartSource(target)) { 275 if (_isDartSource(target)) {
231 bool shouldSetErrors = false; 276 bool shouldSetErrors = false;
232 outputs.forEach((ResultDescriptor descriptor, value) { 277 outputs.forEach((ResultDescriptor descriptor, value) {
233 if (descriptor == PARSED_UNIT && value != null) { 278 if (descriptor == PARSED_UNIT && value != null) {
234 context.getNotice(target).parsedDartUnit = value; 279 context.getNotice(target).parsedDartUnit = value;
235 shouldSetErrors = true; 280 shouldSetErrors = true;
236 } 281 }
237 if (_isErrorResult(descriptor)) { 282 if (_isErrorResult(descriptor)) {
238 shouldSetErrors = true; 283 shouldSetErrors = true;
(...skipping 25 matching lines...) Expand all
264 309
265 /** 310 /**
266 * Returns `true` if the given [result] of the given [target] needs 311 * Returns `true` if the given [result] of the given [target] needs
267 * computing, i.e. it is not in the valid and not in the error state. 312 * computing, i.e. it is not in the valid and not in the error state.
268 */ 313 */
269 bool _needsComputing(AnalysisTarget target, ResultDescriptor result) { 314 bool _needsComputing(AnalysisTarget target, ResultDescriptor result) {
270 CacheState state = analysisCache.getState(target, result); 315 CacheState state = analysisCache.getState(target, result);
271 return state != CacheState.VALID && state != CacheState.ERROR; 316 return state != CacheState.VALID && state != CacheState.ERROR;
272 } 317 }
273 318
319 /**
320 * The given [library] source was changed or removed.
321 * Update [libraryPartsMap] and [partLibrariesMap].
322 */
323 void _onLibrarySourceChangedOrRemoved(Source library) {
324 List<Source> parts = libraryPartsMap.remove(library);
325 if (parts != null) {
326 for (Source part in parts) {
327 List<Source> libraries = partLibrariesMap[part];
328 if (libraries != null) {
329 libraries.remove(library);
330 }
331 }
332 }
333 }
334
335 /**
336 * The given [part] source was changed or removed.
337 * Update [libraryPartsMap] and [partLibrariesMap].
338 */
339 void _onPartSourceChangedOrRemoved(Source part) {
340 List<Source> libraries = partLibrariesMap.remove(part);
341 if (libraries != null) {
342 for (Source library in libraries) {
343 List<Source> parts = libraryPartsMap[library];
344 if (parts != null) {
345 parts.remove(part);
346 }
347 }
348 }
349 }
350
274 static bool _isDartSource(AnalysisTarget target) { 351 static bool _isDartSource(AnalysisTarget target) {
275 return target is Source && AnalysisEngine.isDartFileName(target.fullName); 352 return target is Source && AnalysisEngine.isDartFileName(target.fullName);
276 } 353 }
277 354
278 static bool _isErrorResult(ResultDescriptor descriptor) { 355 static bool _isErrorResult(ResultDescriptor descriptor) {
279 return _SOURCE_ERRORS.contains(descriptor) || 356 return _SOURCE_ERRORS.contains(descriptor) ||
280 _UNIT_ERRORS.contains(descriptor); 357 _UNIT_ERRORS.contains(descriptor);
281 } 358 }
282 } 359 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/test/src/task/dart_work_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698