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

Side by Side Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 1696193003: Fix cache corruption in incremental resolver (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 analyzer.test.generated.incremental_resolver_test; 5 library analyzer.test.generated.incremental_resolver_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/context/cache.dart'; 10 import 'package:analyzer/src/context/cache.dart';
(...skipping 3483 matching lines...) Expand 10 before | Expand all | Expand 10 after
3494 // resolve "newCode" from scratch 3494 // resolve "newCode" from scratch
3495 CompilationUnit fullNewUnit; 3495 CompilationUnit fullNewUnit;
3496 { 3496 {
3497 source = addSource(newCode); 3497 source = addSource(newCode);
3498 _runTasks(); 3498 _runTasks();
3499 LibraryElement library = resolve2(source); 3499 LibraryElement library = resolve2(source);
3500 fullNewUnit = resolveCompilationUnit(source, library); 3500 fullNewUnit = resolveCompilationUnit(source, library);
3501 } 3501 }
3502 _checkCacheEntries(cache); 3502 _checkCacheEntries(cache);
3503 3503
3504 try { 3504 assertSameResolution(unit, fullNewUnit);
3505 assertSameResolution(unit, fullNewUnit);
3506 } on IncrementalResolutionMismatch catch (mismatch) {
3507 fail(mismatch.message);
3508 }
3509 // errors 3505 // errors
3510 List<AnalysisError> newFullErrors = 3506 List<AnalysisError> newFullErrors =
3511 analysisContext.getErrors(source).errors; 3507 analysisContext.getErrors(source).errors;
3512 _assertEqualErrors(newErrors, newFullErrors); 3508 _assertEqualErrors(newErrors, newFullErrors);
3513 // prepare for the next cycle 3509 // prepare for the next cycle
3514 code = newCode; 3510 code = newCode;
3515 } 3511 }
3516 3512
3517 void _resolveUnit(String code) { 3513 void _resolveUnit(String code) {
3518 this.code = code; 3514 this.code = code;
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after
4842 { 4838 {
4843 ClassElement typeA = oldUnitElement.getType('A'); 4839 ClassElement typeA = oldUnitElement.getType('A');
4844 expect(oldUnitElement.getElementAt(typeA.nameOffset), typeA); 4840 expect(oldUnitElement.getElementAt(typeA.nameOffset), typeA);
4845 } 4841 }
4846 { 4842 {
4847 ClassElement typeB = oldUnitElement.getType('B'); 4843 ClassElement typeB = oldUnitElement.getType('B');
4848 expect(oldUnitElement.getElementAt(typeB.nameOffset), typeB); 4844 expect(oldUnitElement.getElementAt(typeB.nameOffset), typeB);
4849 } 4845 }
4850 } 4846 }
4851 4847
4852 void _assertCacheResults({bool expectCachePostConstantsValid: true}) { 4848 void test_updateFunctionToForLoop() {
4849 _resolveUnit(r'''
4850 class PlayDrag {
4851 final List<num> times = new List<num>();
4852
4853 PlayDrag.start() {}
4854
4855 void update(num pos) {
4856 fo (int i = times.length - 2; i >= 0; i--) {}
4857 }
4858 }
4859 ''');
4860
4861 _updateAndValidate(
4862 r'''
4863 class PlayDrag {
4864 final List<num> times = new List<num>();
4865
4866 PlayDrag.start() {}
4867
4868 void update(num pos) {
4869 for (int i = times.length - 2; i >= 0; i--) {}
4870 }
4871 }
4872 ''',
4873 expectLibraryUnchanged: false);
4874 }
4875
4876 void _assertCacheResults(
4877 {bool expectLibraryUnchanged: true,
4878 bool expectCachePostConstantsValid: true}) {
4853 _assertCacheSourceResult(TOKEN_STREAM); 4879 _assertCacheSourceResult(TOKEN_STREAM);
4854 _assertCacheSourceResult(SCAN_ERRORS); 4880 _assertCacheSourceResult(SCAN_ERRORS);
4855 _assertCacheSourceResult(PARSED_UNIT); 4881 _assertCacheSourceResult(PARSED_UNIT);
4856 _assertCacheSourceResult(PARSE_ERRORS); 4882 _assertCacheSourceResult(PARSE_ERRORS);
4883 if (!expectLibraryUnchanged) {
4884 return;
4885 }
4857 _assertCacheSourceResult(LIBRARY_ELEMENT1); 4886 _assertCacheSourceResult(LIBRARY_ELEMENT1);
4858 _assertCacheSourceResult(LIBRARY_ELEMENT2); 4887 _assertCacheSourceResult(LIBRARY_ELEMENT2);
4859 _assertCacheSourceResult(LIBRARY_ELEMENT3); 4888 _assertCacheSourceResult(LIBRARY_ELEMENT3);
4860 _assertCacheSourceResult(LIBRARY_ELEMENT4); 4889 _assertCacheSourceResult(LIBRARY_ELEMENT4);
4861 _assertCacheSourceResult(LIBRARY_ELEMENT5); 4890 _assertCacheSourceResult(LIBRARY_ELEMENT5);
4862 _assertCacheSourceResult(LIBRARY_ELEMENT6); 4891 _assertCacheSourceResult(LIBRARY_ELEMENT6);
4863 _assertCacheSourceResult(LIBRARY_ELEMENT7); 4892 _assertCacheSourceResult(LIBRARY_ELEMENT7);
4864 _assertCacheSourceResult(LIBRARY_ELEMENT8); 4893 _assertCacheSourceResult(LIBRARY_ELEMENT8);
4865 if (expectCachePostConstantsValid) { 4894 if (expectCachePostConstantsValid) {
4866 _assertCacheSourceResult(LIBRARY_ELEMENT); 4895 _assertCacheSourceResult(LIBRARY_ELEMENT);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
4936 4965
4937 void _runTasks() { 4966 void _runTasks() {
4938 AnalysisResult result = analysisContext.performAnalysisTask(); 4967 AnalysisResult result = analysisContext.performAnalysisTask();
4939 while (result.changeNotices != null) { 4968 while (result.changeNotices != null) {
4940 result = analysisContext.performAnalysisTask(); 4969 result = analysisContext.performAnalysisTask();
4941 } 4970 }
4942 } 4971 }
4943 4972
4944 void _updateAndValidate(String newCode, 4973 void _updateAndValidate(String newCode,
4945 {bool expectedSuccess: true, 4974 {bool expectedSuccess: true,
4975 bool expectLibraryUnchanged: true,
4946 bool expectCachePostConstantsValid: true, 4976 bool expectCachePostConstantsValid: true,
4947 bool compareWithFull: true, 4977 bool compareWithFull: true,
4948 bool runTasksBeforeIncremental: true}) { 4978 bool runTasksBeforeIncremental: true}) {
4949 // Run any pending tasks tasks. 4979 // Run any pending tasks tasks.
4950 if (runTasksBeforeIncremental) { 4980 if (runTasksBeforeIncremental) {
4951 _runTasks(); 4981 _runTasks();
4952 } 4982 }
4953 // Update the source - currently this may cause incremental resolution. 4983 // Update the source - currently this may cause incremental resolution.
4954 // Then request the updated resolved unit. 4984 // Then request the updated resolved unit.
4955 _resetWithIncremental(true); 4985 _resetWithIncremental(true);
4956 analysisContext2.setContents(source, newCode); 4986 analysisContext2.setContents(source, newCode);
4957 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); 4987 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary);
4958 expect(logger.hasError, isFalse); 4988 if (logger.hasError) {
4989 fail("logged an error: ${logger.lastError}");
4990 }
4959 List<AnalysisError> newErrors = analysisContext.computeErrors(source); 4991 List<AnalysisError> newErrors = analysisContext.computeErrors(source);
4960 LineInfo newLineInfo = analysisContext.getLineInfo(source); 4992 LineInfo newLineInfo = analysisContext.getLineInfo(source);
4961 // check for expected failure 4993 // check for expected failure
4962 if (!expectedSuccess) { 4994 if (!expectedSuccess) {
4963 expect(newUnit.element, isNot(same(oldUnitElement))); 4995 expect(newUnit.element, isNot(same(oldUnitElement)));
4964 return; 4996 return;
4965 } 4997 }
4966 // The cache must still have enough results to make the incremental 4998 // The cache must still have enough results to make the incremental
4967 // resolution useful. 4999 // resolution useful.
4968 _assertCacheResults( 5000 _assertCacheResults(
5001 expectLibraryUnchanged: expectLibraryUnchanged,
4969 expectCachePostConstantsValid: expectCachePostConstantsValid); 5002 expectCachePostConstantsValid: expectCachePostConstantsValid);
4970 // The existing CompilationUnit[Element] should be updated. 5003 // The existing CompilationUnit[Element] should be updated.
4971 expect(newUnit, same(oldUnit)); 5004 expect(newUnit, same(oldUnit));
4972 expect(newUnit.element, same(oldUnitElement)); 5005 expect(newUnit.element, same(oldUnitElement));
4973 expect(analysisContext.getResolvedCompilationUnit(source, oldLibrary), 5006 expect(analysisContext.getResolvedCompilationUnit(source, oldLibrary),
4974 same(oldUnit)); 5007 same(oldUnit));
4975 // The only expected pending task should return the same resolved 5008 // The only expected pending task should return the same resolved
4976 // "newUnit", so all clients will get it using the usual way. 5009 // "newUnit", so all clients will get it using the usual way.
4977 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); 5010 AnalysisResult analysisResult = analysisContext.performAnalysisTask();
4978 ChangeNotice notice = analysisResult.changeNotices[0]; 5011 ChangeNotice notice = analysisResult.changeNotices[0];
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
5248 } 5281 }
5249 5282
5250 class _Edit { 5283 class _Edit {
5251 final int offset; 5284 final int offset;
5252 final int length; 5285 final int length;
5253 final String replacement; 5286 final String replacement;
5254 _Edit(this.offset, this.length, this.replacement); 5287 _Edit(this.offset, this.length, this.replacement);
5255 } 5288 }
5256 5289
5257 class _TestLogger implements logging.Logger { 5290 class _TestLogger implements logging.Logger {
5258 bool hasError = false; 5291 Object lastError;
5292
5293 bool get hasError => lastError != null;
5259 5294
5260 @override 5295 @override
5261 void enter(String name) {} 5296 void enter(String name) {}
5262 5297
5263 @override 5298 @override
5264 void exit() {} 5299 void exit() {}
5265 5300
5266 @override 5301 @override
5267 void log(Object obj) {} 5302 void log(Object obj) {}
5268 5303
5269 @override 5304 @override
5270 void logException(Object exception, [Object stackTrace]) { 5305 void logException(Object exception, [Object stackTrace]) {
5271 hasError = true; 5306 lastError = exception;
Brian Wilkerson 2016/02/16 15:10:48 Seems like it would be useful to also capture the
skybrian 2016/02/17 01:23:41 Done.
5272 } 5307 }
5273 5308
5274 @override 5309 @override
5275 logging.LoggingTimer startTimer() { 5310 logging.LoggingTimer startTimer() {
5276 return new logging.LoggingTimer(this); 5311 return new logging.LoggingTimer(this);
5277 } 5312 }
5278 } 5313 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698