| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.incremental_resolver; | 5 library engine.incremental_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/src/context/cache.dart' | 10 import 'package:analyzer/src/context/cache.dart' |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 @override | 857 @override |
| 858 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target, | 858 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target, |
| 859 ResultDescriptor descriptor) { | 859 ResultDescriptor descriptor) { |
| 860 // don't invalidate results of standard Dart tasks | 860 // don't invalidate results of standard Dart tasks |
| 861 bool isByTask(TaskDescriptor taskDescriptor) { | 861 bool isByTask(TaskDescriptor taskDescriptor) { |
| 862 return taskDescriptor.results.contains(descriptor); | 862 return taskDescriptor.results.contains(descriptor); |
| 863 } | 863 } |
| 864 if (descriptor == CONTENT) { | 864 if (descriptor == CONTENT) { |
| 865 return DeltaResult.KEEP_CONTINUE; | 865 return DeltaResult.KEEP_CONTINUE; |
| 866 } | 866 } |
| 867 if (target is Source && target != source) { | 867 if (target is LibrarySpecificUnit && target.unit != source) { |
| 868 if (isByTask(DartErrorsTask.DESCRIPTOR) || | 868 if (isByTask(GatherUsedLocalElementsTask.DESCRIPTOR) || |
| 869 isByTask(LibraryErrorsReadyTask.DESCRIPTOR)) { | 869 isByTask(GatherUsedImportedElementsTask.DESCRIPTOR)) { |
| 870 return DeltaResult.KEEP_CONTINUE; | 870 return DeltaResult.KEEP_CONTINUE; |
| 871 } | 871 } |
| 872 } | 872 } |
| 873 if (target is LibrarySpecificUnit && | |
| 874 target.unit != source && | |
| 875 target.library != source) { | |
| 876 if (isByTask(GatherUsedLocalElementsTask.DESCRIPTOR) || | |
| 877 isByTask(GatherUsedImportedElementsTask.DESCRIPTOR) || | |
| 878 isByTask(GenerateHintsTask.DESCRIPTOR) || | |
| 879 isByTask(LibraryUnitErrorsTask.DESCRIPTOR)) { | |
| 880 return DeltaResult.KEEP_CONTINUE; | |
| 881 } | |
| 882 } | |
| 883 if (isByTask(BuildCompilationUnitElementTask.DESCRIPTOR) || | 873 if (isByTask(BuildCompilationUnitElementTask.DESCRIPTOR) || |
| 884 isByTask(BuildDirectiveElementsTask.DESCRIPTOR) || | 874 isByTask(BuildDirectiveElementsTask.DESCRIPTOR) || |
| 885 isByTask(BuildEnumMemberElementsTask.DESCRIPTOR) || | 875 isByTask(BuildEnumMemberElementsTask.DESCRIPTOR) || |
| 886 isByTask(BuildExportNamespaceTask.DESCRIPTOR) || | 876 isByTask(BuildExportNamespaceTask.DESCRIPTOR) || |
| 887 isByTask(BuildLibraryElementTask.DESCRIPTOR) || | 877 isByTask(BuildLibraryElementTask.DESCRIPTOR) || |
| 888 isByTask(BuildPublicNamespaceTask.DESCRIPTOR) || | 878 isByTask(BuildPublicNamespaceTask.DESCRIPTOR) || |
| 889 isByTask(BuildSourceExportClosureTask.DESCRIPTOR) || | 879 isByTask(BuildSourceExportClosureTask.DESCRIPTOR) || |
| 890 isByTask(BuildSourceImportExportClosureTask.DESCRIPTOR) || | 880 isByTask(BuildSourceImportExportClosureTask.DESCRIPTOR) || |
| 891 isByTask(ComputeConstantDependenciesTask.DESCRIPTOR) || | 881 isByTask(ComputeConstantDependenciesTask.DESCRIPTOR) || |
| 892 isByTask(ComputeConstantValueTask.DESCRIPTOR) || | 882 isByTask(ComputeConstantValueTask.DESCRIPTOR) || |
| 883 isByTask(DartErrorsTask.DESCRIPTOR) || |
| 893 isByTask(EvaluateUnitConstantsTask.DESCRIPTOR) || | 884 isByTask(EvaluateUnitConstantsTask.DESCRIPTOR) || |
| 885 isByTask(GenerateHintsTask.DESCRIPTOR) || |
| 894 isByTask(InferInstanceMembersInUnitTask.DESCRIPTOR) || | 886 isByTask(InferInstanceMembersInUnitTask.DESCRIPTOR) || |
| 895 isByTask(InferStaticVariableTypesInUnitTask.DESCRIPTOR) || | 887 isByTask(InferStaticVariableTypesInUnitTask.DESCRIPTOR) || |
| 888 isByTask(LibraryErrorsReadyTask.DESCRIPTOR) || |
| 889 isByTask(LibraryUnitErrorsTask.DESCRIPTOR) || |
| 896 isByTask(ParseDartTask.DESCRIPTOR) || | 890 isByTask(ParseDartTask.DESCRIPTOR) || |
| 897 isByTask(PartiallyResolveUnitReferencesTask.DESCRIPTOR) || | 891 isByTask(PartiallyResolveUnitReferencesTask.DESCRIPTOR) || |
| 898 isByTask(ScanDartTask.DESCRIPTOR) || | 892 isByTask(ScanDartTask.DESCRIPTOR) || |
| 899 isByTask(ResolveFunctionBodiesInUnitTask.DESCRIPTOR) || | 893 isByTask(ResolveFunctionBodiesInUnitTask.DESCRIPTOR) || |
| 900 isByTask(ResolveLibraryReferencesTask.DESCRIPTOR) || | 894 isByTask(ResolveLibraryReferencesTask.DESCRIPTOR) || |
| 901 isByTask(ResolveLibraryTypeNamesTask.DESCRIPTOR) || | 895 isByTask(ResolveLibraryTypeNamesTask.DESCRIPTOR) || |
| 902 isByTask(ResolveUnitTypeNamesTask.DESCRIPTOR) || | 896 isByTask(ResolveUnitTypeNamesTask.DESCRIPTOR) || |
| 903 isByTask(ResolveVariableReferencesTask.DESCRIPTOR) || | 897 isByTask(ResolveVariableReferencesTask.DESCRIPTOR) || |
| 904 isByTask(VerifyUnitTask.DESCRIPTOR)) { | 898 isByTask(VerifyUnitTask.DESCRIPTOR)) { |
| 905 return DeltaResult.KEEP_CONTINUE; | 899 return DeltaResult.KEEP_CONTINUE; |
| 906 } | 900 } |
| 907 // invalidate all the other results | 901 // invalidate all the other results |
| 908 return DeltaResult.INVALIDATE; | 902 return DeltaResult.INVALIDATE_NO_DELTA; |
| 909 } | 903 } |
| 910 } | 904 } |
| 911 | 905 |
| 912 /** | 906 /** |
| 913 * Instances of the class [IncrementalResolver] resolve the smallest portion of | 907 * Instances of the class [IncrementalResolver] resolve the smallest portion of |
| 914 * an AST structure that we currently know how to resolve. | 908 * an AST structure that we currently know how to resolve. |
| 915 */ | 909 */ |
| 916 class IncrementalResolver { | 910 class IncrementalResolver { |
| 917 /** | 911 /** |
| 918 * The element of the compilation unit being resolved. | 912 * The element of the compilation unit being resolved. |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 void _updateEntry() { | 1281 void _updateEntry() { |
| 1288 if (oldEntry != null) { | 1282 if (oldEntry != null) { |
| 1289 _updateEntry_OLD(); | 1283 _updateEntry_OLD(); |
| 1290 } else { | 1284 } else { |
| 1291 _updateEntry_NEW(); | 1285 _updateEntry_NEW(); |
| 1292 } | 1286 } |
| 1293 } | 1287 } |
| 1294 | 1288 |
| 1295 void _updateEntry_NEW() { | 1289 void _updateEntry_NEW() { |
| 1296 _updateErrors_NEW(INFER_STATIC_VARIABLE_TYPES_ERRORS, _resolveErrors); | 1290 _updateErrors_NEW(INFER_STATIC_VARIABLE_TYPES_ERRORS, _resolveErrors); |
| 1297 _updateErrors_NEW(LIBRARY_UNIT_ERRORS, _resolveErrors); | |
| 1298 _updateErrors_NEW(PARTIALLY_RESOLVE_REFERENCES_ERRORS, _resolveErrors); | 1291 _updateErrors_NEW(PARTIALLY_RESOLVE_REFERENCES_ERRORS, _resolveErrors); |
| 1299 _updateErrors_NEW(RESOLVE_FUNCTION_BODIES_ERRORS, _resolveErrors); | 1292 _updateErrors_NEW(RESOLVE_FUNCTION_BODIES_ERRORS, _resolveErrors); |
| 1300 _updateErrors_NEW(RESOLVE_TYPE_NAMES_ERRORS, []); | 1293 _updateErrors_NEW(RESOLVE_TYPE_NAMES_ERRORS, []); |
| 1301 _updateErrors_NEW(VARIABLE_REFERENCE_ERRORS, []); | 1294 _updateErrors_NEW(VARIABLE_REFERENCE_ERRORS, []); |
| 1302 _updateErrors_NEW(VERIFY_ERRORS, _verifyErrors); | 1295 _updateErrors_NEW(VERIFY_ERRORS, _verifyErrors); |
| 1303 // invalidate results we don't update incrementally | 1296 // invalidate results we don't update incrementally |
| 1304 newUnitEntry.setState(USED_IMPORTED_ELEMENTS, CacheState.INVALID); | 1297 newUnitEntry.setState(USED_IMPORTED_ELEMENTS, CacheState.INVALID); |
| 1305 newUnitEntry.setState(USED_LOCAL_ELEMENTS, CacheState.INVALID); | 1298 newUnitEntry.setState(USED_LOCAL_ELEMENTS, CacheState.INVALID); |
| 1306 newUnitEntry.setState(HINTS, CacheState.INVALID); | 1299 newUnitEntry.setState(HINTS, CacheState.INVALID); |
| 1307 } | 1300 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1332 } | 1325 } |
| 1333 } | 1326 } |
| 1334 // done | 1327 // done |
| 1335 return errors; | 1328 return errors; |
| 1336 } | 1329 } |
| 1337 | 1330 |
| 1338 void _updateErrors_NEW(ResultDescriptor<List<AnalysisError>> descriptor, | 1331 void _updateErrors_NEW(ResultDescriptor<List<AnalysisError>> descriptor, |
| 1339 List<AnalysisError> newErrors) { | 1332 List<AnalysisError> newErrors) { |
| 1340 List<AnalysisError> oldErrors = newUnitEntry.getValue(descriptor); | 1333 List<AnalysisError> oldErrors = newUnitEntry.getValue(descriptor); |
| 1341 List<AnalysisError> errors = _updateErrors(oldErrors, newErrors); | 1334 List<AnalysisError> errors = _updateErrors(oldErrors, newErrors); |
| 1342 newUnitEntry.setValueIncremental(descriptor, errors); | 1335 newUnitEntry.setValueIncremental(descriptor, errors, true); |
| 1343 } | 1336 } |
| 1344 | 1337 |
| 1345 void _updateErrors_OLD(DataDescriptor<List<AnalysisError>> descriptor, | 1338 void _updateErrors_OLD(DataDescriptor<List<AnalysisError>> descriptor, |
| 1346 List<AnalysisError> newErrors) { | 1339 List<AnalysisError> newErrors) { |
| 1347 List<AnalysisError> oldErrors = | 1340 List<AnalysisError> oldErrors = |
| 1348 oldEntry.getValueInLibrary(descriptor, _librarySource); | 1341 oldEntry.getValueInLibrary(descriptor, _librarySource); |
| 1349 List<AnalysisError> errors = _updateErrors(oldErrors, newErrors); | 1342 List<AnalysisError> errors = _updateErrors(oldErrors, newErrors); |
| 1350 oldEntry.setValueInLibrary(descriptor, _librarySource, errors); | 1343 oldEntry.setValueInLibrary(descriptor, _librarySource, errors); |
| 1351 } | 1344 } |
| 1352 | 1345 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 | 1698 |
| 1706 void _updateEntry() { | 1699 void _updateEntry() { |
| 1707 if (_oldEntry != null) { | 1700 if (_oldEntry != null) { |
| 1708 _updateEntry_OLD(); | 1701 _updateEntry_OLD(); |
| 1709 } else { | 1702 } else { |
| 1710 _updateEntry_NEW(); | 1703 _updateEntry_NEW(); |
| 1711 } | 1704 } |
| 1712 } | 1705 } |
| 1713 | 1706 |
| 1714 void _updateEntry_NEW() { | 1707 void _updateEntry_NEW() { |
| 1715 _newSourceEntry.setState(DART_ERRORS, CacheState.INVALID); | |
| 1716 // scan results | 1708 // scan results |
| 1717 List<TargetedResult> scanDeps = <TargetedResult>[ | 1709 _newSourceEntry.setValueIncremental(SCAN_ERRORS, _newScanErrors, true); |
| 1718 new TargetedResult(_unitSource, CONTENT) | 1710 _newSourceEntry.setValueIncremental(LINE_INFO, _newLineInfo, false); |
| 1719 ]; | |
| 1720 _newSourceEntry.setState(SCAN_ERRORS, CacheState.INVALID); | |
| 1721 _newSourceEntry.setValue(SCAN_ERRORS, _newScanErrors, scanDeps); | |
| 1722 _newSourceEntry.setValue(LINE_INFO, _newLineInfo, scanDeps); | |
| 1723 // parse results | 1711 // parse results |
| 1724 List<TargetedResult> parseDeps = <TargetedResult>[ | 1712 _newSourceEntry.setValueIncremental(PARSE_ERRORS, _newScanErrors, true); |
| 1725 new TargetedResult(_unitSource, TOKEN_STREAM) | 1713 _newSourceEntry.setValueIncremental(PARSED_UNIT, _newScanErrors, false); |
| 1726 ]; | |
| 1727 _newSourceEntry.setState(PARSE_ERRORS, CacheState.INVALID); | |
| 1728 _newSourceEntry.setValue(PARSE_ERRORS, _newParseErrors, parseDeps); | |
| 1729 _newSourceEntry.setValue(PARSED_UNIT, _oldUnit, parseDeps); | |
| 1730 } | 1714 } |
| 1731 | 1715 |
| 1732 void _updateEntry_OLD() { | 1716 void _updateEntry_OLD() { |
| 1733 _oldEntry.setValue(SourceEntry.LINE_INFO, _newLineInfo); | 1717 _oldEntry.setValue(SourceEntry.LINE_INFO, _newLineInfo); |
| 1734 _oldEntry.setValue(DartEntry.SCAN_ERRORS, _newScanErrors); | 1718 _oldEntry.setValue(DartEntry.SCAN_ERRORS, _newScanErrors); |
| 1735 _oldEntry.setValue(DartEntry.PARSE_ERRORS, _newParseErrors); | 1719 _oldEntry.setValue(DartEntry.PARSE_ERRORS, _newParseErrors); |
| 1736 } | 1720 } |
| 1737 | 1721 |
| 1738 /** | 1722 /** |
| 1739 * Checks if [token] has a balanced number of open and closed curly brackets. | 1723 * Checks if [token] has a balanced number of open and closed curly brackets. |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 @override | 2120 @override |
| 2137 String toString() => name; | 2121 String toString() => name; |
| 2138 } | 2122 } |
| 2139 | 2123 |
| 2140 class _TokenPair { | 2124 class _TokenPair { |
| 2141 final _TokenDifferenceKind kind; | 2125 final _TokenDifferenceKind kind; |
| 2142 final Token oldToken; | 2126 final Token oldToken; |
| 2143 final Token newToken; | 2127 final Token newToken; |
| 2144 _TokenPair(this.kind, this.oldToken, this.newToken); | 2128 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 2145 } | 2129 } |
| OLD | NEW |