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

Side by Side Diff: pkg/analyzer/lib/src/generated/incremental_resolver.dart

Issue 1222433003: Invalidate both hints and lints on incremental resolution. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
OLDNEW
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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 */ 892 */
893 final int _updateEndNew; 893 final int _updateEndNew;
894 894
895 int _updateDelta; 895 int _updateDelta;
896 896
897 RecordingErrorListener errorListener = new RecordingErrorListener(); 897 RecordingErrorListener errorListener = new RecordingErrorListener();
898 ResolutionContext _resolutionContext; 898 ResolutionContext _resolutionContext;
899 899
900 List<AnalysisError> _resolveErrors = AnalysisError.NO_ERRORS; 900 List<AnalysisError> _resolveErrors = AnalysisError.NO_ERRORS;
901 List<AnalysisError> _verifyErrors = AnalysisError.NO_ERRORS; 901 List<AnalysisError> _verifyErrors = AnalysisError.NO_ERRORS;
902 List<AnalysisError> _lints = AnalysisError.NO_ERRORS;
903 902
904 /** 903 /**
905 * Initialize a newly created incremental resolver to resolve a node in the 904 * Initialize a newly created incremental resolver to resolve a node in the
906 * given source in the given library. 905 * given source in the given library.
907 */ 906 */
908 IncrementalResolver(this.oldEntry, this.newSourceEntry, this.newUnitEntry, 907 IncrementalResolver(this.oldEntry, this.newSourceEntry, this.newUnitEntry,
909 this._definingUnit, this._updateOffset, this._updateEndOld, 908 this._definingUnit, this._updateOffset, this._updateEndOld,
910 this._updateEndNew) { 909 this._updateEndNew) {
911 _updateDelta = _updateEndNew - _updateEndOld; 910 _updateDelta = _updateEndNew - _updateEndOld;
912 _definingLibrary = _definingUnit.library; 911 _definingLibrary = _definingUnit.library;
(...skipping 21 matching lines...) Expand all
934 if (!_canBeIncrementallyResolved(rootNode)) { 933 if (!_canBeIncrementallyResolved(rootNode)) {
935 return false; 934 return false;
936 } 935 }
937 // resolve 936 // resolve
938 _resolveReferences(rootNode); 937 _resolveReferences(rootNode);
939 _computeConstants(rootNode); 938 _computeConstants(rootNode);
940 _resolveErrors = errorListener.getErrorsForSource(_source); 939 _resolveErrors = errorListener.getErrorsForSource(_source);
941 // verify 940 // verify
942 _verify(rootNode); 941 _verify(rootNode);
943 _context.invalidateLibraryHints(_librarySource); 942 _context.invalidateLibraryHints(_librarySource);
944 _generateLints(rootNode);
945 // update entry errors 943 // update entry errors
946 _updateEntry(); 944 _updateEntry();
947 // notify unit 945 // notify unit
948 _definingUnit.afterIncrementalResolution(); 946 _definingUnit.afterIncrementalResolution();
949 // OK 947 // OK
950 return true; 948 return true;
951 } finally { 949 } finally {
952 logger.exit(); 950 logger.exit();
953 } 951 }
954 } 952 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 AstNode _findResolutionRoot(AstNode node) { 1044 AstNode _findResolutionRoot(AstNode node) {
1047 while (node != null) { 1045 while (node != null) {
1048 if (_canBeResolved(node)) { 1046 if (_canBeResolved(node)) {
1049 return node; 1047 return node;
1050 } 1048 }
1051 node = node.parent; 1049 node = node.parent;
1052 } 1050 }
1053 throw new AnalysisException("Cannot resolve node: no resolvable node"); 1051 throw new AnalysisException("Cannot resolve node: no resolvable node");
1054 } 1052 }
1055 1053
1056 void _generateLints(AstNode node) {
1057 LoggingTimer timer = logger.startTimer();
1058 try {
1059 if (_context.analysisOptions.lint) {
1060 RecordingErrorListener errorListener = new RecordingErrorListener();
1061 CompilationUnit unit = node.getAncestor((n) => n is CompilationUnit);
1062 LintGenerator lintGenerator =
1063 new LintGenerator(<CompilationUnit>[unit], errorListener);
1064 lintGenerator.generate();
1065 _lints = errorListener.getErrorsForSource(_source);
1066 } else {
1067 _lints = AnalysisError.NO_ERRORS;
1068 }
1069 } finally {
1070 timer.stop('generate lints');
1071 }
1072 }
1073
1074 /** 1054 /**
1075 * Return the element defined by [node], or `null` if the node does not 1055 * Return the element defined by [node], or `null` if the node does not
1076 * define an element. 1056 * define an element.
1077 */ 1057 */
1078 Element _getElement(AstNode node) { 1058 Element _getElement(AstNode node) {
1079 if (node is Declaration) { 1059 if (node is Declaration) {
1080 return node.element; 1060 return node.element;
1081 } else if (node is CompilationUnit) { 1061 } else if (node is CompilationUnit) {
1082 return node.element; 1062 return node.element;
1083 } 1063 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 _updateErrors_NEW(RESOLVE_TYPE_NAMES_ERRORS, []); 1174 _updateErrors_NEW(RESOLVE_TYPE_NAMES_ERRORS, []);
1195 _updateErrors_NEW(VARIABLE_REFERENCE_ERRORS, []); 1175 _updateErrors_NEW(VARIABLE_REFERENCE_ERRORS, []);
1196 _updateErrors_NEW(VERIFY_ERRORS, _verifyErrors); 1176 _updateErrors_NEW(VERIFY_ERRORS, _verifyErrors);
1197 // invalidate results we don't update incrementally 1177 // invalidate results we don't update incrementally
1198 newUnitEntry.setState(USED_IMPORTED_ELEMENTS, CacheState.INVALID); 1178 newUnitEntry.setState(USED_IMPORTED_ELEMENTS, CacheState.INVALID);
1199 newUnitEntry.setState(USED_LOCAL_ELEMENTS, CacheState.INVALID); 1179 newUnitEntry.setState(USED_LOCAL_ELEMENTS, CacheState.INVALID);
1200 newUnitEntry.setState(HINTS, CacheState.INVALID); 1180 newUnitEntry.setState(HINTS, CacheState.INVALID);
1201 } 1181 }
1202 1182
1203 void _updateEntry_OLD() { 1183 void _updateEntry_OLD() {
1204 { 1184 _updateErrors_OLD(DartEntry.RESOLUTION_ERRORS, _resolveErrors);
1205 List<AnalysisError> oldErrors = oldEntry.getValueInLibrary( 1185 _updateErrors_OLD(DartEntry.VERIFICATION_ERRORS, _verifyErrors);
1206 DartEntry.RESOLUTION_ERRORS, _librarySource);
1207 List<AnalysisError> errors = _updateErrors(oldErrors, _resolveErrors);
1208 oldEntry.setValueInLibrary(
1209 DartEntry.RESOLUTION_ERRORS, _librarySource, errors);
1210 }
1211 {
1212 List<AnalysisError> oldErrors = oldEntry.getValueInLibrary(
1213 DartEntry.VERIFICATION_ERRORS, _librarySource);
1214 List<AnalysisError> errors = _updateErrors(oldErrors, _verifyErrors);
1215 oldEntry.setValueInLibrary(
1216 DartEntry.VERIFICATION_ERRORS, _librarySource, errors);
1217 }
1218 oldEntry.setValueInLibrary(DartEntry.LINTS, _librarySource, _lints);
1219 } 1186 }
1220 1187
1221 List<AnalysisError> _updateErrors( 1188 List<AnalysisError> _updateErrors(
1222 List<AnalysisError> oldErrors, List<AnalysisError> newErrors) { 1189 List<AnalysisError> oldErrors, List<AnalysisError> newErrors) {
1223 List<AnalysisError> errors = new List<AnalysisError>(); 1190 List<AnalysisError> errors = new List<AnalysisError>();
1224 // add updated old errors 1191 // add updated old errors
1225 for (AnalysisError error in oldErrors) { 1192 for (AnalysisError error in oldErrors) {
1226 int errorOffset = error.offset; 1193 int errorOffset = error.offset;
1227 if (errorOffset < _updateOffset) { 1194 if (errorOffset < _updateOffset) {
1228 errors.add(error); 1195 errors.add(error);
(...skipping 13 matching lines...) Expand all
1242 return errors; 1209 return errors;
1243 } 1210 }
1244 1211
1245 void _updateErrors_NEW(ResultDescriptor<List<AnalysisError>> descriptor, 1212 void _updateErrors_NEW(ResultDescriptor<List<AnalysisError>> descriptor,
1246 List<AnalysisError> newErrors) { 1213 List<AnalysisError> newErrors) {
1247 List<AnalysisError> oldErrors = newUnitEntry.getValue(descriptor); 1214 List<AnalysisError> oldErrors = newUnitEntry.getValue(descriptor);
1248 List<AnalysisError> errors = _updateErrors(oldErrors, newErrors); 1215 List<AnalysisError> errors = _updateErrors(oldErrors, newErrors);
1249 newUnitEntry.setValueIncremental(descriptor, errors); 1216 newUnitEntry.setValueIncremental(descriptor, errors);
1250 } 1217 }
1251 1218
1219 void _updateErrors_OLD(DataDescriptor<List<AnalysisError>> descriptor,
1220 List<AnalysisError> newErrors) {
1221 List<AnalysisError> oldErrors =
1222 oldEntry.getValueInLibrary(descriptor, _librarySource);
1223 List<AnalysisError> errors = _updateErrors(oldErrors, newErrors);
1224 oldEntry.setValueInLibrary(descriptor, _librarySource, errors);
1225 }
1226
1252 void _verify(AstNode node) { 1227 void _verify(AstNode node) {
1253 LoggingTimer timer = logger.startTimer(); 1228 LoggingTimer timer = logger.startTimer();
1254 try { 1229 try {
1255 RecordingErrorListener errorListener = new RecordingErrorListener(); 1230 RecordingErrorListener errorListener = new RecordingErrorListener();
1256 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source); 1231 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source);
1257 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, 1232 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter,
1258 _definingLibrary, _typeProvider, 1233 _definingLibrary, _typeProvider,
1259 new InheritanceManager(_definingLibrary)); 1234 new InheritanceManager(_definingLibrary));
1260 if (_resolutionContext.enclosingClassDeclaration != null) { 1235 if (_resolutionContext.enclosingClassDeclaration != null) {
1261 errorVerifier.visitClassDeclarationIncrementally( 1236 errorVerifier.visitClassDeclarationIncrementally(
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 @override 1978 @override
2004 String toString() => name; 1979 String toString() => name;
2005 } 1980 }
2006 1981
2007 class _TokenPair { 1982 class _TokenPair {
2008 final _TokenDifferenceKind kind; 1983 final _TokenDifferenceKind kind;
2009 final Token oldToken; 1984 final Token oldToken;
2010 final Token newToken; 1985 final Token newToken;
2011 _TokenPair(this.kind, this.oldToken, this.newToken); 1986 _TokenPair(this.kind, this.oldToken, this.newToken);
2012 } 1987 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698