Put informativeBytes into UnlinkedUnit.
Change-Id: I6f514d9032372cf0ec7dc00e97b79c5af021930c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216520
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 903b0f4..f0f35eb 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -121,7 +121,6 @@
LineInfo? _lineInfo;
Uint8List? _unlinkedSignature;
String? _unlinkedKey;
- String? _informativeKey;
AnalysisDriverUnlinkedUnit? _driverUnlinkedUnit;
Uint8List? _apiSignature;
@@ -335,16 +334,6 @@
return other is FileState && other.uri == uri;
}
- Uint8List getInformativeBytes({CompilationUnit? unit}) {
- var bytes = _fsState._byteStore.get(_informativeKey!);
- if (bytes == null) {
- unit ??= parse();
- bytes = writeUnitInformative(unit);
- _fsState._byteStore.put(_informativeKey!, bytes);
- }
- return bytes;
- }
-
void internal_setLibraryCycle(LibraryCycle? cycle) {
_libraryCycle = cycle;
}
@@ -394,9 +383,8 @@
signature.addBool(_exists!);
_unlinkedSignature = signature.toByteList();
var signatureHex = hex.encode(_unlinkedSignature!);
- _unlinkedKey = '$signatureHex.unlinked2';
// TODO(scheglov) Use the path as the key, and store the signature.
- _informativeKey = '$signatureHex.ast';
+ _unlinkedKey = '$signatureHex.unlinked2';
}
// Prepare the unlinked unit.
@@ -611,6 +599,7 @@
hasLibraryDirective: hasLibraryDirective,
hasPartOfDirective: hasPartOfDirective,
imports: imports,
+ informativeBytes: writeUnitInformative(unit),
lineStarts: Uint32List.fromList(unit.lineInfo!.lineStarts),
partOfName: null,
partOfUri: null,
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_context.dart b/pkg/analyzer/lib/src/dart/analysis/library_context.dart
index 7973df8..72092ad 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_context.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_context.dart
@@ -117,7 +117,7 @@
var unitsInformativeBytes = <Uri, Uint8List>{};
for (var library in cycle.libraries) {
for (var file in library.libraryFiles) {
- unitsInformativeBytes[file.uri] = file.getInformativeBytes();
+ unitsInformativeBytes[file.uri] = file.unlinked2.informativeBytes;
}
}
diff --git a/pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart b/pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart
index 2c7b78b..5ab1857 100644
--- a/pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart
@@ -153,6 +153,9 @@
/// URIs of `import` directives.
final List<UnlinkedNamespaceDirective> imports;
+ /// Encoded informative data.
+ final Uint8List informativeBytes;
+
/// Offsets of the first character of each line in the source code.
final Uint32List lineStarts;
@@ -171,6 +174,7 @@
required this.hasLibraryDirective,
required this.hasPartOfDirective,
required this.imports,
+ required this.informativeBytes,
required this.lineStarts,
required this.partOfName,
required this.partOfUri,
@@ -188,6 +192,7 @@
imports: reader.readTypedList(
() => UnlinkedNamespaceDirective.read(reader),
),
+ informativeBytes: reader.readUint8List(),
lineStarts: reader.readUInt30List(),
partOfName: reader.readOptionalStringUtf8(),
partOfUri: reader.readOptionalStringUtf8(),
@@ -205,6 +210,7 @@
sink.writeList<UnlinkedNamespaceDirective>(imports, (x) {
x.write(sink);
});
+ sink.writeUint8List(informativeBytes);
sink.writeUint30List(lineStarts);
sink.writeOptionalStringUtf8(partOfName);
sink.writeOptionalStringUtf8(partOfUri);
diff --git a/pkg/analyzer/lib/src/dart/micro/library_graph.dart b/pkg/analyzer/lib/src/dart/micro/library_graph.dart
index f600275..9e6cb1c 100644
--- a/pkg/analyzer/lib/src/dart/micro/library_graph.dart
+++ b/pkg/analyzer/lib/src/dart/micro/library_graph.dart
@@ -155,17 +155,11 @@
late Uint8List _digest;
late bool _exists;
late CiderUnlinkedUnit unlinked;
- Uint8List? informativeBytes;
LibraryCycle? _libraryCycle;
/// id of the cache entry with unlinked data.
late int unlinkedId;
- /// id of the cache entry with informative data.
- /// We use a separate entry because there is no good way to efficiently
- /// store a raw byte array.
- late int informativeId;
-
FileState._(
this._fsState,
this.path,
@@ -298,22 +292,15 @@
});
String unlinkedKey = '$path.unlinked';
- String informativeKey = '$path.informative';
// Prepare bytes of the unlinked bundle - existing or new.
// TODO(migration): should not be nullable
Uint8List? unlinkedBytes;
- Uint8List? informativeBytes;
{
var unlinkedData = _fsState._byteStore.get(unlinkedKey, _digest);
- var informativeData = _fsState._byteStore.get(informativeKey, _digest);
unlinkedBytes = unlinkedData?.bytes;
- informativeBytes = informativeData?.bytes;
- if (unlinkedBytes == null ||
- unlinkedBytes.isEmpty ||
- informativeBytes == null ||
- informativeBytes.isEmpty) {
+ if (unlinkedBytes == null || unlinkedBytes.isEmpty) {
var content = performance.run('content', (_) {
return getContent();
});
@@ -333,14 +320,6 @@
unlinkedBytes = unlinkedData!.bytes;
});
- performance.run('informative', (performance) {
- informativeBytes = writeUnitInformative(unit);
- performance.getDataInt('length').add(informativeBytes!.length);
- informativeData = _fsState._byteStore
- .putGet(informativeKey, _digest, informativeBytes!);
- informativeBytes = informativeData!.bytes;
- });
-
unlinked = CiderUnlinkedUnit.fromBytes(unlinkedBytes!);
// TODO(scheglov) We decode above only because we call it here.
@@ -349,8 +328,6 @@
});
}
unlinkedId = unlinkedData!.id;
- informativeId = informativeData!.id;
- this.informativeBytes = Uint8List.fromList(informativeBytes!);
}
// Read the unlinked bundle.
@@ -592,6 +569,7 @@
hasLibraryDirective: hasLibraryDirective,
hasPartOfDirective: hasPartOfDirective,
imports: imports,
+ informativeBytes: writeUnitInformative(unit),
lineStarts: Uint32List.fromList(unit.lineInfo!.lineStarts),
partOfName: partOfName,
partOfUri: partOfUriStr,
@@ -697,7 +675,6 @@
var result = <int>{};
for (var file in _pathToFile.values) {
result.add(file.unlinkedId);
- result.add(file.informativeId);
}
return result;
}
diff --git a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
index 93107c8..ab564f3 100644
--- a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
+++ b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
@@ -168,7 +168,6 @@
// Schedule disposing references to cached unlinked data.
for (var removedFile in removedFiles) {
removedCacheIds.add(removedFile.unlinkedId);
- removedCacheIds.add(removedFile.informativeId);
}
// Remove libraries represented by removed files.
@@ -405,7 +404,6 @@
var removedFiles = fsState!.removeUnusedFiles(files);
for (var removedFile in removedFiles) {
removedCacheIds.add(removedFile.unlinkedId);
- removedCacheIds.add(removedFile.informativeId);
}
}
@@ -825,10 +823,8 @@
var unitsInformativeBytes = <Uri, Uint8List>{};
for (var library in cycle.libraries) {
for (var file in library.libraryFiles) {
- var informativeBytes = file.informativeBytes;
- if (informativeBytes != null) {
- unitsInformativeBytes[file.uri] = informativeBytes;
- }
+ var informativeBytes = file.unlinked.unit.informativeBytes;
+ unitsInformativeBytes[file.uri] = informativeBytes;
}
}