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

Unified Diff: runtime/vm/parser.cc

Issue 2941643002: Check for a passed-in type argument vector in the prolog of generic functions. (Closed)
Patch Set: Fix lookup in dart:_internal Created 3 years, 6 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/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index 6f639387c126ac232945dfea4ccc80cac1915855..014d39bf7d149750c66c48cb48949b10c0f3f913 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -310,6 +310,8 @@ void ParsedFunction::AllocateVariables() {
const intptr_t num_fixed_params = function().num_fixed_parameters();
const intptr_t num_opt_params = function().NumOptionalParameters();
const intptr_t num_params = num_fixed_params + num_opt_params;
+ const intptr_t type_args_slot = function().IsGeneric() ? 1 : 0;
+
// Compute start indices to parameters and locals, and the number of
// parameters to copy.
if (num_opt_params == 0) {
@@ -330,8 +332,8 @@ void ParsedFunction::AllocateVariables() {
// in the context(s).
bool found_captured_variables = false;
int next_free_frame_index = scope->AllocateVariables(
- first_parameter_index_, num_params, first_stack_local_index_, NULL,
- &found_captured_variables);
+ first_parameter_index_, num_params, type_args_slot,
+ first_stack_local_index_, NULL, &found_captured_variables);
// Frame indices are relative to the frame pointer and are decreasing.
ASSERT(next_free_frame_index <= first_stack_local_index_);
@@ -1803,6 +1805,17 @@ void Parser::BuildDispatcherScope(const Function& func,
// Build local scope for function and populate with the formal parameters.
OpenFunctionBlock(func);
AddFormalParamsToScope(&params, current_block_->scope);
+
+ if (desc.TypeArgsLen() > 0) {
+ ASSERT(func.IsGeneric() && !func.HasGenericParent());
+ // Insert function type arguments variable to scope.
+ LocalVariable* type_args_var = new (Z) LocalVariable(
+ TokenPosition::kNoSource, TokenPosition::kNoSource,
+ Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type());
+ current_block_->scope->AddVariable(type_args_var);
+ ASSERT(FunctionLevel() == 0);
+ parsed_function_->set_function_type_arguments(type_args_var);
+ }
}
@@ -1822,7 +1835,9 @@ SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) {
// Receiver is local 0.
LocalScope* scope = current_block_->scope;
- ArgumentListNode* func_args = new ArgumentListNode(token_pos);
+ ArgumentListNode* func_args = new ArgumentListNode(
+ token_pos, parsed_function_->function_type_arguments(),
+ desc.TypeArgsLen());
for (intptr_t i = 0; i < desc.Count(); ++i) {
func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i)));
}
@@ -1898,9 +1913,12 @@ SequenceNode* Parser::ParseInvokeFieldDispatcher(const Function& func) {
}
// Pass arguments 1..n to the closure call.
- ArgumentListNode* args = new (Z) ArgumentListNode(token_pos);
+ ArgumentListNode* args = new (Z)
+ ArgumentListNode(token_pos, parsed_function_->function_type_arguments(),
+ desc.TypeArgsLen());
const Array& names =
Array::Handle(Z, Array::New(desc.NamedCount(), Heap::kOld));
+
// Positional parameters.
intptr_t i = 1;
for (; i < desc.PositionalCount(); ++i) {
@@ -5698,7 +5716,11 @@ RawTypeArguments* Parser::ParseTypeArguments(
ReportError("right angle bracket expected");
}
if (finalization != ClassFinalizer::kIgnore) {
- return NewTypeArguments(types);
+ TypeArguments& type_args = TypeArguments::Handle(NewTypeArguments(types));
+ if (finalization == ClassFinalizer::kCanonicalize) {
+ type_args = type_args.Canonicalize();
+ }
+ return type_args.raw();
}
}
return TypeArguments::null();
@@ -12565,12 +12587,15 @@ void Parser::ResolveType(AbstractType* type) {
if (type->arguments() != TypeArguments::null()) {
const TypeArguments& arguments =
TypeArguments::Handle(Z, type->arguments());
- const intptr_t num_arguments = arguments.Length();
- AbstractType& type_argument = AbstractType::Handle(Z);
- for (intptr_t i = 0; i < num_arguments; i++) {
- type_argument = arguments.TypeAt(i);
- ResolveType(&type_argument);
- arguments.SetTypeAt(i, type_argument);
+ // Already resolved if canonical.
+ if (!arguments.IsCanonical()) {
+ const intptr_t num_arguments = arguments.Length();
+ AbstractType& type_argument = AbstractType::Handle(Z);
+ for (intptr_t i = 0; i < num_arguments; i++) {
+ type_argument = arguments.TypeAt(i);
+ ResolveType(&type_argument);
+ arguments.SetTypeAt(i, type_argument);
+ }
}
}
if (type->IsFunctionType()) {

Powered by Google App Engine
This is Rietveld 408576698