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

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: address review comments 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
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/runtime_entry.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index 6f639387c126ac232945dfea4ccc80cac1915855..1c44a6e490606951d98ae2a1da0239a1e75f6fa1 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -1803,6 +1803,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 +1833,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 +1911,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 +5714,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 +12585,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()) {
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/runtime_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698