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

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

Issue 2138603002: Keep resolution results in more cases. Invalidate only errors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 /** 320 /**
321 * The flag specifying that [RESOLVED_UNIT9] has been been computed for this 321 * The flag specifying that [RESOLVED_UNIT9] has been been computed for this
322 * compilation unit (without requiring that the AST for it still be in cache). 322 * compilation unit (without requiring that the AST for it still be in cache).
323 * 323 *
324 * The result is only available for [LibrarySpecificUnit]s. 324 * The result is only available for [LibrarySpecificUnit]s.
325 */ 325 */
326 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT9 = 326 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT9 =
327 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false); 327 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false);
328 328
329 /** 329 /**
330 * All [AnalysisError]s results for [Source]s.
331 */
332 final List<ListResultDescriptor<AnalysisError>> ERROR_SOURCE_RESULTS =
333 <ListResultDescriptor<AnalysisError>>[
334 BUILD_DIRECTIVES_ERRORS,
335 BUILD_LIBRARY_ERRORS,
336 PARSE_ERRORS,
337 SCAN_ERRORS,
338 ];
339
340 /**
341 * All [AnalysisError]s results in for [LibrarySpecificUnit]s.
342 */
343 final List<ListResultDescriptor<AnalysisError>> ERROR_UNIT_RESULTS =
344 <ListResultDescriptor<AnalysisError>>[
345 HINTS,
346 LIBRARY_UNIT_ERRORS,
347 LINTS,
348 RESOLVE_TYPE_BOUNDS_ERRORS,
349 RESOLVE_TYPE_NAMES_ERRORS,
350 RESOLVE_UNIT_ERRORS,
351 STRONG_MODE_ERRORS,
352 VARIABLE_REFERENCE_ERRORS,
353 VERIFY_ERRORS
354 ];
355
356 /**
330 * The sources representing the export closure of a library. 357 * The sources representing the export closure of a library.
331 * The [Source]s include only library sources, not their units. 358 * The [Source]s include only library sources, not their units.
332 * 359 *
333 * The result is only available for [Source]s representing a library. 360 * The result is only available for [Source]s representing a library.
334 */ 361 */
335 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = 362 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE =
336 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); 363 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null);
337 364
338 /** 365 /**
339 * The errors produced while generating hints a compilation unit. 366 * The errors produced while generating hints a compilation unit.
(...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 2507
2481 final Set<String> changedNames = new Set<String>(); 2508 final Set<String> changedNames = new Set<String>();
2482 final Map<Source, Set<String>> changedPrivateNames = <Source, Set<String>>{}; 2509 final Map<Source, Set<String>> changedPrivateNames = <Source, Set<String>>{};
2483 2510
2484 final Map<String, ClassElementDelta> changedClasses = 2511 final Map<String, ClassElementDelta> changedClasses =
2485 <String, ClassElementDelta>{}; 2512 <String, ClassElementDelta>{};
2486 2513
2487 /** 2514 /**
2488 * The cache of libraries in which all results are invalid. 2515 * The cache of libraries in which all results are invalid.
2489 */ 2516 */
2490 final Set<Source> librariesWithInvalidResults = new Set<Source>(); 2517 final Set<Source> librariesWithAllInvalidResults = new Set<Source>();
2491 2518
2492 /** 2519 /**
2493 * The cache of libraries in which all results are valid. 2520 * The cache of libraries in which all results are valid.
2494 */ 2521 */
2495 final Set<Source> librariesWithValidResults = new Set<Source>(); 2522 final Set<Source> librariesWithAllValidResults = new Set<Source>();
2523
2524 /**
2525 * The cache of libraries with all, but [HINTS] and [VERIFY_ERRORS] results
2526 * are valid.
2527 */
2528 final Set<Source> libraryWithInvalidErrors = new Set<Source>();
2496 2529
2497 DartDelta(Source source) : super(source); 2530 DartDelta(Source source) : super(source);
2498 2531
2499 /** 2532 /**
2500 * Add names that are changed in the given [references]. 2533 * Add names that are changed in the given [references].
2501 */ 2534 */
2502 void addChangedElements(ReferencedNames references, Source refLibrary) { 2535 void addChangedElements(ReferencedNames references, Source refLibrary) {
2503 bool hasProgress = true; 2536 bool hasProgress = true;
2504 while (hasProgress) { 2537 while (hasProgress) {
2505 hasProgress = false; 2538 hasProgress = false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 2579
2547 void classChanged(ClassElementDelta classDelta) { 2580 void classChanged(ClassElementDelta classDelta) {
2548 changedClasses[classDelta.name] = classDelta; 2581 changedClasses[classDelta.name] = classDelta;
2549 } 2582 }
2550 2583
2551 void elementChanged(Element element) { 2584 void elementChanged(Element element) {
2552 Source librarySource = element.library.source; 2585 Source librarySource = element.library.source;
2553 nameChanged(librarySource, element.name); 2586 nameChanged(librarySource, element.name);
2554 } 2587 }
2555 2588
2556 bool hasAffectedReferences(ReferencedNames references, Source refLibrary) { 2589 bool hasAffectedHintsVerifyErrors(
2557 // Verify errors must be recomputed when a superclass changes. 2590 ReferencedNames references, Source refLibrary) {
2558 for (String superName in references.superToSubs.keys) { 2591 for (String superName in references.superToSubs.keys) {
2559 if (isChangedOrClass(refLibrary, superName)) { 2592 if (isChangedOrClass(refLibrary, superName)) {
2560 _log(() => '$refLibrary is affected because ' 2593 _log(() => '$refLibrary hints/verify errors are affected because '
2561 '${references.superToSubs[superName]} subclasses $superName'); 2594 '${references.superToSubs[superName]} subclasses $superName');
2562 return true; 2595 return true;
2563 } 2596 }
2564 } 2597 }
2565 // Verify errors must be recomputed when an instantiated class changes. 2598 return false;
2566 for (String name in references.instantiatedNames) { 2599 }
2567 if (isChangedOrClass(refLibrary, name)) { 2600
2568 _log(() => '$refLibrary is affected because $name is instantiated'); 2601 bool hasAffectedReferences(ReferencedNames references, Source refLibrary) {
2569 return true;
2570 }
2571 }
2572 // Resolution must be performed when a referenced element changes. 2602 // Resolution must be performed when a referenced element changes.
2573 for (String name in references.names) { 2603 for (String name in references.names) {
2574 if (isChangedOrClassMember(refLibrary, name)) { 2604 if (isChangedOrClassMember(refLibrary, name)) {
2575 _log(() => '$refLibrary is affected by $name'); 2605 _log(() => '$refLibrary is affected by $name');
2576 return true; 2606 return true;
2577 } 2607 }
2578 } 2608 }
2579 return false; 2609 return false;
2580 } 2610 }
2581 2611
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2671 } 2701 }
2672 // Keep results that don't change: dependent library. 2702 // Keep results that don't change: dependent library.
2673 if (targetUnit != source) { 2703 if (targetUnit != source) {
2674 if (_isTaskResult(BuildPublicNamespaceTask.DESCRIPTOR, descriptor)) { 2704 if (_isTaskResult(BuildPublicNamespaceTask.DESCRIPTOR, descriptor)) {
2675 return DeltaResult.KEEP_CONTINUE; 2705 return DeltaResult.KEEP_CONTINUE;
2676 } 2706 }
2677 } 2707 }
2678 // Handle in-library results only for now. 2708 // Handle in-library results only for now.
2679 if (targetLibrary != null) { 2709 if (targetLibrary != null) {
2680 // Use cached library results. 2710 // Use cached library results.
2681 if (librariesWithInvalidResults.contains(targetLibrary)) { 2711 if (librariesWithAllInvalidResults.contains(targetLibrary)) {
2682 return DeltaResult.INVALIDATE; 2712 return DeltaResult.INVALIDATE;
2683 } 2713 }
2684 if (librariesWithValidResults.contains(targetLibrary)) { 2714 if (librariesWithAllValidResults.contains(targetLibrary)) {
2685 return DeltaResult.STOP; 2715 return DeltaResult.STOP;
2686 } 2716 }
2717 // The library is almost, but not completely valid.
2718 // Some error results are invalid.
2719 if (libraryWithInvalidErrors.contains(targetLibrary)) {
2720 if (descriptor == HINTS || descriptor == VERIFY_ERRORS) {
2721 return DeltaResult.INVALIDATE_NO_DELTA;
2722 }
2723 return DeltaResult.KEEP_CONTINUE;
2724 }
2687 // Compute the library result. 2725 // Compute the library result.
2688 ReferencedNames referencedNames = 2726 ReferencedNames referencedNames =
2689 context.getResult(targetUnit, REFERENCED_NAMES); 2727 context.getResult(targetUnit, REFERENCED_NAMES);
2690 if (referencedNames == null) { 2728 if (referencedNames == null) {
2691 return DeltaResult.INVALIDATE_NO_DELTA; 2729 return DeltaResult.INVALIDATE_NO_DELTA;
2692 } 2730 }
2693 addChangedElements(referencedNames, targetLibrary); 2731 addChangedElements(referencedNames, targetLibrary);
2694 if (hasAffectedReferences(referencedNames, targetLibrary)) { 2732 if (hasAffectedReferences(referencedNames, targetLibrary)) {
2695 librariesWithInvalidResults.add(targetLibrary); 2733 librariesWithAllInvalidResults.add(targetLibrary);
2696 return DeltaResult.INVALIDATE; 2734 return DeltaResult.INVALIDATE;
2697 } 2735 }
2698 librariesWithValidResults.add(targetLibrary); 2736 if (hasAffectedHintsVerifyErrors(referencedNames, targetLibrary)) {
2737 libraryWithInvalidErrors.add(targetLibrary);
2738 return DeltaResult.KEEP_CONTINUE;
2739 }
2740 librariesWithAllValidResults.add(targetLibrary);
2699 return DeltaResult.STOP; 2741 return DeltaResult.STOP;
2700 } 2742 }
2701 // We don't know what to do with the given target, invalidate it. 2743 // We don't know what to do with the given target, invalidate it.
2702 return DeltaResult.INVALIDATE; 2744 return DeltaResult.INVALIDATE;
2703 } 2745 }
2704 2746
2705 void _log(String getMessage()) { 2747 void _log(String getMessage()) {
2706 // String message = getMessage(); 2748 // String message = getMessage();
2707 // print(message); 2749 // print(message);
2708 } 2750 }
(...skipping 3720 matching lines...) Expand 10 before | Expand all | Expand 10 after
6429 6471
6430 @override 6472 @override
6431 bool moveNext() { 6473 bool moveNext() {
6432 if (_newSources.isEmpty) { 6474 if (_newSources.isEmpty) {
6433 return false; 6475 return false;
6434 } 6476 }
6435 currentTarget = _newSources.removeLast(); 6477 currentTarget = _newSources.removeLast();
6436 return true; 6478 return true;
6437 } 6479 }
6438 } 6480 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698