mirror of
https://github.com/dart-lang/sdk
synced 2024-10-15 00:10:36 +00:00
Add FileResolver.dispose(), instead of collectSharedDataIdentifiers().
Also include 'loadedBundles' into the textual dump. Change-Id: Iba7bfe89dcb085bdcddcd20902d4148b9fa5095a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247325 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
cb2d5c972f
commit
38f6d41e55
|
@ -335,16 +335,6 @@ class FileSystemState {
|
|||
}
|
||||
}
|
||||
|
||||
/// Clears all the cached files. Returns the list of keys of all the removed
|
||||
/// files.
|
||||
Set<String> collectSharedDataKeys() {
|
||||
var result = <String>{};
|
||||
for (var file in _pathToFile.values) {
|
||||
result.add(file._unlinked.unlinkedKey);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
FeatureSet contextFeatureSet(
|
||||
String path,
|
||||
Uri uri,
|
||||
|
@ -373,6 +363,19 @@ class FileSystemState {
|
|||
return featureSetProvider.getLanguageVersion(path, uri);
|
||||
}
|
||||
|
||||
/// Notifies this object that it is about to be discarded.
|
||||
///
|
||||
/// Returns the keys of the artifacts that are no longer used.
|
||||
Set<String> dispose() {
|
||||
final result = <String>{};
|
||||
for (final file in _pathToFile.values) {
|
||||
result.add(file._unlinked.unlinkedKey);
|
||||
}
|
||||
_pathToFile.clear();
|
||||
_uriToFile.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
FileState? getExistingFileForResource(File file) {
|
||||
return _pathToFile[file.path];
|
||||
|
|
|
@ -186,9 +186,18 @@ class FileResolver {
|
|||
|
||||
/// Collects all the cached artifacts and add all the cache id's for the
|
||||
/// removed artifacts to [removedCacheKeys].
|
||||
@Deprecated('Use dispose() instead')
|
||||
void collectSharedDataIdentifiers() {
|
||||
removedCacheKeys.addAll(fsState!.collectSharedDataKeys());
|
||||
removedCacheKeys.addAll(libraryContext!.collectSharedDataKeys());
|
||||
removedCacheKeys.addAll(fsState!.dispose());
|
||||
removedCacheKeys.addAll(libraryContext!.dispose());
|
||||
}
|
||||
|
||||
/// Notifies this object that it is about to be discarded, so it should
|
||||
/// release any shared data.
|
||||
void dispose() {
|
||||
removedCacheKeys.addAll(fsState!.dispose());
|
||||
removedCacheKeys.addAll(libraryContext!.dispose());
|
||||
releaseAndClearRemovedIds();
|
||||
}
|
||||
|
||||
/// Looks for references to the given Element. All the files currently
|
||||
|
@ -846,10 +855,12 @@ class LibraryContext {
|
|||
);
|
||||
}
|
||||
|
||||
/// Clears all the loaded libraries. Returns the cache ids for the removed
|
||||
/// artifacts.
|
||||
Set<String> collectSharedDataKeys() {
|
||||
var keySet = <String>{};
|
||||
/// Notifies this object that it is about to be discarded.
|
||||
///
|
||||
/// Returns the keys of the artifacts that are no longer used.
|
||||
Set<String> dispose() {
|
||||
final keySet = <String>{};
|
||||
final uriSet = <Uri>{};
|
||||
|
||||
void addIfNotNull(String? key) {
|
||||
if (key != null) {
|
||||
|
@ -859,8 +870,12 @@ class LibraryContext {
|
|||
|
||||
for (var cycle in loadedBundles) {
|
||||
addIfNotNull(cycle.resolutionKey);
|
||||
uriSet.addAll(cycle.libraries.map((e) => e.uri));
|
||||
}
|
||||
|
||||
elementFactory.removeLibraries(uriSet);
|
||||
loadedBundles.clear();
|
||||
|
||||
return keySet;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import 'package:analyzer/src/dart/micro/cider_byte_store.dart';
|
|||
import 'package:analyzer/src/dart/micro/library_graph.dart';
|
||||
import 'package:analyzer/src/dart/micro/resolve_file.dart';
|
||||
import 'package:analyzer/src/dart/sdk/sdk.dart';
|
||||
import 'package:analyzer/src/summary2/linked_element_factory.dart';
|
||||
import 'package:analyzer/src/test_utilities/find_element.dart';
|
||||
import 'package:analyzer/src/test_utilities/find_node.dart';
|
||||
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
|
||||
|
@ -67,8 +66,8 @@ class FileResolutionTest with ResourceProviderMixin, ResolutionTest {
|
|||
|
||||
void assertStateString(String expected) {
|
||||
final buffer = StringBuffer();
|
||||
ResolverStatePrinter(resourceProvider, buffer, _keyShorter).write(byteStore,
|
||||
fileResolver.fsState!, libraryContext.elementFactory, testData);
|
||||
ResolverStatePrinter(resourceProvider, buffer, _keyShorter)
|
||||
.write(byteStore, fileResolver.fsState!, libraryContext, testData);
|
||||
final actual = buffer.toString();
|
||||
|
||||
if (actual != expected) {
|
||||
|
@ -170,7 +169,7 @@ class ResolverStatePrinter {
|
|||
ResolverStatePrinter(this._resourceProvider, this._sink, this._keyShorter);
|
||||
|
||||
void write(MemoryCiderByteStore byteStore, FileSystemState fileSystemState,
|
||||
LinkedElementFactory elementFactory, FileResolverTestView testData) {
|
||||
LibraryContext libraryContext, FileResolverTestView testData) {
|
||||
_writelnWithIndent('files');
|
||||
_withIndent(() {
|
||||
final fileMap = testData.fileSystemTestData.files;
|
||||
|
@ -205,9 +204,28 @@ class ResolverStatePrinter {
|
|||
.toList();
|
||||
entries.sortBy((e) => e.key);
|
||||
|
||||
final loadedBundlesMap = Map.fromEntries(
|
||||
libraryContext.loadedBundles.map((cycle) {
|
||||
final key = cycle.libraries
|
||||
.map((fileState) => fileState.resource)
|
||||
.map(_posixPath)
|
||||
.join(' ');
|
||||
return MapEntry(key, cycle);
|
||||
}),
|
||||
);
|
||||
|
||||
for (final entry in entries) {
|
||||
_writelnWithIndent(entry.key);
|
||||
_withIndent(() {
|
||||
final current = loadedBundlesMap[entry.key];
|
||||
if (current != null) {
|
||||
_writelnWithIndent('current');
|
||||
_withIndent(() {
|
||||
final short = _keyShorter.shortKey(current.resolutionKey!);
|
||||
_writelnWithIndent('key: $short');
|
||||
});
|
||||
}
|
||||
|
||||
final shortGets = _keyShorter.shortKeys(entry.value.getKeys);
|
||||
final shortPuts = _keyShorter.shortKeys(entry.value.putKeys);
|
||||
_writelnWithIndent('get: $shortGets');
|
||||
|
@ -218,6 +236,7 @@ class ResolverStatePrinter {
|
|||
|
||||
_writelnWithIndent('elementFactory');
|
||||
_withIndent(() {
|
||||
final elementFactory = libraryContext.elementFactory;
|
||||
_writeUriList(
|
||||
'hasElement',
|
||||
elementFactory.uriListWithLibraryElements,
|
||||
|
|
|
@ -7,7 +7,6 @@ import 'package:analyzer/file_system/file_system.dart';
|
|||
import 'package:analyzer/source/line_info.dart';
|
||||
import 'package:analyzer/src/dart/ast/utilities.dart';
|
||||
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
|
||||
import 'package:analyzer/src/dart/micro/cider_byte_store.dart';
|
||||
import 'package:analyzer/src/dart/micro/resolve_file.dart';
|
||||
import 'package:analyzer/src/dart/micro/utils.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
|
@ -87,15 +86,23 @@ files
|
|||
unlinkedPut: [k07]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k08
|
||||
get: []
|
||||
put: [k08]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
current
|
||||
key: k09
|
||||
get: []
|
||||
put: [k09]
|
||||
/workspace/dart/test/lib/b.dart
|
||||
current
|
||||
key: k10
|
||||
get: []
|
||||
put: [k10]
|
||||
/workspace/dart/test/lib/c.dart
|
||||
current
|
||||
key: k11
|
||||
get: []
|
||||
put: [k11]
|
||||
elementFactory
|
||||
|
@ -163,12 +170,16 @@ files
|
|||
unlinkedPut: [k07]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k08
|
||||
get: []
|
||||
put: [k08]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
get: []
|
||||
put: [k09]
|
||||
/workspace/dart/test/lib/b.dart
|
||||
current
|
||||
key: k10
|
||||
get: []
|
||||
put: [k10]
|
||||
/workspace/dart/test/lib/c.dart
|
||||
|
@ -231,15 +242,23 @@ files
|
|||
unlinkedPut: [k07, k07]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k08
|
||||
get: []
|
||||
put: [k08]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
current
|
||||
key: k09
|
||||
get: []
|
||||
put: [k09, k09]
|
||||
/workspace/dart/test/lib/b.dart
|
||||
current
|
||||
key: k10
|
||||
get: []
|
||||
put: [k10]
|
||||
/workspace/dart/test/lib/c.dart
|
||||
current
|
||||
key: k11
|
||||
get: []
|
||||
put: [k11, k11]
|
||||
elementFactory
|
||||
|
@ -408,9 +427,13 @@ files
|
|||
unlinkedPut: [k06]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k07
|
||||
get: []
|
||||
put: [k07]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
current
|
||||
key: k08
|
||||
get: []
|
||||
put: [k08]
|
||||
elementFactory
|
||||
|
@ -462,6 +485,8 @@ files
|
|||
unlinkedPut: [k06]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k07
|
||||
get: []
|
||||
put: [k07]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
|
@ -518,9 +543,13 @@ files
|
|||
unlinkedPut: [k06, k06]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k07
|
||||
get: []
|
||||
put: [k07]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
current
|
||||
key: k08
|
||||
get: []
|
||||
put: [k08, k08]
|
||||
elementFactory
|
||||
|
@ -597,12 +626,18 @@ files
|
|||
unlinkedPut: [k07]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k08
|
||||
get: []
|
||||
put: [k08]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
current
|
||||
key: k09
|
||||
get: []
|
||||
put: [k09]
|
||||
/workspace/dart/test/lib/c.dart
|
||||
current
|
||||
key: k10
|
||||
get: []
|
||||
put: [k10]
|
||||
elementFactory
|
||||
|
@ -658,6 +693,8 @@ files
|
|||
unlinkedPut: [k07]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k08
|
||||
get: []
|
||||
put: [k08]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
|
@ -722,12 +759,18 @@ files
|
|||
unlinkedPut: [k07, k07]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k08
|
||||
get: []
|
||||
put: [k08]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
current
|
||||
key: k09
|
||||
get: []
|
||||
put: [k09, k09]
|
||||
/workspace/dart/test/lib/c.dart
|
||||
current
|
||||
key: k10
|
||||
get: []
|
||||
put: [k10, k10]
|
||||
elementFactory
|
||||
|
@ -853,17 +896,102 @@ var b = 1 + 2;
|
|||
assertType(findElement.topVar('b').type, 'int');
|
||||
}
|
||||
|
||||
test_collectSharedDataIdentifiers() async {
|
||||
var aPath = convertPath('/workspace/third_party/dart/aaa/lib/a.dart');
|
||||
|
||||
newFile(aPath, r'''
|
||||
test_dispose() async {
|
||||
final a = newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {}
|
||||
''');
|
||||
|
||||
await resolveFile(aPath);
|
||||
fileResolver.collectSharedDataIdentifiers();
|
||||
expect(fileResolver.removedCacheKeys.length,
|
||||
(fileResolver.byteStore as MemoryCiderByteStore).testView!.length);
|
||||
// After resolution the byte store contains unlinked data for files,
|
||||
// and linked data for loaded bundles.
|
||||
await resolveFile(a.path);
|
||||
assertStateString(r'''
|
||||
files
|
||||
/sdk/lib/_internal/internal.dart
|
||||
current
|
||||
unlinkedKey: k00
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k00]
|
||||
/sdk/lib/async/async.dart
|
||||
current
|
||||
unlinkedKey: k01
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k01]
|
||||
/sdk/lib/async/stream.dart
|
||||
current
|
||||
unlinkedKey: k02
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k02]
|
||||
/sdk/lib/core/core.dart
|
||||
current
|
||||
unlinkedKey: k03
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k03]
|
||||
/sdk/lib/math/math.dart
|
||||
current
|
||||
unlinkedKey: k04
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k04]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
current
|
||||
unlinkedKey: k05
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k05]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
current
|
||||
key: k06
|
||||
get: []
|
||||
put: [k06]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
current
|
||||
key: k07
|
||||
get: []
|
||||
put: [k07]
|
||||
elementFactory
|
||||
hasElement
|
||||
dart:_internal
|
||||
dart:async
|
||||
dart:core
|
||||
dart:math
|
||||
package:dart.test/a.dart
|
||||
byteStore
|
||||
1: [k00, k01, k02, k03, k04, k05, k06, k07]
|
||||
''');
|
||||
|
||||
fileResolver.dispose();
|
||||
|
||||
// After dispose() we don't have any loaded libraries or files.
|
||||
// The byte store is empty - no unlinked or linked data.
|
||||
assertStateString(r'''
|
||||
files
|
||||
/sdk/lib/_internal/internal.dart
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k00]
|
||||
/sdk/lib/async/async.dart
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k01]
|
||||
/sdk/lib/async/stream.dart
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k02]
|
||||
/sdk/lib/core/core.dart
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k03]
|
||||
/sdk/lib/math/math.dart
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k04]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
unlinkedGet: []
|
||||
unlinkedPut: [k05]
|
||||
libraryCycles
|
||||
/sdk/lib/_internal/internal.dart /sdk/lib/async/async.dart /sdk/lib/core/core.dart /sdk/lib/math/math.dart
|
||||
get: []
|
||||
put: [k06]
|
||||
/workspace/dart/test/lib/a.dart
|
||||
get: []
|
||||
put: [k07]
|
||||
elementFactory
|
||||
byteStore
|
||||
''');
|
||||
}
|
||||
|
||||
test_elements_export_dartCoreDynamic() async {
|
||||
|
|
Loading…
Reference in a new issue