[vm] Remove complex logic in kernel loader for dealing with annotations

Instead of peeking into constant table and then delaying scanning of
constants by putting it in an array, which is walked again in some
future point, we simply read the annotation constants entirely without
requiring const evaluation. This works fine for pragma annotations the
VM is interested in - as there's no user-defined classes involved.

-> Loading kernel will no longer require constant evaluation to work.

Motivation for this is that [0] wants to make this delayed annotation
scanning logic even more complicated, so I prefer to remove it entirely.

[0] https://dart-review.googlesource.com/c/sdk/+/289027

TEST=ci

Change-Id: Ib859480107b6cf119d66035e66ec161ed11ddb32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290502
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Martin Kustermann 2023-03-22 12:25:47 +00:00 committed by Commit Queue
parent 94c165d189
commit f20e6d3fa0
12 changed files with 135 additions and 363 deletions

View file

@ -25,6 +25,79 @@ ConstantReader::ConstantReader(KernelReaderHelper* helper,
script_(helper->script()),
result_(Object::Handle(zone_)) {}
bool ConstantReader::IsPragmaInstanceConstant(
intptr_t constant_index,
intptr_t* pragma_name_constant_index,
intptr_t* pragma_options_constant_index) {
KernelReaderHelper reader(Z, &H, script_, H.constants_table(), 0);
NavigateToIndex(&reader, constant_index);
if (reader.ReadByte() == kInstanceConstant) {
NameIndex index = reader.ReadCanonicalNameReference();
if (H.IsRoot(index) ||
!H.StringEquals(H.CanonicalNameString(index), "pragma")) {
return false;
}
index = H.CanonicalNameParent(index);
if (H.IsRoot(index) ||
!H.StringEquals(H.CanonicalNameString(index), "dart:core")) {
return false;
}
const intptr_t num_type_args = reader.ReadUInt();
if (num_type_args != 0) return false;
const intptr_t num_fields = reader.ReadUInt();
if (num_fields != 2) return false;
const NameIndex field0_name = reader.ReadCanonicalNameReference();
if (H.IsRoot(field0_name) ||
!H.StringEquals(H.CanonicalNameString(field0_name), "name")) {
return false;
}
const intptr_t name_index = reader.ReadUInt();
if (pragma_name_constant_index != nullptr) {
*pragma_name_constant_index = name_index;
}
const NameIndex field1_name = reader.ReadCanonicalNameReference();
if (H.IsRoot(field1_name) ||
!H.StringEquals(H.CanonicalNameString(field1_name), "options")) {
return false;
}
const intptr_t options_index = reader.ReadUInt();
if (pragma_options_constant_index != nullptr) {
*pragma_options_constant_index = options_index;
}
return true;
}
return false;
}
bool ConstantReader::IsStringConstant(intptr_t constant_index,
const char* name) {
KernelReaderHelper reader(Z, &H, script_, H.constants_table(), 0);
NavigateToIndex(&reader, constant_index);
if (reader.ReadByte() == kStringConstant) {
const StringIndex index = reader.ReadStringReference();
return H.StringEquals(index, name);
}
return false;
}
bool ConstantReader::GetStringConstant(intptr_t constant_index,
String* out_value) {
KernelReaderHelper reader(Z, &H, script_, H.constants_table(), 0);
NavigateToIndex(&reader, constant_index);
if (reader.ReadByte() == kStringConstant) {
const StringIndex index = reader.ReadStringReference();
*out_value = H.DartSymbolPlain(index).ptr();
return true;
}
return false;
}
InstancePtr ConstantReader::ReadConstantInitializer() {
Tag tag = helper_->ReadTag(); // read tag.
switch (tag) {

View file

@ -23,6 +23,12 @@ class ConstantReader {
virtual ~ConstantReader() {}
bool IsPragmaInstanceConstant(intptr_t constant_index,
intptr_t* pragma_name_constant_index,
intptr_t* pragma_options_constant_index);
bool IsStringConstant(intptr_t constant_index, const char* name);
bool GetStringConstant(intptr_t constant_index, String* out_value);
InstancePtr ReadConstantInitializer();
InstancePtr ReadConstantExpression();
ObjectPtr ReadAnnotations();

View file

@ -785,16 +785,6 @@ FlowGraph* FlowGraphBuilder::BuildGraph() {
const Function& function = parsed_function_->function();
#ifdef DEBUG
// If we attached the native name to the function after it's creation (namely
// after reading the constant table from the kernel blob), we must have done
// so before building flow graph for the functions (since FGB depends needs
// the native name to be there).
const Script& script = Script::Handle(Z, function.script());
const KernelProgramInfo& info =
KernelProgramInfo::Handle(script.kernel_program_info());
ASSERT(info.IsNull() ||
info.potential_natives() == GrowableObjectArray::null());
// Check that all functions that are explicitly marked as recognized with the
// vm:recognized annotation are in fact recognized. The check can't be done on
// function creation, since the recognized status isn't set until later.

View file

@ -87,33 +87,6 @@ void TranslationHelper::InitFromKernelProgramInfo(
SetKernelProgramInfo(info);
}
GrowableObjectArrayPtr TranslationHelper::EnsurePotentialPragmaFunctions() {
auto& funcs =
GrowableObjectArray::Handle(Z, info_.potential_pragma_functions());
if (funcs.IsNull()) {
funcs = GrowableObjectArray::New(16, Heap::kNew);
info_.set_potential_pragma_functions(funcs);
}
return funcs.ptr();
}
void TranslationHelper::AddPotentialExtensionLibrary(const Library& library) {
if (potential_extension_libraries_ == nullptr) {
potential_extension_libraries_ =
&GrowableObjectArray::Handle(Z, GrowableObjectArray::New());
}
potential_extension_libraries_->Add(library);
}
GrowableObjectArrayPtr TranslationHelper::GetPotentialExtensionLibraries() {
if (potential_extension_libraries_ != nullptr) {
GrowableObjectArray* result = potential_extension_libraries_;
potential_extension_libraries_ = nullptr;
return result->ptr();
}
return GrowableObjectArray::null();
}
void TranslationHelper::SetStringOffsets(const TypedData& string_offsets) {
ASSERT(string_offsets_.IsNull());
string_offsets_ = string_offsets.ptr();

View file

@ -73,11 +73,6 @@ class TranslationHelper {
KernelProgramInfo& info() { return info_; }
GrowableObjectArrayPtr EnsurePotentialPragmaFunctions();
void AddPotentialExtensionLibrary(const Library& library);
GrowableObjectArrayPtr GetPotentialExtensionLibraries();
void SetKernelProgramInfo(const KernelProgramInfo& info);
const KernelProgramInfo& GetKernelProgramInfo() const { return info_; }

View file

@ -643,7 +643,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
56;
48;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 28;
static constexpr dart::compiler::target::word Library_InstanceSize = 88;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 20;
@ -1331,7 +1331,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
112;
96;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 48;
static constexpr dart::compiler::target::word Library_InstanceSize = 168;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 40;
@ -2010,7 +2010,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
56;
48;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 28;
static constexpr dart::compiler::target::word Library_InstanceSize = 88;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 20;
@ -2699,7 +2699,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
112;
96;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 48;
static constexpr dart::compiler::target::word Library_InstanceSize = 168;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 40;
@ -3386,7 +3386,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
64;
56;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 32;
static constexpr dart::compiler::target::word Library_InstanceSize = 112;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 24;
@ -4074,7 +4074,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
64;
56;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 32;
static constexpr dart::compiler::target::word Library_InstanceSize = 112;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 24;
@ -4755,7 +4755,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
56;
48;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 28;
static constexpr dart::compiler::target::word Library_InstanceSize = 88;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 20;
@ -5444,7 +5444,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
112;
96;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 48;
static constexpr dart::compiler::target::word Library_InstanceSize = 168;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 40;
@ -6117,7 +6117,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
56;
48;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 28;
static constexpr dart::compiler::target::word Library_InstanceSize = 88;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 20;
@ -6797,7 +6797,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
112;
96;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 48;
static constexpr dart::compiler::target::word Library_InstanceSize = 168;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 40;
@ -7468,7 +7468,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
56;
48;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 28;
static constexpr dart::compiler::target::word Library_InstanceSize = 88;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 20;
@ -8149,7 +8149,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
112;
96;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 48;
static constexpr dart::compiler::target::word Library_InstanceSize = 168;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 40;
@ -8828,7 +8828,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
64;
56;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 32;
static constexpr dart::compiler::target::word Library_InstanceSize = 112;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 24;
@ -9508,7 +9508,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
64;
56;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 32;
static constexpr dart::compiler::target::word Library_InstanceSize = 112;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 24;
@ -10181,7 +10181,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
56;
48;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 28;
static constexpr dart::compiler::target::word Library_InstanceSize = 88;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 20;
@ -10862,7 +10862,7 @@ static constexpr dart::compiler::target::word InstructionsTable_InstanceSize =
static constexpr dart::compiler::target::word Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
112;
96;
static constexpr dart::compiler::target::word LanguageError_InstanceSize = 48;
static constexpr dart::compiler::target::word Library_InstanceSize = 168;
static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 40;
@ -11610,7 +11610,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 56;
AOT_KernelProgramInfo_InstanceSize = 48;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
28;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 84;
@ -12371,7 +12371,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 112;
AOT_KernelProgramInfo_InstanceSize = 96;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
48;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 160;
@ -13136,7 +13136,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 112;
AOT_KernelProgramInfo_InstanceSize = 96;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
48;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 160;
@ -13898,7 +13898,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 64;
AOT_KernelProgramInfo_InstanceSize = 56;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
32;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 104;
@ -14661,7 +14661,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 64;
AOT_KernelProgramInfo_InstanceSize = 56;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
32;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 104;
@ -15419,7 +15419,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 56;
AOT_KernelProgramInfo_InstanceSize = 48;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
28;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 84;
@ -16181,7 +16181,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 112;
AOT_KernelProgramInfo_InstanceSize = 96;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
48;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 160;
@ -16930,7 +16930,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 56;
AOT_KernelProgramInfo_InstanceSize = 48;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
28;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 84;
@ -17682,7 +17682,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 112;
AOT_KernelProgramInfo_InstanceSize = 96;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
48;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 160;
@ -18438,7 +18438,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 112;
AOT_KernelProgramInfo_InstanceSize = 96;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
48;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 160;
@ -19191,7 +19191,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 64;
AOT_KernelProgramInfo_InstanceSize = 56;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
32;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 104;
@ -19945,7 +19945,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 64;
AOT_KernelProgramInfo_InstanceSize = 56;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
32;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 104;
@ -20694,7 +20694,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 4;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 56;
AOT_KernelProgramInfo_InstanceSize = 48;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
28;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 84;
@ -21447,7 +21447,7 @@ static constexpr dart::compiler::target::word
static constexpr dart::compiler::target::word AOT_Int32x4_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_Integer_InstanceSize = 8;
static constexpr dart::compiler::target::word
AOT_KernelProgramInfo_InstanceSize = 112;
AOT_KernelProgramInfo_InstanceSize = 96;
static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
48;
static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 160;

View file

@ -207,8 +207,6 @@ KernelLoader::KernelLoader(Program* program,
&active_class_,
/* finalize= */ false),
inferred_type_metadata_helper_(&helper_, &constant_reader_),
annotation_list_(GrowableObjectArray::Handle(Z)),
potential_pragma_functions_(GrowableObjectArray::Handle(Z)),
static_field_value_(Object::Handle(Z)),
pragma_class_(Class::Handle(Z)),
pragma_name_field_(Field::Handle(Z)),
@ -474,8 +472,6 @@ KernelLoader::KernelLoader(const Script& script,
&active_class_,
/* finalize= */ false),
inferred_type_metadata_helper_(&helper_, &constant_reader_),
annotation_list_(GrowableObjectArray::Handle(Z)),
potential_pragma_functions_(GrowableObjectArray::Handle(Z)),
static_field_value_(Object::Handle(Z)),
pragma_class_(Class::Handle(Z)),
pragma_name_field_(Field::Handle(Z)),
@ -488,102 +484,6 @@ KernelLoader::KernelLoader(const Script& script,
H.InitFromKernelProgramInfo(kernel_program_info_);
}
void KernelLoader::EvaluateDelayedPragmas() {
potential_pragma_functions_ =
kernel_program_info_.potential_pragma_functions();
if (potential_pragma_functions_.IsNull()) return;
Function& function = Function::Handle();
Library& library = Library::Handle();
Class& klass = Class::Handle();
for (int i = 0; i < potential_pragma_functions_.Length(); ++i) {
function ^= potential_pragma_functions_.At(i);
klass = function.Owner();
library = klass.library();
library.GetMetadata(function);
}
potential_pragma_functions_ = GrowableObjectArray::null();
kernel_program_info_.set_potential_pragma_functions(
GrowableObjectArray::Handle(Z));
}
void KernelLoader::AnnotateProcedures() {
annotation_list_ = kernel_program_info_.potential_natives();
const intptr_t length =
!annotation_list_.IsNull() ? annotation_list_.Length() : 0;
if (length == 0) return;
// Prepare lazy constant reading.
ConstantReader constant_reader(&helper_, &active_class_);
// Ensure `pragma` class is available before evaluating the annotations.
EnsurePragmaClassIsLookedUp();
Instance& constant = Instance::Handle(Z);
String& pragma_name = String::Handle(Z);
Object& pragma_options = Object::Handle(Z);
// Start scanning all candidates in [potential_natives] for the annotation
// constant. If the annotation is found, flag the [Function] as native and
// attach the native name to it.
Function& function = Function::Handle(Z);
for (intptr_t i = 0; i < length; ++i) {
function ^= annotation_list_.At(i);
helper_.SetOffset(function.KernelDataProgramOffset() +
function.kernel_offset());
if (function.IsGenerativeConstructor()) {
ConstructorHelper constructor_helper(&helper_);
constructor_helper.ReadUntilExcluding(ConstructorHelper::kAnnotations);
} else {
ProcedureHelper procedure_helper(&helper_);
procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations);
}
const intptr_t annotation_count = helper_.ReadListLength();
for (intptr_t j = 0; j < annotation_count; ++j) {
const intptr_t tag = helper_.PeekTag();
if (tag == kConstantExpression) {
helper_.ReadByte(); // Skip the tag.
helper_.ReadPosition(); // Skip fileOffset.
helper_.SkipDartType(); // Skip type.
const intptr_t constant_table_index = helper_.ReadUInt();
if (constant_reader.IsInstanceConstant(constant_table_index,
pragma_class_)) {
constant = constant_reader.ReadConstant(constant_table_index);
ASSERT(constant.clazz() == pragma_class_.ptr());
pragma_name ^= constant.GetField(pragma_name_field_);
if (pragma_name.ptr() == Symbols::vm_invisible().ptr()) {
function.set_is_visible(false);
}
// We found the annotation, let's flag the function as native and
// set the native name!
if (pragma_name.ptr() == Symbols::vm_external_name().ptr()) {
pragma_options = constant.GetField(pragma_options_field_);
if (pragma_options.IsString()) {
function.set_is_native(true);
function.set_native_name(String::Cast(pragma_options));
function.set_is_external(false);
}
}
}
} else {
helper_.SkipExpression();
}
}
}
// Clear out the list of [Function] objects which might need their native
// name to be set after reading the constant table from the kernel blob.
annotation_list_ = GrowableObjectArray::null();
kernel_program_info_.set_potential_natives(annotation_list_);
}
bool KernelLoader::IsClassName(NameIndex name,
const String& library,
const String& klass) {
@ -643,8 +543,6 @@ ObjectPtr KernelLoader::LoadProgram(bool process_pending_classes) {
}
kernel_program_info_.set_constants(array);
H.SetConstants(array); // for caching
AnnotateProcedures();
EvaluateDelayedPragmas();
NameIndex main = program_->main_method();
if (main != -1) {
@ -980,12 +878,8 @@ LibraryPtr KernelLoader::LoadLibrary(intptr_t index) {
library_helper.ReadUntilExcluding(LibraryHelper::kAnnotations);
intptr_t annotations_kernel_offset =
helper_.ReaderOffset() - correction_offset_;
intptr_t annotation_count = helper_.ReadListLength(); // read list length.
if (annotation_count > 0) {
// This must wait until we can evaluate constants.
// So put on the "pending" list.
H.AddPotentialExtensionLibrary(library);
}
const intptr_t annotation_count =
helper_.ReadListLength(); // read list length.
for (intptr_t i = 0; i < annotation_count; ++i) {
helper_.SkipExpression(); // read ith annotation.
}
@ -1150,7 +1044,6 @@ void KernelLoader::FinishTopLevelClassLoading(
intptr_t annotation_count = helper_.ReadListLength();
bool has_pragma_annotation;
ReadVMAnnotations(library, annotation_count, /*native_name=*/nullptr,
/*scan_annotations_lazy=*/nullptr,
/*is_invisible_function=*/nullptr,
&has_pragma_annotation);
field_helper.SetJustRead(FieldHelper::kAnnotations);
@ -1464,7 +1357,6 @@ void KernelLoader::LoadClass(const Library& library,
intptr_t annotation_count = helper_.ReadListLength();
bool has_pragma_annotation = false;
ReadVMAnnotations(library, annotation_count, /*native_name=*/nullptr,
/*scan_annotations_lazy=*/nullptr,
/*is_invisible_function=*/nullptr, &has_pragma_annotation);
if (has_pragma_annotation) {
out_class->set_has_pragma(true);
@ -1544,7 +1436,6 @@ void KernelLoader::FinishClassLoading(const Class& klass,
intptr_t annotation_count = helper_.ReadListLength();
bool has_pragma_annotation;
ReadVMAnnotations(library, annotation_count, /*native_name=*/nullptr,
/*scan_annotations_lazy=*/nullptr,
/*is_invisible_function=*/nullptr,
&has_pragma_annotation);
field_helper.SetJustRead(FieldHelper::kAnnotations);
@ -1669,12 +1560,10 @@ void KernelLoader::FinishClassLoading(const Class& klass,
ConstructorHelper constructor_helper(&helper_);
constructor_helper.ReadUntilExcluding(ConstructorHelper::kAnnotations);
intptr_t annotation_count = helper_.ReadListLength();
bool scan_annotations_lazy;
bool has_pragma_annotation;
bool is_invisible_function;
ReadVMAnnotations(library, annotation_count, /*native_name=*/nullptr,
&scan_annotations_lazy, &is_invisible_function,
&has_pragma_annotation);
&is_invisible_function, &has_pragma_annotation);
constructor_helper.SetJustRead(ConstructorHelper::kAnnotations);
constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction);
@ -1705,12 +1594,6 @@ void KernelLoader::FinishClassLoading(const Class& klass,
function.set_has_pragma(has_pragma_annotation);
function.set_is_visible(!is_invisible_function);
if (scan_annotations_lazy) {
// Cannot be processed right now, so put on "pending" list.
EnsureAnnotationList();
annotation_list_.Add(function);
}
FunctionNodeHelper function_node_helper(&helper_);
function_node_helper.ReadUntilExcluding(
FunctionNodeHelper::kTypeParameters);
@ -1826,9 +1709,6 @@ void KernelLoader::FinishLoading(const Class& klass) {
//
// Output parameters:
//
// `has_annotations_of_interest`: true if there may be annotations of
// interest and we need to re-try after reading the constants table.
//
// `is_invisible_function`: if `@pragma('vm:invisible)` was found.
//
// `native_name`: set if @pragma('vm:external-name)` was identified.
@ -1839,12 +1719,8 @@ void KernelLoader::FinishLoading(const Class& klass) {
void KernelLoader::ReadVMAnnotations(const Library& library,
intptr_t annotation_count,
String* native_name,
bool* has_annotations_of_interest,
bool* is_invisible_function,
bool* has_pragma_annotation) {
if (has_annotations_of_interest != nullptr) {
*has_annotations_of_interest = false;
}
if (is_invisible_function != nullptr) {
*is_invisible_function = false;
}
@ -1853,102 +1729,32 @@ void KernelLoader::ReadVMAnnotations(const Library& library,
return;
}
const Array& constant_table_array =
Array::Handle(Z, kernel_program_info_.constants());
const bool have_read_constant_table = !constant_table_array.IsNull();
Instance& constant = Instance::Handle(Z);
String& pragma_name = String::Handle(Z);
Object& pragma_options = Object::Handle(Z);
for (intptr_t i = 0; i < annotation_count; ++i) {
const intptr_t tag = helper_.PeekTag();
if (tag == kConstantExpression) {
if (!have_read_constant_table) {
// We can only read in the constant table once all classes have been
// finalized (otherwise we can't create instances of the classes!).
//
// We therefore delay the scanning for `@pragma('vm:external-name')`
// constants in the annotation list to later.
if (has_annotations_of_interest != nullptr) {
*has_annotations_of_interest = true;
helper_.ReadByte(); // Skip the tag.
helper_.ReadPosition(); // Skip fileOffset.
helper_.SkipDartType(); // Skip type.
const intptr_t index_in_constant_table = helper_.ReadUInt();
// Prepare lazy constant reading.
ConstantReader constant_reader(&helper_, &active_class_);
intptr_t name_index = -1;
intptr_t options_index = -1;
if (constant_reader.IsPragmaInstanceConstant(
index_in_constant_table, &name_index, &options_index)) {
*has_pragma_annotation = true;
if (is_invisible_function != nullptr) {
if (constant_reader.IsStringConstant(name_index, "vm:invisible")) {
*is_invisible_function = true;
}
}
ASSERT(kernel_program_info_.constants_table() !=
ExternalTypedData::null());
// For pragma annotations, we seek into the constants table and peek
// into the Kernel representation of the constant.
helper_.ReadByte(); // Skip the tag.
helper_.ReadPosition(); // Skip fileOffset.
helper_.SkipDartType(); // Skip type.
const intptr_t index_in_constant_table = helper_.ReadUInt();
AlternativeReadingScopeWithNewData scope(
&helper_.reader_,
&ExternalTypedData::Handle(Z,
kernel_program_info_.constants_table()),
0);
// Seek into the position within the constant table where we can inspect
// this constant's Kernel representation.
// Get the length of the constants (at the end of the mapping).
helper_.SetOffset(helper_.ReaderSize() - 4);
const intptr_t num_constants = helper_.ReadUInt32();
// Get the binary offset of the constant at the wanted index.
helper_.SetOffset(helper_.ReaderSize() - 4 - (num_constants * 4) +
(index_in_constant_table * 4));
const intptr_t constant_offset = helper_.ReadUInt32();
helper_.SetOffset(constant_offset);
uint8_t tag = helper_.ReadTag();
if (tag == kInstanceConstant) {
*has_pragma_annotation =
*has_pragma_annotation ||
IsClassName(helper_.ReadCanonicalNameReference(),
Symbols::DartCore(), Symbols::Pragma());
}
} else {
// Prepare lazy constant reading.
const dart::Class& toplevel_class =
Class::Handle(Z, library.toplevel_class());
ActiveClassScope active_class_scope(&active_class_, &toplevel_class);
ConstantReader constant_reader(&helper_, &active_class_);
helper_.ReadByte(); // Skip the tag.
// Obtain `dart:_internal::pragma`.
EnsurePragmaClassIsLookedUp();
if (tag == kConstantExpression) {
helper_.ReadPosition(); // Skip fileOffset.
helper_.SkipDartType(); // Skip type.
}
const intptr_t constant_table_index = helper_.ReadUInt();
// We have a candidate. Let's look if it's an instance of the
// `pragma` class.
if (constant_reader.IsInstanceConstant(constant_table_index,
pragma_class_)) {
*has_pragma_annotation = true;
if (native_name != nullptr || is_invisible_function != nullptr) {
constant = constant_reader.ReadConstant(constant_table_index);
ASSERT(constant.clazz() == pragma_class_.ptr());
pragma_name ^= constant.GetField(pragma_name_field_);
if (is_invisible_function != nullptr &&
pragma_name.ptr() == Symbols::vm_invisible().ptr()) {
*is_invisible_function = true;
}
if (native_name != nullptr &&
pragma_name.ptr() == Symbols::vm_external_name().ptr()) {
pragma_options = constant.GetField(pragma_options_field_);
if (pragma_options.IsString()) {
*native_name ^= pragma_options.ptr();
}
}
if (native_name != nullptr) {
if (constant_reader.IsStringConstant(name_index,
"vm:external-name")) {
constant_reader.GetStringConstant(options_index, native_name);
}
}
}
@ -1986,15 +1792,11 @@ void KernelLoader::LoadProcedure(const Library& library,
bool is_extension_member = procedure_helper.IsExtensionMember();
bool is_synthetic = procedure_helper.IsSynthetic();
String& native_name = String::Handle(Z);
bool scan_annotations_lazy;
bool has_pragma_annotation;
bool is_invisible_function;
const intptr_t annotation_count = helper_.ReadListLength();
ReadVMAnnotations(library, annotation_count, &native_name,
&scan_annotations_lazy, &is_invisible_function,
&has_pragma_annotation);
// If this is a potential native, we'll unset is_external in
// AnnotateProcedures instead.
&is_invisible_function, &has_pragma_annotation);
is_external = is_external && native_name.IsNull();
procedure_helper.SetJustRead(ProcedureHelper::kAnnotations);
const Object& script_class =
@ -2067,11 +1869,6 @@ void KernelLoader::LoadProcedure(const Library& library,
if (!native_name.IsNull()) {
function.set_native_name(native_name);
}
if (scan_annotations_lazy) {
// Cannot be processed right now, so put on "pending" list.
EnsureAnnotationList();
annotation_list_.Add(function);
}
function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kTypeParameters);
T.SetupFunctionParameters(owner, function, is_method,
@ -2086,17 +1883,6 @@ void KernelLoader::LoadProcedure(const Library& library,
if (annotation_count > 0) {
library.AddMetadata(function, procedure_offset);
}
if (has_pragma_annotation) {
if (kernel_program_info_.constants() == Array::null()) {
// Any potential pragma function before point at which
// constant table could be loaded goes to "pending".
EnsurePotentialPragmaFunctions();
potential_pragma_functions_.Add(function);
} else {
library.GetMetadata(function);
}
}
}
const Object& KernelLoader::ClassForScriptAt(const Class& klass,

View file

@ -224,13 +224,9 @@ class KernelLoader : public ValueObject {
bool IsClassName(NameIndex name, const String& library, const String& klass);
void AnnotateProcedures();
void EvaluateDelayedPragmas();
void ReadVMAnnotations(const Library& library,
intptr_t annotation_count,
String* native_name,
bool* has_annotations_of_interest,
bool* is_invisible_function,
bool* has_pragma_annotation);
@ -348,21 +344,6 @@ class KernelLoader : public ValueObject {
ASSERT(pragma_class_.is_declaration_loaded());
}
void EnsureAnnotationList() {
annotation_list_ = kernel_program_info_.potential_natives();
if (annotation_list_.IsNull()) {
// To avoid too many grows in this array, we'll set it's initial size to
// something close to the actual number of potential native functions.
annotation_list_ = GrowableObjectArray::New(100, Heap::kNew);
kernel_program_info_.set_potential_natives(annotation_list_);
}
}
void EnsurePotentialPragmaFunctions() {
potential_pragma_functions_ =
translation_helper_.EnsurePotentialPragmaFunctions();
}
Program* program_;
Thread* thread_;
@ -388,8 +369,6 @@ class KernelLoader : public ValueObject {
TypeTranslator type_translator_;
InferredTypeMetadataHelper inferred_type_metadata_helper_;
GrowableObjectArray& annotation_list_;
GrowableObjectArray& potential_pragma_functions_;
Object& static_field_value_;
Class& pragma_class_;

View file

@ -14933,16 +14933,6 @@ void KernelProgramInfo::set_constants_table(
untag()->set_constants_table(value.ptr());
}
void KernelProgramInfo::set_potential_natives(
const GrowableObjectArray& candidates) const {
untag()->set_potential_natives(candidates.ptr());
}
void KernelProgramInfo::set_potential_pragma_functions(
const GrowableObjectArray& candidates) const {
untag()->set_potential_pragma_functions(candidates.ptr());
}
void KernelProgramInfo::set_libraries_cache(const Array& cache) const {
untag()->set_libraries_cache(cache.ptr());
}

View file

@ -5260,22 +5260,6 @@ class KernelProgramInfo : public Object {
ArrayPtr constants() const { return untag()->constants(); }
void set_constants(const Array& constants) const;
// If we load a kernel blob with evaluated constants, then we delay setting
// the native names of [Function] objects until we've read the constant table
// (since native names are encoded as constants).
//
// This array will hold the functions which might need their native name set.
GrowableObjectArrayPtr potential_natives() const {
return untag()->potential_natives();
}
void set_potential_natives(const GrowableObjectArray& candidates) const;
GrowableObjectArrayPtr potential_pragma_functions() const {
return untag()->potential_pragma_functions();
}
void set_potential_pragma_functions(
const GrowableObjectArray& candidates) const;
ScriptPtr ScriptAt(intptr_t index) const;
ArrayPtr libraries_cache() const { return untag()->libraries_cache(); }

View file

@ -1694,8 +1694,6 @@ class UntaggedKernelProgramInfo : public UntaggedObject {
COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, metadata_mappings)
COMPRESSED_POINTER_FIELD(ArrayPtr, scripts)
COMPRESSED_POINTER_FIELD(ArrayPtr, constants)
COMPRESSED_POINTER_FIELD(GrowableObjectArrayPtr, potential_natives)
COMPRESSED_POINTER_FIELD(GrowableObjectArrayPtr, potential_pragma_functions)
COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, constants_table)
COMPRESSED_POINTER_FIELD(ArrayPtr, libraries_cache)
COMPRESSED_POINTER_FIELD(ArrayPtr, classes_cache)

View file

@ -80,8 +80,6 @@ namespace dart {
F(KernelProgramInfo, metadata_mappings_) \
F(KernelProgramInfo, scripts_) \
F(KernelProgramInfo, constants_) \
F(KernelProgramInfo, potential_natives_) \
F(KernelProgramInfo, potential_pragma_functions_) \
F(KernelProgramInfo, constants_table_) \
F(KernelProgramInfo, libraries_cache_) \
F(KernelProgramInfo, classes_cache_) \