Skip to content

Commit 620ab34

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm] Implement reading of parameter annotations from kernel
Fixes #33207 Change-Id: I201d262bb913c342b705a607b0d88ba345e759e0 Reviewed-on: https://dart-review.googlesource.com/63644 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 7d7e39a commit 620ab34

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed

runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8892,6 +8892,7 @@ RawObject* StreamingFlowGraphBuilder::BuildParameterDescriptor(
88928892
}
88938893

88948894
// Read ith variable declaration.
8895+
intptr_t param_kernel_offset = reader_.offset();
88958896
VariableDeclarationHelper helper(this);
88968897
helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer);
88978898
param_descriptor.SetAt(entry_start + Parser::kParameterIsFinalOffset,
@@ -8910,13 +8911,37 @@ RawObject* StreamingFlowGraphBuilder::BuildParameterDescriptor(
89108911
Object::null_instance());
89118912
}
89128913

8913-
param_descriptor.SetAt(entry_start + Parser::kParameterMetadataOffset,
8914-
/* Issue(28434): Missing parameter metadata. */
8915-
Object::null_instance());
8914+
if (FLAG_enable_mirrors && (helper.annotation_count_ > 0)) {
8915+
AlternativeReadingScope alt(&reader_, param_kernel_offset);
8916+
VariableDeclarationHelper helper(this);
8917+
helper.ReadUntilExcluding(VariableDeclarationHelper::kAnnotations);
8918+
Object& metadata = Object::ZoneHandle(Z, BuildAnnotations());
8919+
param_descriptor.SetAt(entry_start + Parser::kParameterMetadataOffset,
8920+
metadata);
8921+
} else {
8922+
param_descriptor.SetAt(entry_start + Parser::kParameterMetadataOffset,
8923+
Object::null_instance());
8924+
}
89168925
}
89178926
return param_descriptor.raw();
89188927
}
89198928

8929+
RawObject* StreamingFlowGraphBuilder::BuildAnnotations() {
8930+
ASSERT(active_class() != NULL);
8931+
intptr_t list_length = ReadListLength(); // read list length.
8932+
const Array& metadata_values =
8933+
Array::Handle(Z, Array::New(list_length, H.allocation_space()));
8934+
Instance& value = Instance::Handle(Z);
8935+
for (intptr_t i = 0; i < list_length; ++i) {
8936+
// this will (potentially) read the expression, but reset the position.
8937+
value = constant_evaluator_.EvaluateExpression(ReaderOffset());
8938+
SkipExpression(); // read (actual) initializer.
8939+
metadata_values.SetAt(i, value);
8940+
}
8941+
8942+
return metadata_values.raw();
8943+
}
8944+
89208945
RawObject* StreamingFlowGraphBuilder::EvaluateMetadata(intptr_t kernel_offset) {
89218946
SetOffset(kernel_offset);
89228947
const Tag tag = PeekTag();
@@ -8939,18 +8964,7 @@ RawObject* StreamingFlowGraphBuilder::EvaluateMetadata(intptr_t kernel_offset) {
89398964
FATAL("No support for metadata on this type of kernel node\n");
89408965
}
89418966

8942-
intptr_t list_length = ReadListLength(); // read list length.
8943-
const Array& metadata_values =
8944-
Array::Handle(Z, Array::New(list_length, H.allocation_space()));
8945-
Instance& value = Instance::Handle(Z);
8946-
for (intptr_t i = 0; i < list_length; ++i) {
8947-
// this will (potentially) read the expression, but reset the position.
8948-
value = constant_evaluator_.EvaluateExpression(ReaderOffset());
8949-
SkipExpression(); // read (actual) initializer.
8950-
metadata_values.SetAt(i, value);
8951-
}
8952-
8953-
return metadata_values.raw();
8967+
return BuildAnnotations();
89548968
}
89558969

89568970
void StreamingFlowGraphBuilder::CollectTokenPositionsFor(

runtime/vm/compiler/frontend/kernel_binary_flowgraph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class StreamingFlowGraphBuilder : public KernelReaderHelper {
414414

415415
Fragment BuildStatementAt(intptr_t kernel_offset);
416416
RawObject* BuildParameterDescriptor(intptr_t kernel_offset);
417+
RawObject* BuildAnnotations();
417418
RawObject* EvaluateMetadata(intptr_t kernel_offset);
418419
void CollectTokenPositionsFor(
419420
intptr_t script_index,

runtime/vm/compiler/frontend/kernel_to_il.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,10 +2096,14 @@ RawObject* BuildParameterDescriptor(const Function& function) {
20962096
Script& script = Script::Handle(Z, function.script());
20972097
helper.InitFromScript(script);
20982098

2099+
const Class& owner_class = Class::Handle(Z, function.Owner());
2100+
ActiveClass active_class;
2101+
ActiveClassScope active_class_scope(&active_class, &owner_class);
2102+
20992103
StreamingFlowGraphBuilder streaming_flow_graph_builder(
21002104
&helper, Script::Handle(Z, function.script()), Z,
21012105
ExternalTypedData::Handle(Z, function.KernelData()),
2102-
function.KernelDataProgramOffset(), /* active_class = */ NULL);
2106+
function.KernelDataProgramOffset(), &active_class);
21032107
return streaming_flow_graph_builder.BuildParameterDescriptor(
21042108
function.kernel_offset());
21052109
} else {

runtime/vm/compiler/frontend/kernel_translation_helper.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,10 @@ void VariableDeclarationHelper::ReadUntilExcluding(Field field) {
801801
if (++next_read_ == field) return;
802802
/* Falls through */
803803
case kAnnotations:
804-
helper_->SkipListOfExpressions(); // read annotations.
804+
annotation_count_ = helper_->ReadListLength(); // read list length.
805+
for (intptr_t i = 0; i < annotation_count_; ++i) {
806+
helper_->SkipExpression(); // read ith expression.
807+
}
805808
if (++next_read_ == field) return;
806809
/* Falls through */
807810
case kFlags:

runtime/vm/compiler/frontend/kernel_translation_helper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class VariableDeclarationHelper {
325325
};
326326

327327
explicit VariableDeclarationHelper(KernelReaderHelper* helper)
328-
: helper_(helper), next_read_(kPosition) {}
328+
: annotation_count_(0), helper_(helper), next_read_(kPosition) {}
329329

330330
void ReadUntilIncluding(Field field) {
331331
ReadUntilExcluding(static_cast<Field>(static_cast<int>(field) + 1));
@@ -348,6 +348,7 @@ class VariableDeclarationHelper {
348348
TokenPosition equals_position_;
349349
uint8_t flags_;
350350
StringIndex name_index_;
351+
intptr_t annotation_count_;
351352

352353
private:
353354
KernelReaderHelper* helper_;

tests/lib_2/lib_2_kernel.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ mirrors/mixin_members_test: CompileTimeError # Issue 31402 (Invocation arguments
161161
mirrors/native_class_test: SkipByDesign # Imports dart:html
162162
mirrors/operator_test: CompileTimeError # Issue 31402 (Invocation arguments)
163163
mirrors/other_declarations_location_test: RuntimeError # Issue 33325 (no source positions for type parameters).
164-
mirrors/parameter_annotation_mirror_test: RuntimeError
165-
mirrors/parameter_metadata_test: RuntimeError
166164
mirrors/parameter_of_mixin_app_constructor_test: RuntimeError # Issue 31402 (Invocation arguments)
167165
mirrors/private_symbol_test: RuntimeError # Issue 33326 - CFE/kernel invalid typedef substitution
168166
mirrors/private_types_test: RuntimeError # Issue 33326 - CFE/kernel invalid typedef substitution

0 commit comments

Comments
 (0)