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

Side by Side Diff: runtime/vm/parser.cc

Issue 2941643002: Check for a passed-in type argument vector in the prolog of generic functions. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 deferred_prefixes_->Add(&LibraryPrefix::ZoneHandle(Z, prefix.raw())); 339 deferred_prefixes_->Add(&LibraryPrefix::ZoneHandle(Z, prefix.raw()));
340 } 340 }
341 341
342 342
343 void ParsedFunction::AllocateVariables() { 343 void ParsedFunction::AllocateVariables() {
344 ASSERT(!function().IsIrregexpFunction()); 344 ASSERT(!function().IsIrregexpFunction());
345 LocalScope* scope = node_sequence()->scope(); 345 LocalScope* scope = node_sequence()->scope();
346 const intptr_t num_fixed_params = function().num_fixed_parameters(); 346 const intptr_t num_fixed_params = function().num_fixed_parameters();
347 const intptr_t num_opt_params = function().NumOptionalParameters(); 347 const intptr_t num_opt_params = function().NumOptionalParameters();
348 const intptr_t num_params = num_fixed_params + num_opt_params; 348 const intptr_t num_params = num_fixed_params + num_opt_params;
349 const intptr_t type_args_slot = function().IsGeneric() ? 1 : 0;
350
349 // Compute start indices to parameters and locals, and the number of 351 // Compute start indices to parameters and locals, and the number of
350 // parameters to copy. 352 // parameters to copy.
351 if (num_opt_params == 0) { 353 if (num_opt_params == 0) {
352 // Parameter i will be at fp[kParamEndSlotFromFp + num_params - i] and 354 // Parameter i will be at fp[kParamEndSlotFromFp + num_params - i] and
353 // local variable j will be at fp[kFirstLocalSlotFromFp - j]. 355 // local variable j will be at fp[kFirstLocalSlotFromFp - j].
354 first_parameter_index_ = kParamEndSlotFromFp + num_params; 356 first_parameter_index_ = kParamEndSlotFromFp + num_params;
355 first_stack_local_index_ = kFirstLocalSlotFromFp; 357 first_stack_local_index_ = kFirstLocalSlotFromFp;
356 num_copied_params_ = 0; 358 num_copied_params_ = 0;
357 } else { 359 } else {
358 // Parameter i will be at fp[kFirstLocalSlotFromFp - i] and local variable 360 // Parameter i will be at fp[kFirstLocalSlotFromFp - i] and local variable
359 // j will be at fp[kFirstLocalSlotFromFp - num_params - j]. 361 // j will be at fp[kFirstLocalSlotFromFp - num_params - j].
360 first_parameter_index_ = kFirstLocalSlotFromFp; 362 first_parameter_index_ = kFirstLocalSlotFromFp;
361 first_stack_local_index_ = first_parameter_index_ - num_params; 363 first_stack_local_index_ = first_parameter_index_ - num_params;
362 num_copied_params_ = num_params; 364 num_copied_params_ = num_params;
363 } 365 }
364 366
365 // Allocate parameters and local variables, either in the local frame or 367 // Allocate parameters and local variables, either in the local frame or
366 // in the context(s). 368 // in the context(s).
367 bool found_captured_variables = false; 369 bool found_captured_variables = false;
368 int next_free_frame_index = scope->AllocateVariables( 370 int next_free_frame_index = scope->AllocateVariables(
369 first_parameter_index_, num_params, first_stack_local_index_, NULL, 371 first_parameter_index_, num_params, type_args_slot,
370 &found_captured_variables); 372 first_stack_local_index_, NULL, &found_captured_variables);
371 373
372 // Frame indices are relative to the frame pointer and are decreasing. 374 // Frame indices are relative to the frame pointer and are decreasing.
373 ASSERT(next_free_frame_index <= first_stack_local_index_); 375 ASSERT(next_free_frame_index <= first_stack_local_index_);
374 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; 376 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index;
375 } 377 }
376 378
377 379
378 struct CatchParamDesc { 380 struct CatchParamDesc {
379 CatchParamDesc() 381 CatchParamDesc()
380 : token_pos(TokenPosition::kNoSource), 382 : token_pos(TokenPosition::kNoSource),
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 load_receiver, NULL); 1799 load_receiver, NULL);
1798 1800
1799 ReturnNode* return_node = new ReturnNode(ident_pos, closure); 1801 ReturnNode* return_node = new ReturnNode(ident_pos, closure);
1800 current_block_->statements->Add(return_node); 1802 current_block_->statements->Add(return_node);
1801 return CloseBlock(); 1803 return CloseBlock();
1802 } 1804 }
1803 1805
1804 1806
1805 void Parser::BuildDispatcherScope(const Function& func, 1807 void Parser::BuildDispatcherScope(const Function& func,
1806 const ArgumentsDescriptor& desc) { 1808 const ArgumentsDescriptor& desc) {
1809 if (desc.TypeArgsLen() > 0) {
1810 // TODO(regis): Make func generic.
1811 UNIMPLEMENTED();
1812 }
1807 ParamList params; 1813 ParamList params;
1808 // Receiver first. 1814 // Receiver first.
1809 TokenPosition token_pos = func.token_pos(); 1815 TokenPosition token_pos = func.token_pos();
1810 params.AddReceiver(ReceiverType(current_class()), token_pos); 1816 params.AddReceiver(ReceiverType(current_class()), token_pos);
1811 // Remaining positional parameters. 1817 // Remaining positional parameters.
1812 intptr_t i = 1; 1818 intptr_t i = 1;
1813 for (; i < desc.PositionalCount(); ++i) { 1819 for (; i < desc.PositionalCount(); ++i) {
1814 ParamDesc p; 1820 ParamDesc p;
1815 char name[64]; 1821 char name[64];
1816 OS::SNPrint(name, 64, ":p%" Pd, i); 1822 OS::SNPrint(name, 64, ":p%" Pd, i);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 SequenceNode* Parser::ParseInvokeFieldDispatcher(const Function& func) { 1907 SequenceNode* Parser::ParseInvokeFieldDispatcher(const Function& func) {
1902 TRACE_PARSER("ParseInvokeFieldDispatcher"); 1908 TRACE_PARSER("ParseInvokeFieldDispatcher");
1903 ASSERT(func.IsInvokeFieldDispatcher()); 1909 ASSERT(func.IsInvokeFieldDispatcher());
1904 TokenPosition token_pos = func.token_pos(); 1910 TokenPosition token_pos = func.token_pos();
1905 ASSERT(func.token_pos() == TokenPosition::kMinSource); 1911 ASSERT(func.token_pos() == TokenPosition::kMinSource);
1906 ASSERT(current_class().raw() == func.Owner()); 1912 ASSERT(current_class().raw() == func.Owner());
1907 1913
1908 const Array& args_desc = Array::Handle(Z, func.saved_args_desc()); 1914 const Array& args_desc = Array::Handle(Z, func.saved_args_desc());
1909 ArgumentsDescriptor desc(args_desc); 1915 ArgumentsDescriptor desc(args_desc);
1910 ASSERT(desc.Count() > 0); 1916 ASSERT(desc.Count() > 0);
1917 if (desc.TypeArgsLen() > 0) {
1918 ASSERT(func.IsGeneric());
1919 // TODO(regis): Pass type argument vector. Not clear when this code is used.
rmacnak 2017/06/14 00:14:20 Something like this: func<X, Y, X>(w) => null; c
regis 2017/06/14 21:02:05 Thanks! This example causes an assert fault in ker
Vyacheslav Egorov (Google) 2017/06/15 14:05:44 Is this even legal? I thought the consensus was th
regis 2017/06/15 21:38:26 Yes, the first version required you to pass the ty
1920 UNIMPLEMENTED();
1921 }
1911 1922
1912 // Set up scope for this function. 1923 // Set up scope for this function.
1913 BuildDispatcherScope(func, desc); 1924 BuildDispatcherScope(func, desc);
1914 1925
1915 // Receiver is local 0. 1926 // Receiver is local 0.
1916 LocalScope* scope = current_block_->scope; 1927 LocalScope* scope = current_block_->scope;
1917 ArgumentListNode* no_args = new ArgumentListNode(token_pos); 1928 ArgumentListNode* no_args = new ArgumentListNode(token_pos);
1918 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); 1929 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0));
1919 1930
1920 const Class& closure_cls = 1931 const Class& closure_cls =
(...skipping 3806 matching lines...) Expand 10 before | Expand all | Expand 10 after
5727 } 5738 }
5728 types.Add(&AbstractType::ZoneHandle(Z, type.raw())); 5739 types.Add(&AbstractType::ZoneHandle(Z, type.raw()));
5729 } while (CurrentToken() == Token::kCOMMA); 5740 } while (CurrentToken() == Token::kCOMMA);
5730 Token::Kind token = CurrentToken(); 5741 Token::Kind token = CurrentToken();
5731 if ((token == Token::kGT) || (token == Token::kSHR)) { 5742 if ((token == Token::kGT) || (token == Token::kSHR)) {
5732 ConsumeRightAngleBracket(); 5743 ConsumeRightAngleBracket();
5733 } else { 5744 } else {
5734 ReportError("right angle bracket expected"); 5745 ReportError("right angle bracket expected");
5735 } 5746 }
5736 if (finalization != ClassFinalizer::kIgnore) { 5747 if (finalization != ClassFinalizer::kIgnore) {
5737 return NewTypeArguments(types); 5748 TypeArguments& type_args = TypeArguments::Handle(NewTypeArguments(types));
5749 if (finalization == ClassFinalizer::kCanonicalize) {
5750 type_args = type_args.Canonicalize();
5751 }
5752 return type_args.raw();
5738 } 5753 }
5739 } 5754 }
5740 return TypeArguments::null(); 5755 return TypeArguments::null();
5741 } 5756 }
5742 5757
5743 5758
5744 // Parse interface list and add to class cls. 5759 // Parse interface list and add to class cls.
5745 void Parser::ParseInterfaceList(const Class& cls) { 5760 void Parser::ParseInterfaceList(const Class& cls) {
5746 TRACE_PARSER("ParseInterfaceList"); 5761 TRACE_PARSER("ParseInterfaceList");
5747 ASSERT(CurrentToken() == Token::kIMPLEMENTS); 5762 ASSERT(CurrentToken() == Token::kIMPLEMENTS);
(...skipping 6846 matching lines...) Expand 10 before | Expand all | Expand 10 after
12594 } 12609 }
12595 *type = type_parameter.raw(); 12610 *type = type_parameter.raw();
12596 return; 12611 return;
12597 } 12612 }
12598 } 12613 }
12599 } 12614 }
12600 // Resolve type arguments, if any. 12615 // Resolve type arguments, if any.
12601 if (type->arguments() != TypeArguments::null()) { 12616 if (type->arguments() != TypeArguments::null()) {
12602 const TypeArguments& arguments = 12617 const TypeArguments& arguments =
12603 TypeArguments::Handle(Z, type->arguments()); 12618 TypeArguments::Handle(Z, type->arguments());
12604 const intptr_t num_arguments = arguments.Length(); 12619 // Already resolved if canonical.
12605 AbstractType& type_argument = AbstractType::Handle(Z); 12620 if (!arguments.IsCanonical()) {
12606 for (intptr_t i = 0; i < num_arguments; i++) { 12621 const intptr_t num_arguments = arguments.Length();
12607 type_argument = arguments.TypeAt(i); 12622 AbstractType& type_argument = AbstractType::Handle(Z);
12608 ResolveType(&type_argument); 12623 for (intptr_t i = 0; i < num_arguments; i++) {
12609 arguments.SetTypeAt(i, type_argument); 12624 type_argument = arguments.TypeAt(i);
12625 ResolveType(&type_argument);
12626 arguments.SetTypeAt(i, type_argument);
12627 }
12610 } 12628 }
12611 } 12629 }
12612 if (type->IsFunctionType()) { 12630 if (type->IsFunctionType()) {
12613 const Function& signature = 12631 const Function& signature =
12614 Function::Handle(Z, Type::Cast(*type).signature()); 12632 Function::Handle(Z, Type::Cast(*type).signature());
12615 Type& signature_type = Type::Handle(Z, signature.SignatureType()); 12633 Type& signature_type = Type::Handle(Z, signature.SignatureType());
12616 if (signature_type.raw() != type->raw()) { 12634 if (signature_type.raw() != type->raw()) {
12617 ResolveType(&signature_type); 12635 ResolveType(&signature_type);
12618 } else { 12636 } else {
12619 ResolveSignature(signature); 12637 ResolveSignature(signature);
(...skipping 2729 matching lines...) Expand 10 before | Expand all | Expand 10 after
15349 TokenPosition* start, 15367 TokenPosition* start,
15350 TokenPosition* end) { 15368 TokenPosition* end) {
15351 UNREACHABLE(); 15369 UNREACHABLE();
15352 return false; 15370 return false;
15353 } 15371 }
15354 15372
15355 15373
15356 } // namespace dart 15374 } // namespace dart
15357 15375
15358 #endif // DART_PRECOMPILED_RUNTIME 15376 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698