diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart index 5c091a33b02..9ab564c6e70 100644 --- a/pkg/analyzer/lib/src/dart/analysis/driver.dart +++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart @@ -574,9 +574,7 @@ class AnalysisDriver { addFile(file.path); } - void afterPerformWork() { - _fsState.clearParsedFileStateCache(); - } + void afterPerformWork() {} /// Return a [Future] that completes after pending file changes are applied, /// so that [currentSession] can be used to compute results. diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart index 7d24199fca9..098443e877a 100644 --- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart +++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart @@ -13,7 +13,6 @@ import 'package:analyzer/dart/analysis/declared_variables.dart'; import 'package:analyzer/dart/analysis/features.dart'; import 'package:analyzer/dart/ast/token.dart'; import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/diagnostic/diagnostic.dart'; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/source/file_source.dart'; @@ -656,7 +655,6 @@ class FileState { var rawFileState = _fsState.fileContentStrategy.get(path); var contentChanged = _fileContent?.contentHash != rawFileState.contentHash; _fileContent = rawFileState; - _fsState._parsedFileStateCache.remove(this); // Prepare the unlinked bundle key. var previousUnlinkedKey = _unlinkedKey; @@ -802,30 +800,6 @@ class FileState { return _fsState.getFileForUri(absoluteUri); } - /// Returns either new, or cached parsed result for this file. - _ParsedFileState _getParsed({required OperationPerformanceImpl performance}) { - var result = _fsState._parsedFileStateCache.get(this); - if (result != null) { - return result; - } - - var diagnosticListener = RecordingDiagnosticListener(); - var unit = parseCode( - code: content, - diagnosticListener: diagnosticListener, - performance: performance, - ); - - result = _ParsedFileState( - code: content, - unit: unit, - diagnostics: diagnosticListener.diagnostics, - ); - _fsState._parsedFileStateCache.put(this, result); - - return result; - } - /// Return the unlinked unit, freshly deserialized from bytes, /// previously deserialized from bytes, or new. AnalysisDriverUnlinkedUnit _getUnlinkedUnit( @@ -855,7 +829,7 @@ class FileState { return result; } - var unit = _getParsed(performance: performance).unit; + var unit = parse(performance: performance); return performance.run('compute', (performance) { var unlinkedUnit = performance.run('serializeAstUnlinked2', ( @@ -1280,12 +1254,6 @@ class FileSystemState { /// store here the instance to attach [_newFile] operations. OperationPerformanceImpl? newFileOperationPerformance; - /// We cache results of parsing [FileState]s because they might be useful - /// in the process of a single analysis operation. But after that, even - /// if these results are still valid, they are often never used again. So, - /// currently we clear the cache after each operation. - final _ParsedFileStateCache _parsedFileStateCache = _ParsedFileStateCache(); - FileSystemState( this._byteStore, this.resourceProvider, @@ -1340,11 +1308,6 @@ class FileSystemState { } } - /// Clears the parsed file state cache. - void clearParsedFileStateCache() { - _parsedFileStateCache.clear(); - } - /// Collected files that transitively reference a file with the [path]. /// These files are potentially affected by the change. void collectAffected(String path, Set affected) { @@ -2399,38 +2362,6 @@ class _LibraryNameToFiles { } } -class _ParsedFileState { - final String code; - final CompilationUnitImpl unit; - final List diagnostics; - - _ParsedFileState({ - required this.code, - required this.unit, - required this.diagnostics, - }); -} - -class _ParsedFileStateCache { - final Map _map = Map.identity(); - - void clear() { - _map.clear(); - } - - _ParsedFileState? get(FileState file) { - return _map[file]; - } - - void put(FileState file, _ParsedFileState result) { - _map[file] = result; - } - - void remove(FileState file) { - _map.remove(file); - } -} - extension on List { void disposeAll() { for (var directive in this) { diff --git a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart index 366280a9662..0425694d730 100644 --- a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart +++ b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart @@ -304,7 +304,6 @@ class FileResolver { for (var filePath in result) { await collectReferences2(filePath, performance!); } - _clearFileSystemStateParsedCache(); } return references; }); @@ -415,7 +414,6 @@ class FileResolver { performance.run('libraryContext', (performance) { libraryContext!.load(targetLibrary: kind, performance: performance); - _clearFileSystemStateParsedCache(); }); return libraryContext!.elementFactory.libraryOfUri2(uri); @@ -515,7 +513,6 @@ class FileResolver { path: libraryFile.path, performance: performance, ); - _clearFileSystemStateParsedCache(); var unit = libraryResult.units.firstWhereOrNull( (unitResult) => unitResult.path == path, ); @@ -575,7 +572,6 @@ class FileResolver { performance: OperationPerformanceImpl(''), typeSystemOperations: typeSystemOperations, ); - _clearFileSystemStateParsedCache(); var analysisResult = performance!.run('analyze', (performance) { return libraryAnalyzer.analyzeForCompletion( @@ -678,10 +674,6 @@ class FileResolver { }); } - void _clearFileSystemStateParsedCache() { - fsState?.clearParsedFileStateCache(); - } - /// Make sure that [fsState], [contextObjects], and [libraryContext] are /// created and configured with the given [fileAnalysisOptions]. /// @@ -695,10 +687,6 @@ class FileResolver { /// system. And there are lints that are enabled for one package, but not /// for another. void _createContext(String path, AnalysisOptionsImpl fileAnalysisOptions) { - // Clear it here too, so that even if we miss the invocation somewhere, - // we still eventually do it, and so limit the number of cached items. - _clearFileSystemStateParsedCache(); - if (contextObjects != null) { libraryContext!.analysisContext.analysisOptions = fileAnalysisOptions; return;