Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(749)

Unified Diff: runtime/vm/kernel_binary_flowgraph.cc

Issue 2972343002: [kernel] Insert kernel bodies into VM heap (Closed)
Patch Set: Rebased Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/kernel_binary_flowgraph.cc
diff --git a/runtime/vm/kernel_binary_flowgraph.cc b/runtime/vm/kernel_binary_flowgraph.cc
index a07c181e16663716c9d1e3ceea4aa2bf9686c692..9a30282c170922e5ceccc75b400cff73a4f4ad87 100644
--- a/runtime/vm/kernel_binary_flowgraph.cc
+++ b/runtime/vm/kernel_binary_flowgraph.cc
@@ -25,12 +25,11 @@ static bool IsStaticInitializer(const Function& function, Zone* zone) {
}
StreamingScopeBuilder::StreamingScopeBuilder(ParsedFunction* parsed_function,
- intptr_t kernel_offset,
- const uint8_t* buffer,
- intptr_t buffer_length)
+ intptr_t relative_kernel_offset,
+ const TypedData& body)
: result_(NULL),
parsed_function_(parsed_function),
- kernel_offset_(kernel_offset),
+ relative_kernel_offset_(relative_kernel_offset),
translation_helper_(Thread::Current()),
zone_(translation_helper_.zone()),
current_function_scope_(NULL),
@@ -40,8 +39,8 @@ StreamingScopeBuilder::StreamingScopeBuilder(ParsedFunction* parsed_function,
needs_expr_temp_(false),
builder_(new StreamingFlowGraphBuilder(&translation_helper_,
zone_,
- buffer,
- buffer_length)),
+ relative_kernel_offset,
+ body)),
type_translator_(builder_, /*finalize=*/true) {
Script& script = Script::Handle(Z, parsed_function->function().script());
H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets()));
@@ -60,8 +59,7 @@ ScopeBuildingResult* StreamingScopeBuilder::BuildScopes() {
ASSERT(scope_ == NULL && depth_.loop_ == 0 && depth_.function_ == 0);
result_ = new (Z) ScopeBuildingResult();
- ParsedFunction* parsed_function = parsed_function_;
- const Function& function = parsed_function->function();
+ const Function& function = parsed_function_->function();
// Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used
// e.g. for type translation.
@@ -92,14 +90,14 @@ ScopeBuildingResult* StreamingScopeBuilder::BuildScopes() {
parsed_function_->set_function_type_arguments(type_args_var);
}
- LocalVariable* context_var = parsed_function->current_context_var();
+ LocalVariable* context_var = parsed_function_->current_context_var();
context_var->set_is_forced_stack();
scope_->AddVariable(context_var);
- parsed_function->SetNodeSequence(
+ parsed_function_->SetNodeSequence(
new SequenceNode(TokenPosition::kNoSource, scope_));
- builder_->SetOffset(kernel_offset_);
+ builder_->SetOffset(0);
FunctionNodeHelper function_node_helper(builder_);
@@ -112,7 +110,7 @@ ScopeBuildingResult* StreamingScopeBuilder::BuildScopes() {
case RawFunction::kSetterFunction:
case RawFunction::kConstructor: {
const Tag tag = builder_->PeekTag();
- intptr_t parent_offset = builder_->ReadUntilFunctionNode();
+ builder_->ReadUntilFunctionNode();
function_node_helper.ReadUntilExcluding(
FunctionNodeHelper::kPositionalParameters);
current_function_async_marker_ = function_node_helper.async_marker_;
@@ -139,24 +137,28 @@ ScopeBuildingResult* StreamingScopeBuilder::BuildScopes() {
// We visit instance field initializers because they might contain
// [Let] expressions and we need to have a mapping.
if (tag == kConstructor) {
- ASSERT(parent_offset >= 0);
- AlternativeReadingScope alt(builder_->reader_, parent_offset);
- ClassHelper class_helper(builder_);
- class_helper.ReadUntilExcluding(ClassHelper::kFields);
- intptr_t list_length =
- builder_->ReadListLength(); // read fields list length.
- for (intptr_t i = 0; i < list_length; i++) {
- intptr_t field_offset = builder_->ReaderOffset();
- FieldHelper field_helper(builder_);
- field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
- Tag initializer_tag =
- builder_->ReadTag(); // read first part of initializer.
- if (!field_helper.IsStatic() && initializer_tag == kSomething) {
- EnterScope(field_offset);
- VisitExpression(); // read initializer.
- ExitScope(field_helper.position_, field_helper.end_position_);
- } else if (initializer_tag == kSomething) {
- builder_->SkipExpression(); // read initializer.
+ Class& parent_class = Class::Handle(Z, function.Owner());
+ Array& class_fields = Array::Handle(Z, parent_class.fields());
+ dart::Field& class_field = dart::Field::Handle(Z);
+ for (intptr_t i = 0; i < class_fields.Length(); ++i) {
+ class_field ^= class_fields.At(i);
+ if (!class_field.is_static()) {
+ TypedData& kernel_body =
+ TypedData::Handle(Z, class_field.kernel_body());
+ ASSERT(!kernel_body.IsNull());
+ AlternativeReadingScope alt(builder_->reader_, &kernel_body, 0);
+ intptr_t saved_relative_kernel_offset_ = relative_kernel_offset_;
+ relative_kernel_offset_ = class_field.kernel_offset();
+ FieldHelper field_helper(builder_);
+ field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
+ Tag initializer_tag =
+ builder_->ReadTag(); // read first part of initializer.
+ if (initializer_tag == kSomething) {
+ EnterScope(class_field.kernel_offset());
+ VisitExpression(); // read initializer.
+ ExitScope(field_helper.position_, field_helper.end_position_);
+ }
+ relative_kernel_offset_ = saved_relative_kernel_offset_;
}
}
}
@@ -172,11 +174,11 @@ ScopeBuildingResult* StreamingScopeBuilder::BuildScopes() {
// read positional_parameters and named_parameters.
AddPositionalAndNamedParameters(pos);
- // We generate a syntethic body for implicit closure functions - which
+ // We generate a synthetic body for implicit closure functions - which
// will forward the call to the real function.
// -> see BuildGraphOfImplicitClosureFunction
if (!function.IsImplicitClosureFunction()) {
- builder_->SetOffset(kernel_offset_);
+ builder_->SetOffset(0);
first_body_token_position_ = TokenPosition::kNoSource;
VisitNode();
@@ -256,7 +258,7 @@ ScopeBuildingResult* StreamingScopeBuilder::BuildScopes() {
if (needs_expr_temp_) {
scope_->AddVariable(parsed_function_->EnsureExpressionTemp());
}
- parsed_function->AllocateVariables();
+ parsed_function_->AllocateVariables();
return result_;
}
@@ -290,23 +292,27 @@ void StreamingScopeBuilder::VisitConstructor() {
// constructor.
ConstructorHelper constructor_helper(builder_);
constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction);
- intptr_t parent_offset = constructor_helper.parent_class_binary_offset_;
- ASSERT(parent_offset >= 0);
{
- AlternativeReadingScope alt(builder_->reader_, parent_offset);
- ClassHelper class_helper(builder_);
- class_helper.ReadUntilExcluding(ClassHelper::kFields);
-
- intptr_t list_length =
- builder_->ReadListLength(); // read fields list length.
- for (intptr_t i = 0; i < list_length; i++) {
- FieldHelper field_helper(builder_);
- field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
- Tag initializer_tag = builder_->ReadTag();
- if (!field_helper.IsStatic() && initializer_tag == kSomething) {
- VisitExpression(); // read initializer.
- } else if (initializer_tag == kSomething) {
- builder_->SkipExpression(); // read initializer.
+ const Function& function = parsed_function_->function();
+ Class& parent_class = Class::Handle(Z, function.Owner());
+ Array& class_fields = Array::Handle(Z, parent_class.fields());
+ dart::Field& class_field = dart::Field::Handle(Z);
+ for (intptr_t i = 0; i < class_fields.Length(); ++i) {
+ class_field ^= class_fields.At(i);
+ if (!class_field.is_static()) {
+ TypedData& kernel_body =
+ TypedData::Handle(Z, class_field.kernel_body());
+ ASSERT(!kernel_body.IsNull());
+ AlternativeReadingScope alt(builder_->reader_, &kernel_body, 0);
+ intptr_t saved_relative_kernel_offset_ = relative_kernel_offset_;
+ relative_kernel_offset_ = class_field.kernel_offset();
+ FieldHelper field_helper(builder_);
+ field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
+ Tag initializer_tag = builder_->ReadTag();
+ if (initializer_tag == kSomething) {
+ VisitExpression(); // read initializer.
+ }
+ relative_kernel_offset_ = saved_relative_kernel_offset_;
}
}
}
@@ -620,7 +626,7 @@ void StreamingScopeBuilder::VisitExpression() {
intptr_t offset =
builder_->ReaderOffset() - 1; // -1 to include tag byte.
- EnterScope(offset);
+ EnterScope(relative_kernel_offset_ + offset);
VisitVariableDeclaration(); // read variable declaration.
VisitExpression(); // read expression.
@@ -690,7 +696,7 @@ void StreamingScopeBuilder::VisitStatement() {
intptr_t offset =
builder_->ReaderOffset() - 1; // -1 to include tag byte.
- EnterScope(offset);
+ EnterScope(relative_kernel_offset_ + offset);
intptr_t list_length =
builder_->ReadListLength(); // read number of statements.
@@ -749,7 +755,7 @@ void StreamingScopeBuilder::VisitStatement() {
intptr_t offset =
builder_->ReaderOffset() - 1; // -1 to include tag byte.
- EnterScope(offset);
+ EnterScope(relative_kernel_offset_ + offset);
intptr_t list_length =
builder_->ReadListLength(); // read number of variables.
@@ -793,7 +799,7 @@ void StreamingScopeBuilder::VisitStatement() {
++depth_.for_in_;
AddIteratorVariable();
++depth_.loop_;
- EnterScope(start_offset);
+ EnterScope(relative_kernel_offset_ + start_offset);
{
AlternativeReadingScope alt(builder_->reader_, offset);
@@ -869,7 +875,7 @@ void StreamingScopeBuilder::VisitStatement() {
PositionScope scope(builder_->reader_);
intptr_t offset = builder_->ReaderOffset(); // Catch has no tag.
- EnterScope(offset);
+ EnterScope(relative_kernel_offset_ + offset);
VisitDartType(); // Read the guard.
tag = builder_->ReadTag(); // read first part of exception.
@@ -998,7 +1004,8 @@ void StreamingScopeBuilder::VisitVariableDeclaration() {
variable->set_is_final();
}
scope_->AddVariable(variable);
- result_->locals.Insert(kernel_offset_no_tag, variable);
+ result_->locals.Insert(relative_kernel_offset_ + kernel_offset_no_tag,
+ variable);
}
void StreamingScopeBuilder::VisitDartType() {
@@ -1107,11 +1114,11 @@ void StreamingScopeBuilder::HandleLocalFunction(intptr_t parent_kernel_offset) {
current_function_async_marker_;
StreamingScopeBuilder::DepthState saved_depth_state = depth_;
depth_ = DepthState(depth_.function_ + 1);
- EnterScope(parent_kernel_offset);
+ EnterScope(relative_kernel_offset_ + parent_kernel_offset);
current_function_scope_ = scope_;
current_function_async_marker_ = function_node_helper.async_marker_;
if (depth_.function_ == 1) {
- FunctionScope function_scope = {offset, scope_};
+ FunctionScope function_scope = {relative_kernel_offset_ + offset, scope_};
result_->function_scopes.Add(function_scope);
}
@@ -1174,7 +1181,7 @@ void StreamingScopeBuilder::AddVariableDeclarationParameter(intptr_t pos) {
variable->set_is_forced_stack();
}
scope_->InsertParameterAt(pos, variable);
- result_->locals.Insert(kernel_offset, variable);
+ result_->locals.Insert(relative_kernel_offset_ + kernel_offset, variable);
// The default value may contain 'let' bindings for which the constant
// evaluator needs scope bindings.
@@ -1272,22 +1279,21 @@ void StreamingScopeBuilder::AddSwitchVariable() {
}
}
-void StreamingScopeBuilder::LookupVariable(intptr_t declaration_binary_offest) {
- LocalVariable* variable = result_->locals.Lookup(declaration_binary_offest);
+void StreamingScopeBuilder::LookupVariable(intptr_t declaration_binary_offset) {
+ LocalVariable* variable = result_->locals.Lookup(declaration_binary_offset);
if (variable == NULL) {
// We have not seen a declaration of the variable, so it must be the
// case that we are compiling a nested function and the variable is
// declared in an outer scope. In that case, look it up in the scope by
// name and add it to the variable map to simplify later lookup.
ASSERT(current_function_scope_->parent() != NULL);
-
- StringIndex var_name =
- builder_->GetNameFromVariableDeclaration(declaration_binary_offest);
+ StringIndex var_name = builder_->GetNameFromVariableDeclaration(
+ declaration_binary_offset, parsed_function_->function());
const dart::String& name = H.DartSymbol(var_name);
variable = current_function_scope_->parent()->LookupVariable(name, true);
ASSERT(variable != NULL);
- result_->locals.Insert(declaration_binary_offest, variable);
+ result_->locals.Insert(declaration_binary_offset, variable);
}
if (variable->owner()->function_level() < scope_->function_level()) {
@@ -1463,11 +1469,9 @@ void StreamingDartTypeTranslator::BuildInterfaceType(bool simple) {
void StreamingDartTypeTranslator::BuildFunctionType(bool simple) {
intptr_t list_length = 0;
- intptr_t first_item_offest = -1;
if (!simple) {
list_length =
builder_->ReadListLength(); // read type_parameters list length
- first_item_offest = builder_->ReaderOffset();
for (int i = 0; i < list_length; ++i) {
builder_->SkipStringReference(); // read string index (name).
builder_->SkipDartType(); // read dart type.
@@ -1481,7 +1485,7 @@ void StreamingDartTypeTranslator::BuildFunctionType(bool simple) {
// checker and the runtime unless explicitly specified otherwise.
//
// So we convert malformed return/parameter types to `dynamic`.
- TypeParameterScope scope(this, first_item_offest, list_length);
+ TypeParameterScope scope(this, list_length);
Function& signature_function = Function::ZoneHandle(
Z,
@@ -2231,7 +2235,8 @@ void StreamingConstantEvaluator::EvaluateMapLiteralInternal() {
}
void StreamingConstantEvaluator::EvaluateLet() {
- intptr_t kernel_position = builder_->ReaderOffset();
+ intptr_t kernel_position =
+ builder_->ReaderOffset() + builder_->relative_kernel_offset_;
LocalVariable* local = builder_->LookupVariable(kernel_position);
// read variable declaration.
@@ -2436,7 +2441,8 @@ bool StreamingConstantEvaluator::GetCachedConstant(intptr_t kernel_offset,
return false;
}
KernelConstantsMap constants(script_.compile_time_constants());
- *value ^= constants.GetOrNull(kernel_offset, &is_present);
+ *value ^= constants.GetOrNull(
+ kernel_offset + builder_->relative_kernel_offset_, &is_present);
// Mutator compiler thread may add constants while background compiler
// is running, and thus change the value of 'compile_time_constants';
// do not assert that 'compile_time_constants' has not changed.
@@ -2467,7 +2473,8 @@ void StreamingConstantEvaluator::CacheConstantValue(intptr_t kernel_offset,
script_.set_compile_time_constants(array);
}
KernelConstantsMap constants(script_.compile_time_constants());
- constants.InsertNewOrGetValue(kernel_offset, value);
+ constants.InsertNewOrGetValue(
+ kernel_offset + builder_->relative_kernel_offset_, value);
script_.set_compile_time_constants(constants.Release());
}
@@ -2483,7 +2490,7 @@ void StreamingFlowGraphBuilder::DiscoverEnclosingElements(
}
}
-intptr_t StreamingFlowGraphBuilder::ReadUntilFunctionNode() {
+void StreamingFlowGraphBuilder::ReadUntilFunctionNode() {
const Tag tag = PeekTag();
if (tag == kProcedure) {
ProcedureHelper procedure_helper(this);
@@ -2492,12 +2499,12 @@ intptr_t StreamingFlowGraphBuilder::ReadUntilFunctionNode() {
// Running a procedure without a function node doesn't make sense.
UNREACHABLE();
}
- return -1;
+ return;
// Now at start of FunctionNode.
} else if (tag == kConstructor) {
ConstructorHelper constructor_helper(this);
constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction);
- return constructor_helper.parent_class_binary_offset_;
+ return;
// Now at start of FunctionNode.
// Notice that we also have a list of initializers after that!
} else if (tag == kFunctionNode) {
@@ -2505,13 +2512,28 @@ intptr_t StreamingFlowGraphBuilder::ReadUntilFunctionNode() {
} else {
UNREACHABLE();
}
- return -1;
+ return;
}
StringIndex StreamingFlowGraphBuilder::GetNameFromVariableDeclaration(
- intptr_t kernel_offset) {
+ intptr_t kernel_offset,
+ const Function& function) {
+ Function& function_or_parent = Function::Handle(Z, function.raw());
+ intptr_t function_start_relative =
+ function_or_parent.kernel_offset() - kernel_offset;
+ while (function_start_relative > 0) {
+ function_or_parent = function_or_parent.parent_function();
+ function_start_relative =
+ function_or_parent.kernel_offset() - kernel_offset;
+ }
+ TypedData& kernel_body =
+ TypedData::Handle(Z, function_or_parent.kernel_body());
+ ASSERT(!kernel_body.IsNull());
+
// Temporarily go to the variable declaration, read the name.
- AlternativeReadingScope alt(reader_, kernel_offset);
+ AlternativeReadingScope alt(
+ reader_, &kernel_body,
+ kernel_offset - function_or_parent.kernel_offset());
VariableDeclarationHelper helper(this);
helper.ReadUntilIncluding(VariableDeclarationHelper::kNameIndex);
return helper.name_index_;
@@ -2701,7 +2723,7 @@ Fragment StreamingFlowGraphBuilder::BuildFieldInitializer(
}
Fragment StreamingFlowGraphBuilder::BuildInitializers(
- intptr_t constructor_class_parent_offset) {
+ const Class& parent_class) {
Fragment instructions;
// Start by getting the position of the constructors initializer.
@@ -2729,23 +2751,27 @@ Fragment StreamingFlowGraphBuilder::BuildInitializers(
}
if (!is_redirecting_constructor) {
- AlternativeReadingScope alt(reader_, constructor_class_parent_offset);
- ClassHelper class_helper(this);
- class_helper.ReadUntilExcluding(ClassHelper::kFields);
- intptr_t list_length = ReadListLength(); // read fields list length.
-
- for (intptr_t i = 0; i < list_length; ++i) {
- intptr_t field_offset = ReaderOffset();
- FieldHelper field_helper(this);
- field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
- Tag initializer_tag = ReadTag(); // read first part of initializer.
- if (!field_helper.IsStatic() && initializer_tag == kSomething) {
- EnterScope(field_offset);
- instructions += BuildFieldInitializer(
- field_helper.canonical_name_); // read initializer.
- ExitScope(field_offset);
- } else if (initializer_tag == kSomething) {
- SkipExpression(); // read initializer.
+ Array& class_fields = Array::Handle(Z, parent_class.fields());
+ dart::Field& class_field = dart::Field::Handle(Z);
+ for (intptr_t i = 0; i < class_fields.Length(); ++i) {
+ class_field ^= class_fields.At(i);
+ if (!class_field.is_static()) {
+ TypedData& kernel_body =
+ TypedData::Handle(Z, class_field.kernel_body());
+ ASSERT(!kernel_body.IsNull());
+ AlternativeReadingScope alt(reader_, &kernel_body, 0);
+ intptr_t saved_relative_kernel_offset_ = relative_kernel_offset_;
+ relative_kernel_offset_ = class_field.kernel_offset();
+ FieldHelper field_helper(this);
+ field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
+ Tag initializer_tag = ReadTag(); // read first part of initializer.
+ if (initializer_tag == kSomething) {
+ EnterScope(class_field.kernel_offset());
+ instructions += BuildFieldInitializer(
+ field_helper.canonical_name_); // read initializer.
+ ExitScope(class_field.kernel_offset());
+ }
+ relative_kernel_offset_ = saved_relative_kernel_offset_;
}
}
}
@@ -2837,7 +2863,8 @@ Fragment StreamingFlowGraphBuilder::BuildInitializers(
//
// (This is strictly speaking not what one should do in terms of the
// specification but that is how it is currently implemented.)
- LocalVariable* variable = LookupVariable(ReaderOffset());
+ LocalVariable* variable =
+ LookupVariable(ReaderOffset() + relative_kernel_offset_);
// Variable declaration
VariableDeclarationHelper helper(this);
@@ -2889,7 +2916,8 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfImplicitClosureFunction(
// Positional.
intptr_t positional_argument_count = ReadListLength();
for (intptr_t i = 0; i < positional_argument_count; ++i) {
- body += LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset.
+ body += LoadLocal(LookupVariable(
+ ReaderOffset() + relative_kernel_offset_)); // ith variable offset.
body += PushArgument();
SkipVariableDeclaration(); // read ith variable.
}
@@ -2901,11 +2929,15 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfImplicitClosureFunction(
argument_names = Array::New(named_argument_count);
for (intptr_t i = 0; i < named_argument_count; ++i) {
// ith variable offset.
- body += LoadLocal(LookupVariable(ReaderOffset()));
+ body +=
+ LoadLocal(LookupVariable(ReaderOffset() + relative_kernel_offset_));
body += PushArgument();
- StringIndex name = GetNameFromVariableDeclaration(ReaderOffset());
- argument_names.SetAt(i, H.DartSymbol(name));
- SkipVariableDeclaration(); // read ith variable.
+
+ // read ith variable.
+ VariableDeclarationHelper helper(this);
+ helper.ReadUntilExcluding(VariableDeclarationHelper::kEnd);
+
+ argument_names.SetAt(i, H.DartSymbol(helper.name_index_));
}
}
@@ -2953,7 +2985,8 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfConvertedClosureFunction(
// closures its context field contains the context vector that is used by the
// converted top-level function (target) explicitly and that should be passed
// to that function as the first parameter.
- body += LoadLocal(LookupVariable(ReaderOffset())); // 0th variable offset.
+ body += LoadLocal(LookupVariable(
+ ReaderOffset() + relative_kernel_offset_)); // 0th variable offset.
body += flow_graph_builder_->LoadField(Closure::context_offset());
body += PushArgument();
SkipVariableDeclaration(); // read 0th variable.
@@ -2961,7 +2994,8 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfConvertedClosureFunction(
// The rest of the parameters are the same for the method of the Closure class
// being invoked and the top-level function (target).
for (intptr_t i = 1; i < positional_argument_count; i++) {
- body += LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset.
+ body += LoadLocal(LookupVariable(
+ ReaderOffset() + relative_kernel_offset_)); // ith variable offset.
body += PushArgument();
SkipVariableDeclaration(); // read ith variable.
}
@@ -2972,12 +3006,16 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfConvertedClosureFunction(
if (named_argument_count > 0) {
argument_names = Array::New(named_argument_count);
for (intptr_t i = 0; i < named_argument_count; i++) {
+ // ith variable offset.
body +=
- LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset.
+ LoadLocal(LookupVariable(ReaderOffset() + relative_kernel_offset_));
body += PushArgument();
- argument_names.SetAt(
- i, H.DartSymbol(GetNameFromVariableDeclaration(ReaderOffset())));
- SkipVariableDeclaration(); // read ith variable.
+
+ // read ith variable.
+ VariableDeclarationHelper helper(this);
+ helper.ReadUntilExcluding(VariableDeclarationHelper::kEnd);
+
+ argument_names.SetAt(i, H.DartSymbol(helper.name_index_));
}
}
@@ -2995,8 +3033,7 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfConvertedClosureFunction(
flow_graph_builder_->next_block_id_ - 1);
}
-FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(
- intptr_t constructor_class_parent_offset) {
+FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(bool constructor) {
const Function& dart_function = parsed_function()->function();
TargetEntryInstr* normal_entry = flow_graph_builder_->BuildTargetEntry();
flow_graph_builder_->graph_entry_ = new (Z) GraphEntryInstr(
@@ -3045,11 +3082,11 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(
}
body += Drop(); // The context.
}
- if (constructor_class_parent_offset > 0) {
+ if (constructor) {
// TODO(27590): Currently the [VariableDeclaration]s from the
// initializers will be visible inside the entire body of the constructor.
// We should make a separate scope for them.
- body += BuildInitializers(constructor_class_parent_offset);
+ body += BuildInitializers(Class::Handle(Z, dart_function.Owner()));
}
FunctionNodeHelper function_node_helper(this);
@@ -3060,7 +3097,7 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(
AlternativeReadingScope alt(reader_);
intptr_t list_length = ReadListLength(); // read number of positionals.
if (list_length > 0) {
- first_parameter_offset = ReaderOffset();
+ first_parameter_offset = ReaderOffset() + relative_kernel_offset_;
}
}
// Current position: About to read list of positionals.
@@ -3104,8 +3141,10 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(
intptr_t list_length = ReadListLength();
for (intptr_t i = 0; i < list_length; ++i) {
// ith variable offset.
- body += LoadLocal(LookupVariable(ReaderOffset()));
- body += CheckVariableTypeInCheckedMode(ReaderOffset());
+ body +=
+ LoadLocal(LookupVariable(ReaderOffset() + relative_kernel_offset_));
+ body += CheckVariableTypeInCheckedMode(ReaderOffset() +
+ relative_kernel_offset_);
body += Drop();
SkipVariableDeclaration(); // read ith variable.
}
@@ -3114,8 +3153,10 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(
list_length = ReadListLength();
for (intptr_t i = 0; i < list_length; ++i) {
// ith variable offset.
- body += LoadLocal(LookupVariable(ReaderOffset()));
- body += CheckVariableTypeInCheckedMode(ReaderOffset());
+ body +=
+ LoadLocal(LookupVariable(ReaderOffset() + relative_kernel_offset_));
+ body += CheckVariableTypeInCheckedMode(ReaderOffset() +
+ relative_kernel_offset_);
body += Drop();
SkipVariableDeclaration(); // read ith variable.
}
@@ -3287,6 +3328,10 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(
FlowGraph* StreamingFlowGraphBuilder::BuildGraph(intptr_t kernel_offset) {
const Function& function = parsed_function()->function();
+ TypedData& kernel_body = TypedData::Handle(Z, function.kernel_body());
+ if (kernel_body.IsNull() && kernel_offset > 0) {
+ UNREACHABLE();
+ }
// Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used
// e.g. for type translation.
@@ -3321,18 +3366,11 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraph(intptr_t kernel_offset) {
} else if (function.IsConvertedClosureFunction()) {
return BuildGraphOfConvertedClosureFunction(function);
}
- return BuildGraphOfFunction();
+ return BuildGraphOfFunction(false);
}
case RawFunction::kConstructor: {
- bool is_factory = function.IsFactory();
- if (is_factory) {
- ReadUntilFunctionNode(); // read until function node.
- return BuildGraphOfFunction();
- } else {
- // Constructor: Pass offset to parent class.
- return BuildGraphOfFunction(
- ReadUntilFunctionNode()); // read until function node.
- }
+ ReadUntilFunctionNode(); // read until function node.
+ return BuildGraphOfFunction(!function.IsFactory());
}
case RawFunction::kImplicitGetter:
case RawFunction::kImplicitStaticFinalGetter:
@@ -5647,8 +5685,7 @@ Fragment StreamingFlowGraphBuilder::BuildMapLiteral(bool is_const,
}
Fragment StreamingFlowGraphBuilder::BuildFunctionExpression() {
- intptr_t offset = ReaderOffset() - 1; // -1 to include tag byte.
- return BuildFunctionNode(offset, TokenPosition::kNoSource, false, -1);
+ return BuildFunctionNode(TokenPosition::kNoSource, StringIndex());
}
Fragment StreamingFlowGraphBuilder::BuildLet(TokenPosition* position) {
@@ -5821,7 +5858,7 @@ Fragment StreamingFlowGraphBuilder::BuildBlock() {
Fragment instructions;
- instructions += EnterScope(offset);
+ instructions += EnterScope(offset + relative_kernel_offset_);
intptr_t list_length = ReadListLength(); // read number of statements.
for (intptr_t i = 0; i < list_length; ++i) {
if (instructions.is_open()) {
@@ -5830,7 +5867,7 @@ Fragment StreamingFlowGraphBuilder::BuildBlock() {
SkipStatement(); // read ith statement.
}
}
- instructions += ExitScope(offset);
+ instructions += ExitScope(offset + relative_kernel_offset_);
return instructions;
}
@@ -6003,7 +6040,7 @@ Fragment StreamingFlowGraphBuilder::BuildForStatement() {
Fragment declarations;
bool new_context = false;
- declarations += EnterScope(offset, &new_context);
+ declarations += EnterScope(offset + relative_kernel_offset_, &new_context);
intptr_t list_length = ReadListLength(); // read number of variables.
for (intptr_t i = 0; i < list_length; ++i) {
@@ -6053,7 +6090,7 @@ Fragment StreamingFlowGraphBuilder::BuildForStatement() {
Fragment loop(declarations.entry, loop_exit);
loop_depth_dec();
- loop += ExitScope(offset);
+ loop += ExitScope(offset + relative_kernel_offset_);
return loop;
}
@@ -6062,7 +6099,7 @@ Fragment StreamingFlowGraphBuilder::BuildForInStatement(bool async) {
intptr_t offset = ReaderOffset() - 1; // Include the tag.
TokenPosition position = ReadPosition(); // read position.
- intptr_t variable_kernel_position = ReaderOffset();
+ intptr_t variable_kernel_position = ReaderOffset() + relative_kernel_offset_;
SkipVariableDeclaration(); // read variable.
TokenPosition iterable_position = TokenPosition::kNoSource;
@@ -6089,7 +6126,7 @@ Fragment StreamingFlowGraphBuilder::BuildForInStatement(bool async) {
condition += BranchIfTrue(&body_entry, &loop_exit, false);
Fragment body(body_entry);
- body += EnterScope(offset);
+ body += EnterScope(offset + relative_kernel_offset_);
body += LoadLocal(iterator);
body += PushArgument();
const dart::String& current_getter = dart::String::ZoneHandle(
@@ -6099,7 +6136,7 @@ Fragment StreamingFlowGraphBuilder::BuildForInStatement(bool async) {
LookupVariable(variable_kernel_position));
body += Drop();
body += BuildStatement(); // read body.
- body += ExitScope(offset);
+ body += ExitScope(offset + relative_kernel_offset_);
if (body.is_open()) {
JoinEntryInstr* join = BuildJoinEntry();
@@ -6440,13 +6477,15 @@ Fragment StreamingFlowGraphBuilder::BuildTryCatch() {
handler_types.SetAt(i, Object::dynamic_type());
}
- Fragment catch_handler_body = EnterScope(catch_offset);
+ Fragment catch_handler_body =
+ EnterScope(catch_offset + relative_kernel_offset_);
tag = ReadTag(); // read first part of exception.
if (tag == kSomething) {
catch_handler_body += LoadLocal(CurrentException());
catch_handler_body +=
- StoreLocal(TokenPosition::kNoSource, LookupVariable(ReaderOffset()));
+ StoreLocal(TokenPosition::kNoSource,
+ LookupVariable(ReaderOffset() + relative_kernel_offset_));
catch_handler_body += Drop();
SkipVariableDeclaration(); // read exception.
}
@@ -6455,7 +6494,8 @@ Fragment StreamingFlowGraphBuilder::BuildTryCatch() {
if (tag == kSomething) {
catch_handler_body += LoadLocal(CurrentStackTrace());
catch_handler_body +=
- StoreLocal(TokenPosition::kNoSource, LookupVariable(ReaderOffset()));
+ StoreLocal(TokenPosition::kNoSource,
+ LookupVariable(ReaderOffset() + relative_kernel_offset_));
catch_handler_body += Drop();
SkipVariableDeclaration(); // read stack trace.
}
@@ -6468,7 +6508,7 @@ Fragment StreamingFlowGraphBuilder::BuildTryCatch() {
// Note: ExitScope adjusts context_depth_ so even if catch_handler_body
// is closed we still need to execute ExitScope for its side effect.
- catch_handler_body += ExitScope(catch_offset);
+ catch_handler_body += ExitScope(catch_offset + relative_kernel_offset_);
if (catch_handler_body.is_open()) {
catch_handler_body += Goto(after_try);
}
@@ -6692,7 +6732,7 @@ Fragment StreamingFlowGraphBuilder::BuildYieldStatement() {
}
Fragment StreamingFlowGraphBuilder::BuildVariableDeclaration() {
- intptr_t kernel_position_no_tag = ReaderOffset();
+ intptr_t kernel_position_no_tag = ReaderOffset() + relative_kernel_offset_;
LocalVariable* variable = LookupVariable(kernel_position_no_tag);
VariableDeclarationHelper helper(this);
@@ -6731,30 +6771,32 @@ Fragment StreamingFlowGraphBuilder::BuildVariableDeclaration() {
}
Fragment StreamingFlowGraphBuilder::BuildFunctionDeclaration() {
- intptr_t offset = ReaderOffset() - 1; // -1 to include tag byte.
TokenPosition position = ReadPosition(); // read position.
- intptr_t variable_offeset = ReaderOffset();
- SkipVariableDeclaration(); // read variable declaration.
+ intptr_t variable_offset = ReaderOffset() + relative_kernel_offset_;
+
+ // read variable declaration.
+ VariableDeclarationHelper helper(this);
+ helper.ReadUntilExcluding(VariableDeclarationHelper::kEnd);
Fragment instructions = DebugStepCheck(position);
- instructions += BuildFunctionNode(offset, position, true, variable_offeset);
- instructions += StoreLocal(position, LookupVariable(variable_offeset));
+ instructions += BuildFunctionNode(position, helper.name_index_);
+ instructions += StoreLocal(position, LookupVariable(variable_offset));
instructions += Drop();
return instructions;
}
Fragment StreamingFlowGraphBuilder::BuildFunctionNode(
- intptr_t parent_kernel_offset,
TokenPosition parent_position,
- bool declaration,
- intptr_t variable_offeset) {
- intptr_t offset = ReaderOffset();
+ StringIndex name_index) {
+ intptr_t offset = ReaderOffset() + relative_kernel_offset_;
FunctionNodeHelper function_node_helper(this);
function_node_helper.ReadUntilExcluding(
FunctionNodeHelper::kTotalParameterCount);
TokenPosition position = function_node_helper.position_;
+ bool declaration = name_index >= 0;
+
if (declaration) {
position = parent_position;
}
@@ -6778,10 +6820,10 @@ Fragment StreamingFlowGraphBuilder::BuildFunctionNode(
}
const dart::String* name;
- if (!declaration) {
- name = &Symbols::AnonymousClosure();
+ if (declaration) {
+ name = &H.DartSymbol(name_index);
} else {
- name = &H.DartSymbol(GetNameFromVariableDeclaration(variable_offeset));
+ name = &Symbols::AnonymousClosure();
}
// NOTE: This is not TokenPosition in the general sense!
function = Function::NewClosureFunction(
@@ -6821,6 +6863,10 @@ Fragment StreamingFlowGraphBuilder::BuildFunctionNode(
false, // is_method
true, // is_closure
&function_node_helper);
+ function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd);
+ TypedData& body_data = reader_->CopyDataToVMHeap(
+ Z, offset - relative_kernel_offset_, ReaderOffset());
+ function.set_kernel_body(body_data);
// Finalize function type.
Type& signature_type = Type::Handle(Z, function.SignatureType());
@@ -7046,23 +7092,29 @@ RawObject* StreamingFlowGraphBuilder::EvaluateMetadata(intptr_t kernel_offset) {
void StreamingFlowGraphBuilder::CollectTokenPositionsFor(
intptr_t script_index,
+ intptr_t initial_script_index,
GrowableArray<intptr_t>* record_token_positions_in,
GrowableArray<intptr_t>* record_yield_positions_in) {
record_token_positions_into_ = record_token_positions_in;
record_yield_positions_into_ = record_yield_positions_in;
record_for_script_id_ = script_index;
+ current_script_id_ = initial_script_index;
- // Get offset for 1st library.
- SetOffset(reader_->size() - 4);
- intptr_t library_count = reader_->ReadUInt32();
-
- SetOffset(reader_->size() - 4 - 4 * library_count);
- intptr_t offset = reader_->ReadUInt32();
-
- SetOffset(offset);
- for (intptr_t i = 0; i < library_count; ++i) {
- LibraryHelper library_helper(this);
- library_helper.ReadUntilExcluding(LibraryHelper::kEnd);
+ const Tag tag = PeekTag();
+ if (tag == kProcedure) {
+ ProcedureHelper procedure_helper(this);
+ procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd);
+ } else if (tag == kConstructor) {
+ ConstructorHelper constructor_helper(this);
+ constructor_helper.ReadUntilExcluding(ConstructorHelper::kEnd);
+ } else if (tag == kFunctionNode) {
+ FunctionNodeHelper function_node_helper(this);
+ function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd);
+ } else if (tag == kField) {
+ FieldHelper field_helper(this);
+ field_helper.ReadUntilExcluding(FieldHelper::kEnd);
+ } else {
+ UNREACHABLE();
}
record_token_positions_into_ = NULL;
@@ -7097,8 +7149,9 @@ String& StreamingFlowGraphBuilder::SourceTableUriFor(intptr_t index) {
}
}
intptr_t end_offset = ReaderOffset();
- return H.DartString(reader_->buffer() + end_offset + start, end - start,
- Heap::kOld);
+ return H.DartString(
+ reader_->CopyDataIntoZone(Z, end_offset + start, end - start),
+ end - start, Heap::kOld);
}
String& StreamingFlowGraphBuilder::GetSourceFor(intptr_t index) {
@@ -7118,8 +7171,8 @@ String& StreamingFlowGraphBuilder::GetSourceFor(intptr_t index) {
for (intptr_t i = 0; i < size; ++i) {
intptr_t length = ReadUInt();
if (index == i) {
- return H.DartString(reader_->buffer() + ReaderOffset(), length,
- Heap::kOld);
+ return H.DartString(reader_->CopyDataIntoZone(Z, ReaderOffset(), length),
+ length, Heap::kOld);
}
SkipBytes(length);
intptr_t line_count = ReadUInt();

Powered by Google App Engine
This is Rietveld 408576698