Skip to content

Commit eff3522

Browse files
scheglovCommit Queue
authored andcommitted
CQ. Remove not useful _ParsedFileStateCache.
It was used to support macros, so is not useful anymore. Change-Id: I12b98ed75125bc59473c9048a9f35554b5f33eae Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435561 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent f5eaefd commit eff3522

File tree

3 files changed

+2
-85
lines changed

3 files changed

+2
-85
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,7 @@ class AnalysisDriver {
574574
addFile(file.path);
575575
}
576576

577-
void afterPerformWork() {
578-
_fsState.clearParsedFileStateCache();
579-
}
577+
void afterPerformWork() {}
580578

581579
/// Return a [Future] that completes after pending file changes are applied,
582580
/// so that [currentSession] can be used to compute results.

pkg/analyzer/lib/src/dart/analysis/file_state.dart

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import 'package:analyzer/dart/analysis/declared_variables.dart';
1313
import 'package:analyzer/dart/analysis/features.dart';
1414
import 'package:analyzer/dart/ast/token.dart';
1515
import 'package:analyzer/dart/element/element.dart';
16-
import 'package:analyzer/diagnostic/diagnostic.dart';
1716
import 'package:analyzer/error/listener.dart';
1817
import 'package:analyzer/file_system/file_system.dart';
1918
import 'package:analyzer/source/file_source.dart';
@@ -656,7 +655,6 @@ class FileState {
656655
var rawFileState = _fsState.fileContentStrategy.get(path);
657656
var contentChanged = _fileContent?.contentHash != rawFileState.contentHash;
658657
_fileContent = rawFileState;
659-
_fsState._parsedFileStateCache.remove(this);
660658

661659
// Prepare the unlinked bundle key.
662660
var previousUnlinkedKey = _unlinkedKey;
@@ -802,30 +800,6 @@ class FileState {
802800
return _fsState.getFileForUri(absoluteUri);
803801
}
804802

805-
/// Returns either new, or cached parsed result for this file.
806-
_ParsedFileState _getParsed({required OperationPerformanceImpl performance}) {
807-
var result = _fsState._parsedFileStateCache.get(this);
808-
if (result != null) {
809-
return result;
810-
}
811-
812-
var diagnosticListener = RecordingDiagnosticListener();
813-
var unit = parseCode(
814-
code: content,
815-
diagnosticListener: diagnosticListener,
816-
performance: performance,
817-
);
818-
819-
result = _ParsedFileState(
820-
code: content,
821-
unit: unit,
822-
diagnostics: diagnosticListener.diagnostics,
823-
);
824-
_fsState._parsedFileStateCache.put(this, result);
825-
826-
return result;
827-
}
828-
829803
/// Return the unlinked unit, freshly deserialized from bytes,
830804
/// previously deserialized from bytes, or new.
831805
AnalysisDriverUnlinkedUnit _getUnlinkedUnit(
@@ -855,7 +829,7 @@ class FileState {
855829
return result;
856830
}
857831

858-
var unit = _getParsed(performance: performance).unit;
832+
var unit = parse(performance: performance);
859833

860834
return performance.run('compute', (performance) {
861835
var unlinkedUnit = performance.run('serializeAstUnlinked2', (
@@ -1280,12 +1254,6 @@ class FileSystemState {
12801254
/// store here the instance to attach [_newFile] operations.
12811255
OperationPerformanceImpl? newFileOperationPerformance;
12821256

1283-
/// We cache results of parsing [FileState]s because they might be useful
1284-
/// in the process of a single analysis operation. But after that, even
1285-
/// if these results are still valid, they are often never used again. So,
1286-
/// currently we clear the cache after each operation.
1287-
final _ParsedFileStateCache _parsedFileStateCache = _ParsedFileStateCache();
1288-
12891257
FileSystemState(
12901258
this._byteStore,
12911259
this.resourceProvider,
@@ -1340,11 +1308,6 @@ class FileSystemState {
13401308
}
13411309
}
13421310

1343-
/// Clears the parsed file state cache.
1344-
void clearParsedFileStateCache() {
1345-
_parsedFileStateCache.clear();
1346-
}
1347-
13481311
/// Collected files that transitively reference a file with the [path].
13491312
/// These files are potentially affected by the change.
13501313
void collectAffected(String path, Set<FileState> affected) {
@@ -2399,38 +2362,6 @@ class _LibraryNameToFiles {
23992362
}
24002363
}
24012364

2402-
class _ParsedFileState {
2403-
final String code;
2404-
final CompilationUnitImpl unit;
2405-
final List<Diagnostic> diagnostics;
2406-
2407-
_ParsedFileState({
2408-
required this.code,
2409-
required this.unit,
2410-
required this.diagnostics,
2411-
});
2412-
}
2413-
2414-
class _ParsedFileStateCache {
2415-
final Map<FileState, _ParsedFileState> _map = Map.identity();
2416-
2417-
void clear() {
2418-
_map.clear();
2419-
}
2420-
2421-
_ParsedFileState? get(FileState file) {
2422-
return _map[file];
2423-
}
2424-
2425-
void put(FileState file, _ParsedFileState result) {
2426-
_map[file] = result;
2427-
}
2428-
2429-
void remove(FileState file) {
2430-
_map.remove(file);
2431-
}
2432-
}
2433-
24342365
extension on List<DirectiveState> {
24352366
void disposeAll() {
24362367
for (var directive in this) {

pkg/analyzer/lib/src/dart/micro/resolve_file.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ class FileResolver {
304304
for (var filePath in result) {
305305
await collectReferences2(filePath, performance!);
306306
}
307-
_clearFileSystemStateParsedCache();
308307
}
309308
return references;
310309
});
@@ -415,7 +414,6 @@ class FileResolver {
415414

416415
performance.run('libraryContext', (performance) {
417416
libraryContext!.load(targetLibrary: kind, performance: performance);
418-
_clearFileSystemStateParsedCache();
419417
});
420418

421419
return libraryContext!.elementFactory.libraryOfUri2(uri);
@@ -515,7 +513,6 @@ class FileResolver {
515513
path: libraryFile.path,
516514
performance: performance,
517515
);
518-
_clearFileSystemStateParsedCache();
519516
var unit = libraryResult.units.firstWhereOrNull(
520517
(unitResult) => unitResult.path == path,
521518
);
@@ -575,7 +572,6 @@ class FileResolver {
575572
performance: OperationPerformanceImpl('<root>'),
576573
typeSystemOperations: typeSystemOperations,
577574
);
578-
_clearFileSystemStateParsedCache();
579575

580576
var analysisResult = performance!.run('analyze', (performance) {
581577
return libraryAnalyzer.analyzeForCompletion(
@@ -678,10 +674,6 @@ class FileResolver {
678674
});
679675
}
680676

681-
void _clearFileSystemStateParsedCache() {
682-
fsState?.clearParsedFileStateCache();
683-
}
684-
685677
/// Make sure that [fsState], [contextObjects], and [libraryContext] are
686678
/// created and configured with the given [fileAnalysisOptions].
687679
///
@@ -695,10 +687,6 @@ class FileResolver {
695687
/// system. And there are lints that are enabled for one package, but not
696688
/// for another.
697689
void _createContext(String path, AnalysisOptionsImpl fileAnalysisOptions) {
698-
// Clear it here too, so that even if we miss the invocation somewhere,
699-
// we still eventually do it, and so limit the number of cached items.
700-
_clearFileSystemStateParsedCache();
701-
702690
if (contextObjects != null) {
703691
libraryContext!.analysisContext.analysisOptions = fileAnalysisOptions;
704692
return;

0 commit comments

Comments
 (0)