mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[CFE] Serialize language version
Change-Id: I6ea448df722a7e1e51c31f06d42bfbe743855a45 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/111725 Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
This commit is contained in:
parent
4969bc6d23
commit
fd7baa4fd9
|
@ -139,7 +139,7 @@ type CanonicalName {
|
|||
|
||||
type ComponentFile {
|
||||
UInt32 magic = 0x90ABCDEF;
|
||||
UInt32 formatVersion = 26;
|
||||
UInt32 formatVersion = 27;
|
||||
List<String> problemsAsJson; // Described in problems.md.
|
||||
Library[] libraries;
|
||||
UriSource sourceMap;
|
||||
|
|
|
@ -820,6 +820,15 @@ class BinaryBuilder {
|
|||
int flags = readByte();
|
||||
bool isExternal = (flags & Library.ExternalFlag) != 0;
|
||||
_isReadingLibraryImplementation = !isExternal;
|
||||
|
||||
// TODO(jensj): Eventually, language version should always be set.
|
||||
int languageVersionMajor = readUInt();
|
||||
int languageVersionMinor = readUInt();
|
||||
if (languageVersionMajor == 0 || languageVersionMinor == 0) {
|
||||
languageVersionMajor = null;
|
||||
languageVersionMinor = null;
|
||||
}
|
||||
|
||||
var canonicalName = readCanonicalNameReference();
|
||||
Reference reference = canonicalName.getReference();
|
||||
Library library = reference.node;
|
||||
|
@ -842,6 +851,8 @@ class BinaryBuilder {
|
|||
|
||||
if (shouldWriteData) {
|
||||
library.flags = flags;
|
||||
library.languageVersionMajor = languageVersionMajor;
|
||||
library.languageVersionMinor = languageVersionMinor;
|
||||
library.name = name;
|
||||
library.fileUri = fileUri;
|
||||
library.problemsAsJson = problemsAsJson;
|
||||
|
|
|
@ -912,6 +912,11 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
|||
insideExternalLibrary = node.isExternal;
|
||||
libraryOffsets.add(getBufferOffset());
|
||||
writeByte(node.flags);
|
||||
|
||||
// TODO(jensj): Eventually, language version should always be set.
|
||||
writeUInt30(node.languageVersionMajor ?? 0);
|
||||
writeUInt30(node.languageVersionMinor ?? 0);
|
||||
|
||||
writeNonNullCanonicalNameReference(getCanonicalNameOfLibrary(node));
|
||||
writeStringReference(node.name ?? '');
|
||||
writeUriReference(node.fileUri);
|
||||
|
|
|
@ -150,7 +150,7 @@ class Tag {
|
|||
/// Internal version of kernel binary format.
|
||||
/// Bump it when making incompatible changes in kernel binaries.
|
||||
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
|
||||
static const int BinaryFormatVersion = 25;
|
||||
static const int BinaryFormatVersion = 27;
|
||||
}
|
||||
|
||||
abstract class ConstantTag {
|
||||
|
|
|
@ -1305,11 +1305,21 @@ void LibraryHelper::ReadUntilExcluding(Field field) {
|
|||
|
||||
// Ordered with fall-through.
|
||||
switch (next_read_) {
|
||||
// Note that this (up to canonical name) needs to be kept in sync with
|
||||
// "library_canonical_name" (currently in "kernel_loader.h").
|
||||
case kFlags: {
|
||||
flags_ = helper_->ReadFlags();
|
||||
if (++next_read_ == field) return;
|
||||
FALL_THROUGH;
|
||||
}
|
||||
case kLanguageVersion: {
|
||||
if (binary_version_ >= 27) {
|
||||
helper_->ReadUInt(); // Read major language version.
|
||||
helper_->ReadUInt(); // Read minor language version.
|
||||
}
|
||||
if (++next_read_ == field) return;
|
||||
FALL_THROUGH;
|
||||
}
|
||||
case kCanonicalName:
|
||||
canonical_name_ =
|
||||
helper_->ReadCanonicalNameReference(); // read canonical_name.
|
||||
|
|
|
@ -715,6 +715,7 @@ class LibraryHelper {
|
|||
public:
|
||||
enum Field {
|
||||
kFlags,
|
||||
kLanguageVersion /* from binary version 27 */,
|
||||
kCanonicalName,
|
||||
kName,
|
||||
kSourceUriIndex,
|
||||
|
@ -739,8 +740,8 @@ class LibraryHelper {
|
|||
kSynthetic = 1 << 1,
|
||||
};
|
||||
|
||||
explicit LibraryHelper(KernelReaderHelper* helper)
|
||||
: helper_(helper), next_read_(kFlags) {}
|
||||
explicit LibraryHelper(KernelReaderHelper* helper, uint32_t binary_version)
|
||||
: helper_(helper), binary_version_(binary_version), next_read_(kFlags) {}
|
||||
|
||||
void ReadUntilIncluding(Field field) {
|
||||
ReadUntilExcluding(static_cast<Field>(static_cast<int>(field) + 1));
|
||||
|
@ -761,6 +762,7 @@ class LibraryHelper {
|
|||
|
||||
private:
|
||||
KernelReaderHelper* helper_;
|
||||
uint32_t binary_version_;
|
||||
intptr_t next_read_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LibraryHelper);
|
||||
|
|
|
@ -20,7 +20,7 @@ static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
|
|||
|
||||
// Both version numbers are inclusive.
|
||||
static const uint32_t kMinSupportedKernelFormatVersion = 18;
|
||||
static const uint32_t kMaxSupportedKernelFormatVersion = 26;
|
||||
static const uint32_t kMaxSupportedKernelFormatVersion = 27;
|
||||
|
||||
// Keep in sync with package:kernel/lib/binary/tag.dart
|
||||
#define KERNEL_TAG_LIST(V) \
|
||||
|
|
|
@ -655,7 +655,7 @@ void KernelLoader::LoadNativeExtensionLibraries() {
|
|||
} else {
|
||||
helper_.SetOffset(library.kernel_offset());
|
||||
|
||||
LibraryHelper library_helper(&helper_);
|
||||
LibraryHelper library_helper(&helper_, kernel_binary_version_);
|
||||
library_helper.ReadUntilExcluding(LibraryHelper::kAnnotations);
|
||||
|
||||
const intptr_t annotation_count = helper_.ReadListLength();
|
||||
|
@ -925,7 +925,7 @@ void KernelLoader::walk_incremental_kernel(BitVector* modified_libs,
|
|||
for (intptr_t i = 0; i < length; i++) {
|
||||
intptr_t kernel_offset = library_offset(i);
|
||||
helper_.SetOffset(kernel_offset);
|
||||
LibraryHelper library_helper(&helper_);
|
||||
LibraryHelper library_helper(&helper_, kernel_binary_version_);
|
||||
library_helper.ReadUntilIncluding(LibraryHelper::kCanonicalName);
|
||||
lib = LookupLibraryOrNull(library_helper.canonical_name_);
|
||||
if (!lib.IsNull() && !lib.is_dart_scheme()) {
|
||||
|
@ -994,7 +994,7 @@ RawLibrary* KernelLoader::LoadLibrary(intptr_t index) {
|
|||
// offset.
|
||||
helper_.SetOffset(library_kernel_offset_);
|
||||
|
||||
LibraryHelper library_helper(&helper_);
|
||||
LibraryHelper library_helper(&helper_, kernel_binary_version_);
|
||||
library_helper.ReadUntilIncluding(LibraryHelper::kCanonicalName);
|
||||
if (!FLAG_precompiled_mode && !I->should_load_vmservice()) {
|
||||
StringIndex lib_name_index =
|
||||
|
|
|
@ -288,7 +288,12 @@ class KernelLoader : public ValueObject {
|
|||
reader.set_offset(library_offset(index));
|
||||
|
||||
// Start reading library.
|
||||
// Note that this needs to be keep in sync with LibraryHelper.
|
||||
reader.ReadFlags();
|
||||
if (program_->binary_version() >= 27) {
|
||||
reader.ReadUInt(); // Read major language version.
|
||||
reader.ReadUInt(); // Read minor language version.
|
||||
}
|
||||
return reader.ReadCanonicalNameReference();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue