Remove unused AnalysisDriver flag 'disableChangesAndCacheAllResults'.

R=brianwilkerson@google.com

Change-Id: Ic9a98493496cf875434d0d6c2246721d4985c8c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152707
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2020-06-26 21:16:38 +00:00 committed by commit-bot@chromium.org
parent 4472284758
commit 4b93c8aabd
3 changed files with 1 additions and 135 deletions

View file

@ -235,28 +235,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
/// The [FileTracker] used by this driver.
FileTracker _fileTracker;
/// When this flag is set to `true`, the set of analyzed files must not change,
/// and all [AnalysisResult]s are cached infinitely.
///
/// The flag is intended to be used for non-interactive clients, like DDC,
/// which start a new analysis session, load a set of files, resolve all of
/// them, process the resolved units, and then throw away that whole session.
///
/// The key problem that this flag is solving is that the driver analyzes the
/// whole library when the result for a unit of the library is requested. So,
/// when the client requests sequentially the defining unit, then the first
/// part, then the second part, the driver has to perform analysis of the
/// library three times and every time throw away all the units except the one
/// which was requested. With this flag set to `true`, the driver can analyze
/// once and cache all the resolved units.
final bool disableChangesAndCacheAllResults;
/// Whether resolved units should be indexed.
final bool enableIndex;
/// The cache to use with [disableChangesAndCacheAllResults].
final Map<String, AnalysisResult> _allCachedResults = {};
/// The current analysis session.
AnalysisSessionImpl _currentSession;
@ -288,7 +269,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
SourceFactory sourceFactory,
this._analysisOptions,
{Packages packages,
this.disableChangesAndCacheAllResults = false,
this.enableIndex = false,
SummaryDataStore externalSummaries,
bool retainDataForTesting = false})
@ -482,7 +462,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
/// [changeFile] invocation.
void changeFile(String path) {
_throwIfNotAbsolutePath(path);
_throwIfChangesAreNotAllowed();
_changeFile(path);
}
@ -547,11 +526,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
/// The [path] can be any file - explicitly or implicitly analyzed, or neither.
ResolvedUnitResult getCachedResult(String path) {
_throwIfNotAbsolutePath(path);
ResolvedUnitResult result = _priorityResults[path];
if (disableChangesAndCacheAllResults) {
result ??= _allCachedResults[path];
}
return result;
return _priorityResults[path];
}
/// Return a [Future] that completes with the [ErrorsResult] for the Dart
@ -1179,7 +1154,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
/// but does not guarantee this.
void removeFile(String path) {
_throwIfNotAbsolutePath(path);
_throwIfChangesAreNotAllowed();
_fileTracker.removeFile(path);
clearLibraryContext();
_priorityResults.clear();
@ -1323,12 +1297,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
bytes = unitBytes;
resolvedUnit = unitResult.unit;
}
if (disableChangesAndCacheAllResults) {
AnalysisResult result = _getAnalysisResultFromBytes(
unitFile, unitSignature, unitBytes,
content: unitFile.content, resolvedUnit: unitResult.unit);
_allCachedResults[unitFile.path] = result;
}
}
// Return the result, full or partial.
@ -1723,14 +1691,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
}
}
/// If the driver is used in the read-only mode with infinite cache,
/// we should not allow invocations that change files.
void _throwIfChangesAreNotAllowed() {
if (disableChangesAndCacheAllResults) {
throw StateError('Changing files is not allowed for this driver.');
}
}
/// The driver supports only absolute paths, this method is used to validate
/// any input paths to prevent errors later.
void _throwIfNotAbsolutePath(String path) {

View file

@ -66,8 +66,6 @@ class BaseAnalysisDriverTest with ResourceProviderMixin {
List<String> enabledExperiments = [];
bool get disableChangesAndCacheAllResults => false;
void addTestFile(String content, {bool priority = false}) {
testCode = content;
newFile(testFile, content: content);
@ -100,7 +98,6 @@ class BaseAnalysisDriverTest with ResourceProviderMixin {
]),
createAnalysisOptions(),
packages: Packages.empty,
disableChangesAndCacheAllResults: disableChangesAndCacheAllResults,
enableIndex: true,
externalSummaries: externalSummaries);
}

View file

@ -36,7 +36,6 @@ main() {
defineReflectiveSuite(() {
defineReflectiveTests(AnalysisDriverSchedulerTest);
defineReflectiveTests(AnalysisDriverTest);
defineReflectiveTests(CacheAllAnalysisDriverTest);
});
}
@ -3168,96 +3167,6 @@ var v = 0
}
}
@reflectiveTest
class CacheAllAnalysisDriverTest extends BaseAnalysisDriverTest {
@override
bool get disableChangesAndCacheAllResults => true;
test_addFile() async {
var a = convertPath('/test/lib/a.dart');
var b = convertPath('/test/lib/b.dart');
driver.addFile(a);
driver.addFile(b);
}
test_changeFile() async {
var path = convertPath('/test.dart');
expect(() {
driver.changeFile(path);
}, throwsStateError);
}
test_getResult_libraryUnits() async {
var lib = convertPath('/lib.dart');
var part1 = convertPath('/part1.dart');
var part2 = convertPath('/part2.dart');
newFile(lib, content: r'''
library test;
part 'part1.dart';
part 'part2.dart';
''');
newFile(part1, content: 'part of test; class A {}');
newFile(part2, content: 'part of test; class B {}');
driver.addFile(lib);
driver.addFile(part1);
driver.addFile(part2);
// No analyzed libraries initially.
expect(driver.test.numOfAnalyzedLibraries, 0);
ResolvedUnitResult libResult = await driver.getResult(lib);
ResolvedUnitResult partResult1 = await driver.getResult(part1);
ResolvedUnitResult partResult2 = await driver.getResult(part2);
// Just one library was analyzed, results for parts are cached.
expect(driver.test.numOfAnalyzedLibraries, 1);
expect(libResult.path, lib);
expect(partResult1.path, part1);
expect(partResult2.path, part2);
expect(libResult.unit, isNotNull);
expect(partResult1.unit, isNotNull);
expect(partResult2.unit, isNotNull);
// The parts uses the same resynthesized library element.
var libLibrary = libResult.unit.declaredElement.library;
var partLibrary1 = partResult1.unit.declaredElement.library;
var partLibrary2 = partResult2.unit.declaredElement.library;
expect(partLibrary1, same(libLibrary));
expect(partLibrary2, same(libLibrary));
}
test_getResult_singleFile() async {
var path = convertPath('/test.dart');
newFile(path, content: 'main() {}');
driver.addFile(path);
ResolvedUnitResult result1 = await driver.getResult(path);
expect(driver.test.numOfAnalyzedLibraries, 1);
var unit1 = result1.unit;
var unitElement1 = unit1.declaredElement;
expect(result1.path, path);
expect(unit1, isNotNull);
expect(unitElement1, isNotNull);
ResolvedUnitResult result2 = await driver.getResult(path);
expect(driver.test.numOfAnalyzedLibraries, 1);
expect(result2.path, path);
expect(result2.unit, same(unit1));
expect(result2.unit.declaredElement, same(unitElement1));
}
test_removeFile() async {
var path = convertPath('/test.dart');
expect(() {
driver.removeFile(path);
}, throwsStateError);
}
}
class _SourceMock implements Source {
@override
final String fullName;