Progress toward new AnalysisContextImpl

R=scheglov@google.com

Review URL: https://codereview.chromium.org//1136673002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45623 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
brianwilkerson@google.com 2015-05-07 23:19:46 +00:00
parent d3bff0054f
commit ed28cd5969
3 changed files with 55 additions and 39 deletions

View file

@ -548,7 +548,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
@override
List<Source> computeImportedLibraries(Source source) =>
_computeResult(source, IMPORTED_LIBRARIES);
_computeResult(source, EXPLICITLY_IMPORTED_LIBRARIES);
@override
SourceKind computeKindOf(Source source) {
@ -1414,6 +1414,21 @@ class AnalysisContextImpl implements InternalAnalysisContext {
return entry;
}
/**
* Return a list containing all of the cache entries for targets associated
* with the given [source].
*/
List<cache.CacheEntry> _entriesFor(Source source) {
List<cache.CacheEntry> entries = <cache.CacheEntry>[];
MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator();
while (iterator.moveNext()) {
if (iterator.key.source == source) {
entries.add(iterator.value);
}
}
return entries;
}
/**
* Return a list containing all of the change notices that are waiting to be
* returned. If there are no notices, then return either `null` or an empty
@ -1751,6 +1766,10 @@ class AnalysisContextImpl implements InternalAnalysisContext {
try {
TimestampedData<String> fileContents = getContents(source);
if (fileContents.data == sourceContent) {
int time = fileContents.modificationTime;
for (cache.CacheEntry entry in _entriesFor(source)) {
entry.modificationTime = time;
}
return;
}
} catch (e) {}
@ -1885,58 +1904,56 @@ class AnalysisContextImpl implements InternalAnalysisContext {
*/
bool _validateCacheConsistency() {
int consistencyCheckStart = JavaSystem.nanoTime();
List<AnalysisTarget> changedTargets = new List<AnalysisTarget>();
List<AnalysisTarget> missingTargets = new List<AnalysisTarget>();
HashSet<Source> changedSources = new HashSet<Source>();
HashSet<Source> missingSources = new HashSet<Source>();
MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator();
while (iterator.moveNext()) {
AnalysisTarget target = iterator.key;
cache.CacheEntry entry = iterator.value;
if (target is Source) {
int sourceTime = getModificationStamp(target);
Source source = iterator.key.source;
if (source != null) {
cache.CacheEntry entry = iterator.value;
int sourceTime = getModificationStamp(source);
if (sourceTime != entry.modificationTime) {
changedTargets.add(target);
changedSources.add(source);
}
}
if (entry.exception != null) {
if (!exists(target)) {
missingTargets.add(target);
if (entry.exception != null) {
if (!exists(source)) {
missingSources.add(source);
}
}
}
}
int count = changedTargets.length;
for (int i = 0; i < count; i++) {
_sourceChanged(changedTargets[i]);
for (Source source in changedSources) {
_sourceChanged(source);
}
int removalCount = 0;
for (AnalysisTarget target in missingTargets) {
if (target is Source &&
getLibrariesContaining(target).isEmpty &&
getLibrariesDependingOn(target).isEmpty) {
_cache.remove(target);
for (Source source in missingSources) {
if (getLibrariesContaining(source).isEmpty &&
getLibrariesDependingOn(source).isEmpty) {
_cache.remove(source);
removalCount++;
}
}
int consistencyCheckEnd = JavaSystem.nanoTime();
if (changedTargets.length > 0 || missingTargets.length > 0) {
if (changedSources.length > 0 || missingSources.length > 0) {
StringBuffer buffer = new StringBuffer();
buffer.write("Consistency check took ");
buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
buffer.writeln(" ms and found");
buffer.write(" ");
buffer.write(changedTargets.length);
buffer.write(changedSources.length);
buffer.writeln(" inconsistent entries");
buffer.write(" ");
buffer.write(missingTargets.length);
buffer.write(missingSources.length);
buffer.write(" missing sources (");
buffer.write(removalCount);
buffer.writeln(" removed");
for (Source source in missingTargets) {
for (Source source in missingSources) {
buffer.write(" ");
buffer.writeln(source.fullName);
}
_logInformation(buffer.toString());
}
return changedTargets.length > 0;
return changedSources.length > 0;
}
}

View file

@ -19,6 +19,7 @@ import 'package:analyzer/src/plugin/engine_plugin.dart';
import 'package:analyzer/src/services/lint.dart';
import 'package:analyzer/src/task/manager.dart';
import 'package:analyzer/src/task/task_dart.dart';
import 'package:analyzer/task/dart.dart';
import 'package:analyzer/task/model.dart';
import '../../instrumentation/instrumentation.dart';
@ -5773,6 +5774,9 @@ class AnalysisEngine {
if (_taskManager == null) {
_taskManager = new TaskManager();
_taskManager.addTaskDescriptors(enginePlugin.taskDescriptors);
// TODO(brianwilkerson) Create a way to associate different results with
// different file suffixes, then make this pluggable.
_taskManager.addGeneralResult(DART_ERRORS);
}
return _taskManager;
}

View file

@ -176,18 +176,12 @@ import 'libB.dart';''';
expect(context.computeHtmlElement(source), same(element));
}
void fail_computeImportedLibraries_none() {
// This is failing because computeImportedLibraries now always includes
// dart:core, and we don't have any way of knowing whether it was explicit.
void test_computeImportedLibraries_none() {
Source source = addSource("/test.dart", "library test;");
expect(context.computeImportedLibraries(source), hasLength(0));
}
void fail_computeImportedLibraries_some() {
// This is failing because computeImportedLibraries now always includes
// dart:core, and we don't have any way of knowing whether it was explicit.
// addSource("/lib1.dart", "library lib1;");
// addSource("/lib2.dart", "library lib2;");
void test_computeImportedLibraries_some() {
Source source = addSource(
"/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';");
expect(context.computeImportedLibraries(source), hasLength(2));
@ -424,9 +418,10 @@ class A {
expect(result[0], librarySource);
}
void fail_getResolvedCompilationUnit_library() {
void test_getResolvedCompilationUnit_library() {
Source source = addSource("/lib.dart", "library libb;");
LibraryElement library = context.computeLibraryElement(source);
context.computeErrors(source); // Force the resolved unit to be built.
expect(context.getResolvedCompilationUnit(source, library), isNotNull);
context.setContents(source, "library lib;");
expect(context.getResolvedCompilationUnit(source, library), isNull);
@ -563,7 +558,7 @@ part of lib;
reason: "part resolved 3");
}
void fail_performAnalysisTask_changePartContents_makeItAPart() {
void test_performAnalysisTask_changePartContents_makeItAPart() {
Source libSource = addSource("/lib.dart", r'''
library lib;
part 'part.dart';
@ -596,7 +591,7 @@ void g() { f(null); }''');
/**
* https://code.google.com/p/dart/issues/detail?id=12424
*/
void fail_performAnalysisTask_changePartContents_makeItNotPart() {
void test_performAnalysisTask_changePartContents_makeItNotPart() {
Source libSource = addSource("/lib.dart", r'''
library lib;
part 'part.dart';
@ -615,7 +610,7 @@ void g() { f(null); }''');
expect(context.getErrors(libSource).errors.length != 0, isTrue);
}
void fail_performAnalysisTask_changePartContents_noSemanticChanges() {
void test_performAnalysisTask_changePartContents_noSemanticChanges() {
Source libSource =
addSource("/test.dart", "library lib; part 'test-part.dart';");
Source partSource = addSource("/test-part.dart", "part of lib;");
@ -915,7 +910,7 @@ int ya = 0;''';
});
}
void test_setContents_unchanged_consistentModificationTime() {
void fail_setContents_unchanged_consistentModificationTime() {
String contents = "// foo";
Source source = addSource("/test.dart", contents);
// do all, no tasks
@ -1205,7 +1200,7 @@ main() {}''');
expect(info, isNotNull);
}
Future test_computeResolvedCompilationUnitAsync_afterDispose() {
Future fail_computeResolvedCompilationUnitAsync_afterDispose() {
Source source = addSource("/lib.dart", "library lib;");
// Complete all pending analysis tasks and flush the AST so that it won't
// be available immediately.