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

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

Issue 2834773003: Remove the limited invalidation feature. (Closed)
Patch Set: Created 3 years, 8 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.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index a7856f9490311fdd1e8cd44ca8cd74738d1130f0..6c999e4501dfe5748e0faf1dd01ed3ebf79c6a31 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -43,7 +43,6 @@ import 'package:analyzer/src/services/lint.dart';
import 'package:analyzer/src/task/driver.dart';
import 'package:analyzer/src/task/general.dart';
import 'package:analyzer/src/task/html.dart';
-import 'package:analyzer/src/task/incremental_element_builder.dart';
import 'package:analyzer/src/task/inputs.dart';
import 'package:analyzer/src/task/model.dart';
import 'package:analyzer/src/task/strong/checker.dart';
@@ -2466,338 +2465,6 @@ class ContainingLibrariesTask extends SourceBasedAnalysisTask {
}
/**
- * The description for a change in a Dart source.
- */
-class DartDelta extends Delta {
- final Set<String> changedNames = new Set<String>();
- final Map<Source, Set<String>> changedPrivateNames = <Source, Set<String>>{};
-
- final Map<String, ClassElementDelta> changedClasses =
- <String, ClassElementDelta>{};
-
- /**
- * The cache of libraries in which all results are invalid.
- */
- final Set<Source> librariesWithAllInvalidResults = new Set<Source>();
-
- /**
- * The cache of libraries in which all results are valid.
- */
- final Set<Source> librariesWithAllValidResults = new Set<Source>();
-
- /**
- * The cache of libraries with all, but [HINTS] and [VERIFY_ERRORS] results
- * are valid.
- */
- final Set<Source> libraryWithInvalidErrors = new Set<Source>();
-
- /**
- * This set is cleared in every [gatherEnd], and [gatherChanges] uses it
- * to find changes in every source only once per visit process.
- */
- final Set<Source> currentVisitUnits = new Set<Source>();
-
- DartDelta(Source source) : super(source);
-
- @override
- bool get shouldGatherChanges => true;
-
- /**
- * Add names that are changed in the given [references].
- * Return `true` if any change was added.
- */
- bool addChangedElements(ReferencedNames references, Source refLibrary) {
- int numberOfChanges = 0;
- int lastNumberOfChange = -1;
- while (numberOfChanges != lastNumberOfChange) {
- lastNumberOfChange = numberOfChanges;
- // Classes that extend changed classes are also changed.
- // If there is a delta for a superclass, use it for the subclass.
- // Otherwise mark the subclass as "general name change".
- references.superToSubs.forEach((String superName, Set<String> subNames) {
- ClassElementDelta superDelta = changedClasses[superName];
- for (String subName in subNames) {
- if (superDelta != null) {
- ClassElementDelta subDelta = changedClasses.putIfAbsent(subName,
- () => new ClassElementDelta(null, refLibrary, subName));
- _log(() => '$subName in $refLibrary has delta because of its '
- 'superclass $superName has delta');
- if (subDelta.superDeltas.add(superDelta)) {
- numberOfChanges++;
- }
- } else if (isChanged(refLibrary, superName)) {
- if (nameChanged(refLibrary, subName)) {
- _log(() => '$subName in $refLibrary is changed because its '
- 'superclass $superName is changed');
- numberOfChanges++;
- }
- }
- }
- });
- // If a user element uses a changed top-level element, then the user is
- // also changed. Note that if a changed class with delta is used, this
- // does not make the user changed - classes with delta keep their
- // original elements, so resolution of their names does not change.
- references.userToDependsOn.forEach((user, dependencies) {
- for (String dependency in dependencies) {
- if (isChangedOrClassMember(refLibrary, dependency)) {
- if (nameChanged(refLibrary, user)) {
- _log(() => '$user in $refLibrary is changed because '
- 'of $dependency in $dependencies');
- numberOfChanges++;
- }
- }
- }
- });
- }
- return numberOfChanges != 0;
- }
-
- void classChanged(ClassElementDelta classDelta) {
- changedClasses[classDelta.name] = classDelta;
- }
-
- void elementChanged(Element element) {
- Source librarySource = element.library.source;
- nameChanged(librarySource, element.name);
- }
-
- @override
- bool gatherChanges(InternalAnalysisContext context, AnalysisTarget target,
- ResultDescriptor descriptor, Object value) {
- // Prepare target source.
- Source targetUnit = target.source;
- Source targetLibrary = target.librarySource;
- if (target is Source) {
- if (context.getKindOf(target) == SourceKind.LIBRARY) {
- targetLibrary = target;
- }
- }
- // We don't know what to do with the given target.
- if (targetUnit == null || targetUnit != targetLibrary) {
- return false;
- }
- // Attempt to find new changed names for the unit only once.
- if (!currentVisitUnits.add(targetUnit)) {
- return false;
- }
- // Add changes.
- ReferencedNames referencedNames =
- context.getResult(targetUnit, REFERENCED_NAMES);
- if (referencedNames == null) {
- return false;
- }
- return addChangedElements(referencedNames, targetLibrary);
- }
-
- @override
- void gatherEnd() {
- currentVisitUnits.clear();
- }
-
- bool hasAffectedHintsVerifyErrors(
- ReferencedNames references, Source refLibrary) {
- for (String superName in references.superToSubs.keys) {
- if (isChangedOrClass(refLibrary, superName)) {
- _log(() => '$refLibrary hints/verify errors are affected because '
- '${references.superToSubs[superName]} subclasses $superName');
- return true;
- }
- }
- for (String name in references.names) {
- ClassElementDelta classDelta = changedClasses[name];
- if (classDelta != null && classDelta.hasAnnotationChanges) {
- _log(() => '$refLibrary hints/verify errors are affected because '
- '$name has a class delta with annotation changes');
- return true;
- }
- }
- return false;
- }
-
- bool hasAffectedReferences(ReferencedNames references, Source refLibrary) {
- // Resolution must be performed when a referenced element changes.
- for (String name in references.names) {
- if (isChangedOrClassMember(refLibrary, name)) {
- _log(() => '$refLibrary is affected by $name');
- return true;
- }
- }
- // Resolution must be performed when the unnamed constructor of
- // an instantiated class is added/changed/removed.
- // TODO(scheglov) Use only instantiations with default constructor.
- for (String name in references.instantiatedNames) {
- for (ClassElementDelta classDelta in changedClasses.values) {
- if (classDelta.name == name && classDelta.hasUnnamedConstructorChange) {
- _log(() =>
- '$refLibrary is affected by the default constructor of $name');
- return true;
- }
- }
- }
- for (String name in references.extendedUsedUnnamedConstructorNames) {
- for (ClassElementDelta classDelta in changedClasses.values) {
- if (classDelta.name == name && classDelta.hasUnnamedConstructorChange) {
- _log(() =>
- '$refLibrary is affected by the default constructor of $name');
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Return `true` if the given [name], used in a unit of the [librarySource],
- * is affected by a changed top-level element, excluding classes.
- */
- bool isChanged(Source librarySource, String name) {
- if (_isPrivateName(name)) {
- if (changedPrivateNames[librarySource]?.contains(name) ?? false) {
- return true;
- }
- }
- return changedNames.contains(name);
- }
-
- /**
- * Return `true` if the given [name], used in a unit of the [librarySource],
- * is affected by a changed top-level element or a class.
- */
- bool isChangedOrClass(Source librarySource, String name) {
- if (isChanged(librarySource, name)) {
- return true;
- }
- return changedClasses[name] != null;
- }
-
- /**
- * Return `true` if the given [name], used in a unit of the [librarySource],
- * is affected by a changed top-level element or a class member.
- */
- bool isChangedOrClassMember(Source librarySource, String name) {
- if (isChanged(librarySource, name)) {
- return true;
- }
- // TODO(scheglov) Optimize this.
- for (ClassElementDelta classDelta in changedClasses.values) {
- if (classDelta.hasChanges(librarySource, name)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Register the fact that the given [name], defined in the [librarySource]
- * is changed. Return `true` if the [name] is a new name, not yet registered.
- */
- bool nameChanged(Source librarySource, String name) {
- if (_isPrivateName(name)) {
- return changedPrivateNames
- .putIfAbsent(librarySource, () => new Set<String>())
- .add(name);
- } else {
- return changedNames.add(name);
- }
- }
-
- @override
- DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target,
- ResultDescriptor descriptor, Object value) {
- // Always invalidate compounding results.
- if (descriptor == LIBRARY_ELEMENT4 ||
- descriptor == READY_LIBRARY_ELEMENT6 ||
- descriptor == READY_LIBRARY_ELEMENT7) {
- return DeltaResult.INVALIDATE_KEEP_DEPENDENCIES;
- }
- // Prepare target source.
- Source targetUnit = target.source;
- Source targetLibrary = target.librarySource;
- if (target is Source) {
- if (context.getKindOf(target) == SourceKind.LIBRARY) {
- targetLibrary = target;
- }
- }
- // We don't know what to do with the given target, invalidate it.
- if (targetUnit == null || targetUnit != targetLibrary) {
- return DeltaResult.INVALIDATE;
- }
- // Keep results that don't change: any library.
- if (_isTaskResult(ScanDartTask.DESCRIPTOR, descriptor) ||
- _isTaskResult(ParseDartTask.DESCRIPTOR, descriptor) ||
- _isTaskResult(BuildCompilationUnitElementTask.DESCRIPTOR, descriptor) ||
- _isTaskResult(BuildLibraryElementTask.DESCRIPTOR, descriptor) ||
- _isTaskResult(BuildDirectiveElementsTask.DESCRIPTOR, descriptor) ||
- _isTaskResult(ResolveDirectiveElementsTask.DESCRIPTOR, descriptor) ||
- _isTaskResult(BuildEnumMemberElementsTask.DESCRIPTOR, descriptor) ||
- _isTaskResult(BuildSourceExportClosureTask.DESCRIPTOR, descriptor) ||
- _isTaskResult(ReadyLibraryElement2Task.DESCRIPTOR, descriptor) ||
- _isTaskResult(ComputeLibraryCycleTask.DESCRIPTOR, descriptor)) {
- return DeltaResult.KEEP_CONTINUE;
- }
- // Keep results that don't change: changed library.
- if (targetUnit == source) {
- return DeltaResult.INVALIDATE;
- }
- // Keep results that don't change: dependent library.
- if (targetUnit != source) {
- if (_isTaskResult(BuildPublicNamespaceTask.DESCRIPTOR, descriptor)) {
- return DeltaResult.KEEP_CONTINUE;
- }
- }
- // Handle in-library results only for now.
- if (targetLibrary != null) {
- // Use cached library results.
- if (librariesWithAllInvalidResults.contains(targetLibrary)) {
- return DeltaResult.INVALIDATE;
- }
- if (librariesWithAllValidResults.contains(targetLibrary)) {
- return DeltaResult.KEEP_CONTINUE;
- }
- // The library is almost, but not completely valid.
- // Some error results are invalid.
- if (libraryWithInvalidErrors.contains(targetLibrary)) {
- if (descriptor == HINTS || descriptor == VERIFY_ERRORS) {
- return DeltaResult.INVALIDATE_NO_DELTA;
- }
- return DeltaResult.KEEP_CONTINUE;
- }
- // Compute the library result.
- ReferencedNames referencedNames =
- context.getResult(targetUnit, REFERENCED_NAMES);
- if (referencedNames == null) {
- return DeltaResult.INVALIDATE_NO_DELTA;
- }
- if (hasAffectedReferences(referencedNames, targetLibrary)) {
- librariesWithAllInvalidResults.add(targetLibrary);
- return DeltaResult.INVALIDATE;
- }
- if (hasAffectedHintsVerifyErrors(referencedNames, targetLibrary)) {
- libraryWithInvalidErrors.add(targetLibrary);
- return DeltaResult.KEEP_CONTINUE;
- }
- librariesWithAllValidResults.add(targetLibrary);
- return DeltaResult.KEEP_CONTINUE;
- }
- // We don't know what to do with the given target, invalidate it.
- return DeltaResult.INVALIDATE;
- }
-
- void _log(String getMessage()) {
-// String message = getMessage();
-// print(message);
- }
-
- static bool _isPrivateName(String name) => name.startsWith('_');
-
- static bool _isTaskResult(
- TaskDescriptor taskDescriptor, ResultDescriptor result) {
- return taskDescriptor.results.contains(result);
- }
-}
-
-/**
* A task that merges all of the errors for a single source into a single list
* of errors.
*/
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/task/incremental_element_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698