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

Unified Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 1650873002: Fix memory leak in incremental resolver (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: simplify and improve tests Created 4 years, 11 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/incremental_resolver.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/incremental_resolver_test.dart
diff --git a/pkg/analyzer/test/generated/incremental_resolver_test.dart b/pkg/analyzer/test/generated/incremental_resolver_test.dart
index 6b321b0e1df188d82bc7bd2a82f6238bb7bfdae5..201b783e0578c22a646eb78b15735d2d1791d66c 100644
--- a/pkg/analyzer/test/generated/incremental_resolver_test.dart
+++ b/pkg/analyzer/test/generated/incremental_resolver_test.dart
@@ -22,8 +22,10 @@ import 'package:analyzer/src/generated/scanner.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/generated/testing/ast_factory.dart';
import 'package:analyzer/src/generated/testing/element_factory.dart';
+import 'package:analyzer/src/generated/utilities_collection.dart';
import 'package:analyzer/src/task/dart.dart';
import 'package:analyzer/task/dart.dart';
+import 'package:analyzer/task/model.dart';
import 'package:unittest/unittest.dart';
import '../reflective_tests.dart';
@@ -118,6 +120,21 @@ void _assertEqualErrors(
}
}
+void _checkCacheEntries(AnalysisCache cache) {
+ Set seen = new Set();
+ MapIterator<AnalysisTarget, CacheEntry> it = cache.iterator();
+ while (it.moveNext()) {
+ AnalysisTarget key = it.key;
+ if (cache.get(key) == null) {
Brian Wilkerson 2016/02/02 22:51:14 Would the test cache.get(key) != it.value be b
scheglov 2016/02/02 23:04:25 `it.value` works mostly as `cache.get(key)`. So, i
skybrian 2016/02/02 23:27:02 Yes, the old value is (usually) no longer accessib
+ fail("cache corrupted: value of $key changed to null");
+ }
+ if (seen.contains(key)) {
Brian Wilkerson 2016/02/02 22:51:14 nit: just use "!seen.add(key)" here and remove lin
skybrian 2016/02/02 23:27:02 Done.
+ fail("cache corrupted: $key appears more than once");
+ }
+ seen.add(key);
+ }
+}
+
@reflectiveTest
class DeclarationMatcherTest extends ResolverTestCase {
void setUp() {
@@ -3121,6 +3138,21 @@ class A {
_resolve(_editString('+', '*'), _isFunctionBody);
}
+ void test_computeConstants_offsetChanged() {
+ _resolveUnit(r'''
+int f() => 0;
+main() {
+ const x1 = f();
+ const x2 = f();
+ const x3 = f();
+ const x4 = f();
+ const x5 = f();
+ print(x1 + x2 + x3 + x4 + x5 + 1);
+}
+''');
+ _resolve(_editString('x1', ' x1'), _isFunctionBody);
+ }
+
void test_constructor_body() {
_resolveUnit(r'''
class A {
@@ -3426,6 +3458,9 @@ class B {
edit.replacement +
code.substring(offset + edit.length);
CompilationUnit newUnit = _parseUnit(newCode);
+ AnalysisCache cache = analysisContext2.analysisCache;
+ _checkCacheEntries(cache);
+
// replace the node
AstNode oldNode = _findNodeAt(unit, offset, predicate);
AstNode newNode = _findNodeAt(newUnit, offset, predicate);
@@ -3444,11 +3479,12 @@ class B {
int updateOldNew = updateOffset + edit.replacement.length;
IncrementalResolver resolver;
LibrarySpecificUnit lsu = new LibrarySpecificUnit(source, source);
- AnalysisCache cache = analysisContext2.analysisCache;
- resolver = new IncrementalResolver(cache.get(source), cache.get(lsu),
+ resolver = new IncrementalResolver(cache, cache.get(source), cache.get(lsu),
unit.element, updateOffset, updateEndOld, updateOldNew);
bool success = resolver.resolve(newNode);
expect(success, isTrue);
+ _checkCacheEntries(cache);
+
List<AnalysisError> newErrors = analysisContext.computeErrors(source);
// resolve "newCode" from scratch
CompilationUnit fullNewUnit;
@@ -3458,6 +3494,8 @@ class B {
LibraryElement library = resolve2(source);
fullNewUnit = resolveCompilationUnit(source, library);
}
+ _checkCacheEntries(cache);
+
try {
assertSameResolution(unit, fullNewUnit);
} on IncrementalResolutionMismatch catch (mismatch) {
@@ -3477,6 +3515,7 @@ class B {
library = resolve2(source);
unit = resolveCompilationUnit(source, library);
_runTasks();
+ _checkCacheEntries(analysisContext2.analysisCache);
}
void _runTasks() {
@@ -4867,6 +4906,7 @@ class B extends A {}
analysisContext.getErrors(source).errors;
_assertEqualErrors(newErrors, newFullErrors);
}
+ _checkCacheEntries(analysisContext2.analysisCache);
}
static void _assertEqualToken(Token incrToken, Token fullToken) {
« no previous file with comments | « pkg/analyzer/lib/src/generated/incremental_resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698