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

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

Issue 2835513002: Process generic function type arguments in more places (function type tests, (Closed)
Patch Set: address comments Created 3 years, 8 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/become.h" 10 #include "vm/become.h"
(...skipping 6414 matching lines...) Expand 10 before | Expand all | Expand 10 after
6425 return chars; 6425 return chars;
6426 } 6426 }
6427 6427
6428 6428
6429 bool Function::HasCompatibleParametersWith(const Function& other, 6429 bool Function::HasCompatibleParametersWith(const Function& other,
6430 Error* bound_error) const { 6430 Error* bound_error) const {
6431 ASSERT(Isolate::Current()->error_on_bad_override()); 6431 ASSERT(Isolate::Current()->error_on_bad_override());
6432 ASSERT((bound_error != NULL) && bound_error->IsNull()); 6432 ASSERT((bound_error != NULL) && bound_error->IsNull());
6433 // Check that this function's signature type is a subtype of the other 6433 // Check that this function's signature type is a subtype of the other
6434 // function's signature type. 6434 // function's signature type.
6435 // Map type parameters in the signature to dynamic before the test. 6435 // Map type parameters referred to by formal parameter types and result type
6436 // in the signature to dynamic before the test.
6437 // Note that type parameters declared by a generic signature are preserved.
6436 Function& this_fun = Function::Handle(raw()); 6438 Function& this_fun = Function::Handle(raw());
6437 if (!this_fun.HasInstantiatedSignature()) { 6439 if (!this_fun.HasInstantiatedSignature()) {
6438 // TODO(regis): Should we pass the context explicitly here (i.e. null) once
6439 // we support generic functions?
6440 this_fun = this_fun.InstantiateSignatureFrom(Object::null_type_arguments(), 6440 this_fun = this_fun.InstantiateSignatureFrom(Object::null_type_arguments(),
6441 Object::null_type_arguments(), 6441 Object::null_type_arguments(),
6442 Heap::kOld); 6442 Heap::kOld);
6443 } 6443 }
6444 Function& other_fun = Function::Handle(other.raw()); 6444 Function& other_fun = Function::Handle(other.raw());
6445 if (!other_fun.HasInstantiatedSignature()) { 6445 if (!other_fun.HasInstantiatedSignature()) {
6446 // TODO(regis): Should we pass the context explicitly here (i.e. null) once
6447 // we support generic functions?
6448 other_fun = other_fun.InstantiateSignatureFrom( 6446 other_fun = other_fun.InstantiateSignatureFrom(
6449 Object::null_type_arguments(), Object::null_type_arguments(), 6447 Object::null_type_arguments(), Object::null_type_arguments(),
6450 Heap::kOld); 6448 Heap::kOld);
6451 } 6449 }
6452 if (!this_fun.TypeTest(kIsSubtypeOf, other_fun, bound_error, Heap::kOld)) { 6450 if (!this_fun.TypeTest(kIsSubtypeOf, other_fun, bound_error, Heap::kOld)) {
6453 // For more informative error reporting, use the location of the other 6451 // For more informative error reporting, use the location of the other
6454 // function here, since the caller will use the location of this function. 6452 // function here, since the caller will use the location of this function.
6455 *bound_error = LanguageError::NewFormatted( 6453 *bound_error = LanguageError::NewFormatted(
6456 *bound_error, // A bound error if non null. 6454 *bound_error, // A bound error if non null.
6457 Script::Handle(other.script()), other.token_pos(), Report::AtLocation, 6455 Script::Handle(other.script()), other.token_pos(), Report::AtLocation,
(...skipping 19 matching lines...) Expand all
6477 RawFunction* Function::InstantiateSignatureFrom( 6475 RawFunction* Function::InstantiateSignatureFrom(
6478 const TypeArguments& instantiator_type_arguments, 6476 const TypeArguments& instantiator_type_arguments,
6479 const TypeArguments& function_type_arguments, 6477 const TypeArguments& function_type_arguments,
6480 Heap::Space space) const { 6478 Heap::Space space) const {
6481 Zone* zone = Thread::Current()->zone(); 6479 Zone* zone = Thread::Current()->zone();
6482 const Object& owner = Object::Handle(zone, RawOwner()); 6480 const Object& owner = Object::Handle(zone, RawOwner());
6483 ASSERT(!HasInstantiatedSignature()); 6481 ASSERT(!HasInstantiatedSignature());
6484 Function& sig = Function::Handle( 6482 Function& sig = Function::Handle(
6485 zone, 6483 zone,
6486 Function::NewSignatureFunction(owner, TokenPosition::kNoSource, space)); 6484 Function::NewSignatureFunction(owner, TokenPosition::kNoSource, space));
6487 // TODO(regis): If type parameter bounds are not IsInstantiated(kFunctions),
6488 // clone finalized type parameters and instantiate bounds.
6489 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); 6485 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters()));
6490 AbstractType& type = AbstractType::Handle(zone, result_type()); 6486 AbstractType& type = AbstractType::Handle(zone, result_type());
6491 if (!type.IsInstantiated()) { 6487 if (!type.IsInstantiated()) {
6492 type = 6488 type =
6493 type.InstantiateFrom(instantiator_type_arguments, 6489 type.InstantiateFrom(instantiator_type_arguments,
6494 function_type_arguments, NULL, NULL, NULL, space); 6490 function_type_arguments, NULL, NULL, NULL, space);
6495 } 6491 }
6496 sig.set_result_type(type); 6492 sig.set_result_type(type);
6497 const intptr_t num_params = NumParameters(); 6493 const intptr_t num_params = NumParameters();
6498 sig.set_num_fixed_parameters(num_fixed_parameters()); 6494 sig.set_num_fixed_parameters(num_fixed_parameters());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
6546 ASSERT(test_kind == kIsMoreSpecificThan); 6542 ASSERT(test_kind == kIsMoreSpecificThan);
6547 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error, NULL, 6543 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error, NULL,
6548 space)) { 6544 space)) {
6549 return false; 6545 return false;
6550 } 6546 }
6551 } 6547 }
6552 return true; 6548 return true;
6553 } 6549 }
6554 6550
6555 6551
6552 bool Function::HasSameTypeParametersAndBounds(const Function& other) const {
6553 Thread* thread = Thread::Current();
6554 Zone* zone = thread->zone();
6555 const intptr_t num_type_params = NumTypeParameters(thread);
6556 if (num_type_params != other.NumTypeParameters(thread)) {
6557 return false;
6558 }
6559 if (num_type_params > 0) {
6560 const TypeArguments& type_params =
6561 TypeArguments::Handle(zone, type_parameters());
6562 ASSERT(!type_params.IsNull());
6563 const TypeArguments& other_type_params =
6564 TypeArguments::Handle(zone, other.type_parameters());
6565 ASSERT(!other_type_params.IsNull());
6566 TypeParameter& type_param = TypeParameter::Handle(zone);
6567 TypeParameter& other_type_param = TypeParameter::Handle(zone);
6568 AbstractType& bound = AbstractType::Handle(zone);
6569 AbstractType& other_bound = AbstractType::Handle(zone);
6570 for (intptr_t i = 0; i < num_type_params; i++) {
6571 type_param ^= type_params.TypeAt(i);
6572 other_type_param ^= other_type_params.TypeAt(i);
6573 bound = type_param.bound();
6574 ASSERT(bound.IsFinalized());
6575 other_bound = other_type_param.bound();
6576 ASSERT(other_bound.IsFinalized());
6577 if (!bound.Equals(other_bound)) {
6578 return false;
6579 }
6580 }
6581 }
6582 return true;
6583 }
6584
6585
6556 bool Function::TypeTest(TypeTestKind test_kind, 6586 bool Function::TypeTest(TypeTestKind test_kind,
6557 const Function& other, 6587 const Function& other,
6558 Error* bound_error, 6588 Error* bound_error,
6559 Heap::Space space) const { 6589 Heap::Space space) const {
6560 const intptr_t num_fixed_params = num_fixed_parameters(); 6590 const intptr_t num_fixed_params = num_fixed_parameters();
6561 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); 6591 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters();
6562 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); 6592 const intptr_t num_opt_named_params = NumOptionalNamedParameters();
6563 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); 6593 const intptr_t other_num_fixed_params = other.num_fixed_parameters();
6564 const intptr_t other_num_opt_pos_params = 6594 const intptr_t other_num_opt_pos_params =
6565 other.NumOptionalPositionalParameters(); 6595 other.NumOptionalPositionalParameters();
6566 const intptr_t other_num_opt_named_params = 6596 const intptr_t other_num_opt_named_params =
6567 other.NumOptionalNamedParameters(); 6597 other.NumOptionalNamedParameters();
6568 // This function requires the same arguments or less and accepts the same 6598 // This function requires the same arguments or less and accepts the same
6569 // arguments or more. We can ignore implicit parameters. 6599 // arguments or more. We can ignore implicit parameters.
6570 const intptr_t num_ignored_params = NumImplicitParameters(); 6600 const intptr_t num_ignored_params = NumImplicitParameters();
6571 const intptr_t other_num_ignored_params = other.NumImplicitParameters(); 6601 const intptr_t other_num_ignored_params = other.NumImplicitParameters();
6572 if (((num_fixed_params - num_ignored_params) > 6602 if (((num_fixed_params - num_ignored_params) >
6573 (other_num_fixed_params - other_num_ignored_params)) || 6603 (other_num_fixed_params - other_num_ignored_params)) ||
6574 ((num_fixed_params - num_ignored_params + num_opt_pos_params) < 6604 ((num_fixed_params - num_ignored_params + num_opt_pos_params) <
6575 (other_num_fixed_params - other_num_ignored_params + 6605 (other_num_fixed_params - other_num_ignored_params +
6576 other_num_opt_pos_params)) || 6606 other_num_opt_pos_params)) ||
6577 (num_opt_named_params < other_num_opt_named_params)) { 6607 (num_opt_named_params < other_num_opt_named_params)) {
6578 return false; 6608 return false;
6579 } 6609 }
6580 6610 if (FLAG_reify_generic_functions) {
6581 // TODO(regis): Check the type parameters and bounds of a generic function. 6611 // Check the type parameters and bounds of generic functions.
6582 6612 if (!HasSameTypeParametersAndBounds(other)) {
6613 return false;
6614 }
6615 }
6616 Thread* thread = Thread::Current();
6617 Zone* zone = thread->zone();
6583 // Check the result type. 6618 // Check the result type.
6584 const AbstractType& other_res_type = 6619 const AbstractType& other_res_type =
6585 AbstractType::Handle(other.result_type()); 6620 AbstractType::Handle(zone, other.result_type());
6586 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { 6621 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) {
6587 const AbstractType& res_type = AbstractType::Handle(result_type()); 6622 const AbstractType& res_type = AbstractType::Handle(zone, result_type());
6588 if (res_type.IsVoidType()) { 6623 if (res_type.IsVoidType()) {
6589 return false; 6624 return false;
6590 } 6625 }
6591 if (test_kind == kIsSubtypeOf) { 6626 if (test_kind == kIsSubtypeOf) {
6592 if (!res_type.IsSubtypeOf(other_res_type, bound_error, NULL, space) && 6627 if (!res_type.IsSubtypeOf(other_res_type, bound_error, NULL, space) &&
6593 !other_res_type.IsSubtypeOf(res_type, bound_error, NULL, space)) { 6628 !other_res_type.IsSubtypeOf(res_type, bound_error, NULL, space)) {
6594 return false; 6629 return false;
6595 } 6630 }
6596 } else { 6631 } else {
6597 ASSERT(test_kind == kIsMoreSpecificThan); 6632 ASSERT(test_kind == kIsMoreSpecificThan);
(...skipping 21 matching lines...) Expand all
6619 // function type, there exists an optional named parameter of this function 6654 // function type, there exists an optional named parameter of this function
6620 // type with an identical name and with a type S that is a either a subtype 6655 // type with an identical name and with a type S that is a either a subtype
6621 // or supertype of T (if test_kind == kIsSubtypeOf) or that is more specific 6656 // or supertype of T (if test_kind == kIsSubtypeOf) or that is more specific
6622 // than T (if test_kind == kIsMoreSpecificThan). 6657 // than T (if test_kind == kIsMoreSpecificThan).
6623 // Note that SetParameterNameAt() guarantees that names are symbols, so we 6658 // Note that SetParameterNameAt() guarantees that names are symbols, so we
6624 // can compare their raw pointers. 6659 // can compare their raw pointers.
6625 const int num_params = num_fixed_params + num_opt_named_params; 6660 const int num_params = num_fixed_params + num_opt_named_params;
6626 const int other_num_params = 6661 const int other_num_params =
6627 other_num_fixed_params + other_num_opt_named_params; 6662 other_num_fixed_params + other_num_opt_named_params;
6628 bool found_param_name; 6663 bool found_param_name;
6629 String& other_param_name = String::Handle(); 6664 String& other_param_name = String::Handle(zone);
6630 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { 6665 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) {
6631 other_param_name = other.ParameterNameAt(i); 6666 other_param_name = other.ParameterNameAt(i);
6632 ASSERT(other_param_name.IsSymbol()); 6667 ASSERT(other_param_name.IsSymbol());
6633 found_param_name = false; 6668 found_param_name = false;
6634 for (intptr_t j = num_fixed_params; j < num_params; j++) { 6669 for (intptr_t j = num_fixed_params; j < num_params; j++) {
6635 ASSERT(String::Handle(ParameterNameAt(j)).IsSymbol()); 6670 ASSERT(String::Handle(zone, ParameterNameAt(j)).IsSymbol());
6636 if (ParameterNameAt(j) == other_param_name.raw()) { 6671 if (ParameterNameAt(j) == other_param_name.raw()) {
6637 found_param_name = true; 6672 found_param_name = true;
6638 if (!TestParameterType(test_kind, j, i, other, bound_error, space)) { 6673 if (!TestParameterType(test_kind, j, i, other, bound_error, space)) {
6639 return false; 6674 return false;
6640 } 6675 }
6641 break; 6676 break;
6642 } 6677 }
6643 } 6678 }
6644 if (!found_param_name) { 6679 if (!found_param_name) {
6645 return false; 6680 return false;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
6755 // Functions other than signature functions have no reason to be allocated 6790 // Functions other than signature functions have no reason to be allocated
6756 // in new space. 6791 // in new space.
6757 ASSERT(space == Heap::kOld); 6792 ASSERT(space == Heap::kOld);
6758 } 6793 }
6759 return result.raw(); 6794 return result.raw();
6760 } 6795 }
6761 6796
6762 6797
6763 RawFunction* Function::Clone(const Class& new_owner) const { 6798 RawFunction* Function::Clone(const Class& new_owner) const {
6764 ASSERT(!IsGenerativeConstructor()); 6799 ASSERT(!IsGenerativeConstructor());
6765 Function& clone = Function::Handle(); 6800 Thread* thread = Thread::Current();
6801 Zone* zone = thread->zone();
6802 Function& clone = Function::Handle(zone);
6766 clone ^= Object::Clone(*this, Heap::kOld); 6803 clone ^= Object::Clone(*this, Heap::kOld);
6767 const Class& origin = Class::Handle(this->origin()); 6804 const Class& origin = Class::Handle(zone, this->origin());
6768 const PatchClass& clone_owner = 6805 const PatchClass& clone_owner =
6769 PatchClass::Handle(PatchClass::New(new_owner, origin)); 6806 PatchClass::Handle(zone, PatchClass::New(new_owner, origin));
6770 clone.set_owner(clone_owner); 6807 clone.set_owner(clone_owner);
6771 clone.ClearICDataArray(); 6808 clone.ClearICDataArray();
6772 clone.ClearCode(); 6809 clone.ClearCode();
6773 clone.set_usage_counter(0); 6810 clone.set_usage_counter(0);
6774 clone.set_deoptimization_counter(0); 6811 clone.set_deoptimization_counter(0);
6775 clone.set_optimized_instruction_count(0); 6812 clone.set_optimized_instruction_count(0);
6776 clone.set_optimized_call_site_count(0); 6813 clone.set_optimized_call_site_count(0);
6777 clone.set_kernel_function(kernel_function()); 6814 clone.set_kernel_function(kernel_function());
6778 // TODO(regis): Clone function type parameters (their bounds may change).
6779 if (new_owner.NumTypeParameters() > 0) { 6815 if (new_owner.NumTypeParameters() > 0) {
6780 // Adjust uninstantiated types to refer to type parameters of the new owner. 6816 // Adjust uninstantiated types to refer to type parameters of the new owner.
6781 AbstractType& type = AbstractType::Handle(clone.result_type()); 6817 const TypeArguments& type_params =
6818 TypeArguments::Handle(zone, type_parameters());
6819 if (!type_params.IsNull()) {
6820 const intptr_t num_type_params = type_params.Length();
6821 const TypeArguments& type_params_clone =
6822 TypeArguments::Handle(zone, TypeArguments::New(num_type_params));
6823 TypeParameter& type_param = TypeParameter::Handle(zone);
6824 for (intptr_t i = 0; i < num_type_params; i++) {
6825 type_param ^= type_params.TypeAt(i);
6826 type_param ^= type_param.CloneUninstantiated(new_owner);
6827 type_params_clone.SetTypeAt(i, type_param);
6828 }
6829 clone.set_type_parameters(type_params_clone);
6830 }
6831 AbstractType& type = AbstractType::Handle(zone, clone.result_type());
6782 type ^= type.CloneUninstantiated(new_owner); 6832 type ^= type.CloneUninstantiated(new_owner);
6783 clone.set_result_type(type); 6833 clone.set_result_type(type);
6784 const intptr_t num_params = clone.NumParameters(); 6834 const intptr_t num_params = clone.NumParameters();
6785 Array& array = Array::Handle(clone.parameter_types()); 6835 Array& array = Array::Handle(zone, clone.parameter_types());
6786 array ^= Object::Clone(array, Heap::kOld); 6836 array ^= Object::Clone(array, Heap::kOld);
6787 clone.set_parameter_types(array); 6837 clone.set_parameter_types(array);
6788 for (intptr_t i = 0; i < num_params; i++) { 6838 for (intptr_t i = 0; i < num_params; i++) {
6789 type = clone.ParameterTypeAt(i); 6839 type = clone.ParameterTypeAt(i);
6790 type ^= type.CloneUninstantiated(new_owner); 6840 type ^= type.CloneUninstantiated(new_owner);
6791 clone.SetParameterTypeAt(i, type); 6841 clone.SetParameterTypeAt(i, type);
6792 } 6842 }
6793 } 6843 }
6794 return clone.raw(); 6844 return clone.raw();
6795 } 6845 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
6852 result.set_eval_script(script); 6902 result.set_eval_script(script);
6853 return result.raw(); 6903 return result.raw();
6854 } 6904 }
6855 6905
6856 RawFunction* Function::ImplicitClosureFunction() const { 6906 RawFunction* Function::ImplicitClosureFunction() const {
6857 // Return the existing implicit closure function if any. 6907 // Return the existing implicit closure function if any.
6858 if (implicit_closure_function() != Function::null()) { 6908 if (implicit_closure_function() != Function::null()) {
6859 return implicit_closure_function(); 6909 return implicit_closure_function();
6860 } 6910 }
6861 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); 6911 ASSERT(!IsSignatureFunction() && !IsClosureFunction());
6912 Thread* thread = Thread::Current();
6913 Zone* zone = thread->zone();
6862 // Create closure function. 6914 // Create closure function.
6863 const String& closure_name = String::Handle(name()); 6915 const String& closure_name = String::Handle(zone, name());
6864 const Function& closure_function = 6916 const Function& closure_function = Function::Handle(
6865 Function::Handle(NewClosureFunction(closure_name, *this, token_pos())); 6917 zone, NewClosureFunction(closure_name, *this, token_pos()));
6866 6918
6867 // Set closure function's context scope. 6919 // Set closure function's context scope.
6868 if (is_static()) { 6920 if (is_static()) {
6869 closure_function.set_context_scope(Object::empty_context_scope()); 6921 closure_function.set_context_scope(Object::empty_context_scope());
6870 } else { 6922 } else {
6871 const ContextScope& context_scope = 6923 const ContextScope& context_scope = ContextScope::Handle(
6872 ContextScope::Handle(LocalScope::CreateImplicitClosureScope(*this)); 6924 zone, LocalScope::CreateImplicitClosureScope(*this));
6873 closure_function.set_context_scope(context_scope); 6925 closure_function.set_context_scope(context_scope);
6874 } 6926 }
6875 6927
6928 // Set closure function's type parameters.
6929 closure_function.set_type_parameters(
6930 TypeArguments::Handle(zone, type_parameters()));
6931
6876 // Set closure function's result type to this result type. 6932 // Set closure function's result type to this result type.
6877 closure_function.set_result_type(AbstractType::Handle(result_type())); 6933 closure_function.set_result_type(AbstractType::Handle(zone, result_type()));
6878 6934
6879 // Set closure function's end token to this end token. 6935 // Set closure function's end token to this end token.
6880 closure_function.set_end_token_pos(end_token_pos()); 6936 closure_function.set_end_token_pos(end_token_pos());
6881 6937
6882 // The closurized method stub just calls into the original method and should 6938 // The closurized method stub just calls into the original method and should
6883 // therefore be skipped by the debugger and in stack traces. 6939 // therefore be skipped by the debugger and in stack traces.
6884 closure_function.set_is_debuggable(false); 6940 closure_function.set_is_debuggable(false);
6885 closure_function.set_is_visible(false); 6941 closure_function.set_is_visible(false);
6886 6942
6887 // Set closure function's formal parameters to this formal parameters, 6943 // Set closure function's formal parameters to this formal parameters,
6888 // removing the receiver if this is an instance method and adding the closure 6944 // removing the receiver if this is an instance method and adding the closure
6889 // object as first parameter. 6945 // object as first parameter.
6890 const int kClosure = 1; 6946 const int kClosure = 1;
6891 const int has_receiver = is_static() ? 0 : 1; 6947 const int has_receiver = is_static() ? 0 : 1;
6892 const int num_fixed_params = kClosure - has_receiver + num_fixed_parameters(); 6948 const int num_fixed_params = kClosure - has_receiver + num_fixed_parameters();
6893 const int num_opt_params = NumOptionalParameters(); 6949 const int num_opt_params = NumOptionalParameters();
6894 const bool has_opt_pos_params = HasOptionalPositionalParameters(); 6950 const bool has_opt_pos_params = HasOptionalPositionalParameters();
6895 const int num_params = num_fixed_params + num_opt_params; 6951 const int num_params = num_fixed_params + num_opt_params;
6896 closure_function.set_num_fixed_parameters(num_fixed_params); 6952 closure_function.set_num_fixed_parameters(num_fixed_params);
6897 closure_function.SetNumOptionalParameters(num_opt_params, has_opt_pos_params); 6953 closure_function.SetNumOptionalParameters(num_opt_params, has_opt_pos_params);
6898 closure_function.set_parameter_types( 6954 closure_function.set_parameter_types(
6899 Array::Handle(Array::New(num_params, Heap::kOld))); 6955 Array::Handle(zone, Array::New(num_params, Heap::kOld)));
6900 closure_function.set_parameter_names( 6956 closure_function.set_parameter_names(
6901 Array::Handle(Array::New(num_params, Heap::kOld))); 6957 Array::Handle(zone, Array::New(num_params, Heap::kOld)));
6902 AbstractType& param_type = AbstractType::Handle(); 6958 AbstractType& param_type = AbstractType::Handle(zone);
6903 String& param_name = String::Handle(); 6959 String& param_name = String::Handle(zone);
6904 // Add implicit closure object parameter. 6960 // Add implicit closure object parameter.
6905 param_type = Type::DynamicType(); 6961 param_type = Type::DynamicType();
6906 closure_function.SetParameterTypeAt(0, param_type); 6962 closure_function.SetParameterTypeAt(0, param_type);
6907 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter()); 6963 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter());
6908 for (int i = kClosure; i < num_params; i++) { 6964 for (int i = kClosure; i < num_params; i++) {
6909 param_type = ParameterTypeAt(has_receiver - kClosure + i); 6965 param_type = ParameterTypeAt(has_receiver - kClosure + i);
6910 closure_function.SetParameterTypeAt(i, param_type); 6966 closure_function.SetParameterTypeAt(i, param_type);
6911 param_name = ParameterNameAt(has_receiver - kClosure + i); 6967 param_name = ParameterNameAt(has_receiver - kClosure + i);
6912 closure_function.SetParameterNameAt(i, param_name); 6968 closure_function.SetParameterNameAt(i, param_name);
6913 } 6969 }
6914 closure_function.set_kernel_function(kernel_function()); 6970 closure_function.set_kernel_function(kernel_function());
6915 6971
6916 const Type& signature_type = Type::Handle(closure_function.SignatureType()); 6972 const Type& signature_type =
6973 Type::Handle(zone, closure_function.SignatureType());
6917 if (!signature_type.IsFinalized()) { 6974 if (!signature_type.IsFinalized()) {
6918 ClassFinalizer::FinalizeType(Class::Handle(Owner()), signature_type); 6975 ClassFinalizer::FinalizeType(Class::Handle(zone, Owner()), signature_type);
6919 } 6976 }
6920 set_implicit_closure_function(closure_function); 6977 set_implicit_closure_function(closure_function);
6921 ASSERT(closure_function.IsImplicitClosureFunction()); 6978 ASSERT(closure_function.IsImplicitClosureFunction());
6922 return closure_function.raw(); 6979 return closure_function.raw();
6923 } 6980 }
6924 6981
6925 6982
6926 void Function::DropUncompiledImplicitClosureFunction() const { 6983 void Function::DropUncompiledImplicitClosureFunction() const {
6927 if (implicit_closure_function() != Function::null()) { 6984 if (implicit_closure_function() != Function::null()) {
6928 const Function& func = Function::Handle(implicit_closure_function()); 6985 const Function& func = Function::Handle(implicit_closure_function());
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
7058 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); 7115 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1);
7059 ClosureData::Cast(obj).set_hash(result); 7116 ClosureData::Cast(obj).set_hash(result);
7060 return Smi::New(result); 7117 return Smi::New(result);
7061 } 7118 }
7062 7119
7063 7120
7064 RawString* Function::BuildSignature(NameVisibility name_visibility) const { 7121 RawString* Function::BuildSignature(NameVisibility name_visibility) const {
7065 Thread* thread = Thread::Current(); 7122 Thread* thread = Thread::Current();
7066 Zone* zone = thread->zone(); 7123 Zone* zone = thread->zone();
7067 GrowableHandlePtrArray<const String> pieces(zone, 4); 7124 GrowableHandlePtrArray<const String> pieces(zone, 4);
7125 String& name = String::Handle(zone);
7126 if (FLAG_reify_generic_functions) {
7127 const TypeArguments& type_params =
7128 TypeArguments::Handle(zone, type_parameters());
7129 if (!type_params.IsNull()) {
7130 const intptr_t num_type_params = type_params.Length();
7131 ASSERT(num_type_params > 0);
7132 TypeParameter& type_param = TypeParameter::Handle(zone);
7133 AbstractType& bound = AbstractType::Handle(zone);
7134 pieces.Add(Symbols::LAngleBracket());
7135 for (intptr_t i = 0; i < num_type_params; i++) {
7136 type_param ^= type_params.TypeAt(i);
7137 name = type_param.name();
7138 pieces.Add(name);
7139 bound = type_param.bound();
7140 if (!bound.IsNull() && !bound.IsObjectType()) {
7141 pieces.Add(Symbols::SpaceExtendsSpace());
7142 name = bound.BuildName(name_visibility);
7143 pieces.Add(name);
7144 }
7145 if (i < num_type_params - 1) {
7146 pieces.Add(Symbols::CommaSpace());
7147 }
7148 }
7149 pieces.Add(Symbols::RAngleBracket());
7150 }
7151 }
7068 pieces.Add(Symbols::LParen()); 7152 pieces.Add(Symbols::LParen());
7069 BuildSignatureParameters(thread, zone, name_visibility, &pieces); 7153 BuildSignatureParameters(thread, zone, name_visibility, &pieces);
7070 pieces.Add(Symbols::RParenArrow()); 7154 pieces.Add(Symbols::RParenArrow());
7071 const AbstractType& res_type = AbstractType::Handle(zone, result_type()); 7155 const AbstractType& res_type = AbstractType::Handle(zone, result_type());
7072 const String& name = 7156 name = res_type.BuildName(name_visibility);
7073 String::Handle(zone, res_type.BuildName(name_visibility));
7074 pieces.Add(name); 7157 pieces.Add(name);
7075 return Symbols::FromConcatAll(thread, pieces); 7158 return Symbols::FromConcatAll(thread, pieces);
7076 } 7159 }
7077 7160
7078 7161
7079 bool Function::HasInstantiatedSignature(Genericity genericity, 7162 bool Function::HasInstantiatedSignature(Genericity genericity,
7080 TrailPtr trail) const { 7163 TrailPtr trail) const {
7081 AbstractType& type = AbstractType::Handle(result_type()); 7164 AbstractType& type = AbstractType::Handle(result_type());
7082 if (!type.IsInstantiated(genericity, trail)) { 7165 if (!type.IsInstantiated(genericity, trail)) {
7083 return false; 7166 return false;
(...skipping 8723 matching lines...) Expand 10 before | Expand all | Expand 10 after
15807 // Check if this instance understands a call() method of a compatible type. 15890 // Check if this instance understands a call() method of a compatible type.
15808 Function& sig_fun = 15891 Function& sig_fun =
15809 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); 15892 Function::Handle(zone, cls.LookupCallFunctionForTypeTest());
15810 if (!sig_fun.IsNull()) { 15893 if (!sig_fun.IsNull()) {
15811 if (other_is_dart_function) { 15894 if (other_is_dart_function) {
15812 return true; 15895 return true;
15813 } 15896 }
15814 if (!sig_fun.HasInstantiatedSignature()) { 15897 if (!sig_fun.HasInstantiatedSignature()) {
15815 const TypeArguments& function_type_arguments = 15898 const TypeArguments& function_type_arguments =
15816 TypeArguments::Handle(zone, sig_fun.type_parameters()); 15899 TypeArguments::Handle(zone, sig_fun.type_parameters());
15817 // TODO(regis): Pass the closure context to InstantiateSignatureFrom().
15818 // No bound error possible, since the instance exists. 15900 // No bound error possible, since the instance exists.
15819 sig_fun = sig_fun.InstantiateSignatureFrom( 15901 sig_fun = sig_fun.InstantiateSignatureFrom(
15820 type_arguments, function_type_arguments, Heap::kOld); 15902 type_arguments, function_type_arguments, Heap::kOld);
15821 } 15903 }
15822 const Function& other_signature = 15904 const Function& other_signature =
15823 Function::Handle(zone, Type::Cast(instantiated_other).signature()); 15905 Function::Handle(zone, Type::Cast(instantiated_other).signature());
15824 if (sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld)) { 15906 if (sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld)) {
15825 return true; 15907 return true;
15826 } 15908 }
15827 } 15909 }
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after
17116 ASSERT(Type::Cast(other).IsFunctionType()); 17198 ASSERT(Type::Cast(other).IsFunctionType());
17117 // Equal function types must have equal signature types and equal optional 17199 // Equal function types must have equal signature types and equal optional
17118 // named arguments. 17200 // named arguments.
17119 if (signature() == other_type.signature()) { 17201 if (signature() == other_type.signature()) {
17120 return true; 17202 return true;
17121 } 17203 }
17122 const Function& sig_fun = Function::Handle(zone, signature()); 17204 const Function& sig_fun = Function::Handle(zone, signature());
17123 const Function& other_sig_fun = 17205 const Function& other_sig_fun =
17124 Function::Handle(zone, other_type.signature()); 17206 Function::Handle(zone, other_type.signature());
17125 17207
17208 if (FLAG_reify_generic_functions) {
17209 // Compare function type parameters and their bounds.
17210 // Check the type parameters and bounds of generic functions.
17211 if (!sig_fun.HasSameTypeParametersAndBounds(other_sig_fun)) {
17212 return false;
17213 }
17214 }
17215
17126 // Compare number of function parameters. 17216 // Compare number of function parameters.
17127 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters(); 17217 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters();
17128 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters(); 17218 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters();
17129 if (num_fixed_params != other_num_fixed_params) { 17219 if (num_fixed_params != other_num_fixed_params) {
17130 return false; 17220 return false;
17131 } 17221 }
17132 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters(); 17222 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters();
17133 const intptr_t other_num_opt_pos_params = 17223 const intptr_t other_num_opt_pos_params =
17134 other_sig_fun.NumOptionalPositionalParameters(); 17224 other_sig_fun.NumOptionalPositionalParameters();
17135 if (num_opt_pos_params != other_num_opt_pos_params) { 17225 if (num_opt_pos_params != other_num_opt_pos_params) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
17204 if (IsMalbounded()) { 17294 if (IsMalbounded()) {
17205 const LanguageError& bound_error = LanguageError::Handle(zone, error()); 17295 const LanguageError& bound_error = LanguageError::Handle(zone, error());
17206 clone.set_error(bound_error); 17296 clone.set_error(bound_error);
17207 } 17297 }
17208 // Clone the signature if this type represents a function type. 17298 // Clone the signature if this type represents a function type.
17209 Function& fun = Function::Handle(zone, signature()); 17299 Function& fun = Function::Handle(zone, signature());
17210 if (!fun.IsNull()) { 17300 if (!fun.IsNull()) {
17211 const Class& owner = Class::Handle(zone, fun.Owner()); 17301 const Class& owner = Class::Handle(zone, fun.Owner());
17212 Function& fun_clone = Function::Handle( 17302 Function& fun_clone = Function::Handle(
17213 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); 17303 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource));
17214 // TODO(regis): Handle cloning of a generic function type. 17304 const TypeArguments& type_params =
17305 TypeArguments::Handle(zone, fun.type_parameters());
17306 if (!type_params.IsNull()) {
17307 const intptr_t num_type_params = type_params.Length();
17308 const TypeArguments& type_params_clone =
17309 TypeArguments::Handle(zone, TypeArguments::New(num_type_params));
17310 TypeParameter& type_param = TypeParameter::Handle(zone);
17311 for (intptr_t i = 0; i < num_type_params; i++) {
17312 type_param ^= type_params.TypeAt(i);
17313 type_param ^= type_param.CloneUnfinalized();
17314 type_params_clone.SetTypeAt(i, type_param);
17315 }
17316 fun_clone.set_type_parameters(type_params_clone);
17317 }
17215 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); 17318 AbstractType& type = AbstractType::Handle(zone, fun.result_type());
17216 type = type.CloneUnfinalized(); 17319 type = type.CloneUnfinalized();
17217 fun_clone.set_result_type(type); 17320 fun_clone.set_result_type(type);
17218 const intptr_t num_params = fun.NumParameters(); 17321 const intptr_t num_params = fun.NumParameters();
17219 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); 17322 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters());
17220 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), 17323 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(),
17221 fun.HasOptionalPositionalParameters()); 17324 fun.HasOptionalPositionalParameters());
17222 fun_clone.set_parameter_types( 17325 fun_clone.set_parameter_types(
17223 Array::Handle(Array::New(num_params, Heap::kOld))); 17326 Array::Handle(Array::New(num_params, Heap::kOld)));
17224 for (intptr_t i = 0; i < num_params; i++) { 17327 for (intptr_t i = 0; i < num_params; i++) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
17260 } 17363 }
17261 // Clone the signature if this type represents a function type. 17364 // Clone the signature if this type represents a function type.
17262 const Function& fun = Function::Handle(zone, signature()); 17365 const Function& fun = Function::Handle(zone, signature());
17263 if (!fun.IsNull()) { 17366 if (!fun.IsNull()) {
17264 ASSERT(type_cls.IsTypedefClass() || type_cls.IsClosureClass()); 17367 ASSERT(type_cls.IsTypedefClass() || type_cls.IsClosureClass());
17265 // If the scope class is not a typedef and if it is generic, it must be the 17368 // If the scope class is not a typedef and if it is generic, it must be the
17266 // mixin class, set it to the new owner. 17369 // mixin class, set it to the new owner.
17267 Function& fun_clone = Function::Handle( 17370 Function& fun_clone = Function::Handle(
17268 zone, 17371 zone,
17269 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource)); 17372 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource));
17373 const TypeArguments& type_params =
17374 TypeArguments::Handle(zone, fun.type_parameters());
17375 if (!type_params.IsNull()) {
17376 const intptr_t num_type_params = type_params.Length();
17377 const TypeArguments& type_params_clone =
17378 TypeArguments::Handle(zone, TypeArguments::New(num_type_params));
17379 TypeParameter& type_param = TypeParameter::Handle(zone);
17380 for (intptr_t i = 0; i < num_type_params; i++) {
17381 type_param ^= type_params.TypeAt(i);
17382 type_param ^= type_param.CloneUninstantiated(new_owner, trail);
17383 type_params_clone.SetTypeAt(i, type_param);
17384 }
17385 fun_clone.set_type_parameters(type_params_clone);
17386 }
17270 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); 17387 AbstractType& type = AbstractType::Handle(zone, fun.result_type());
17271 type = type.CloneUninstantiated(new_owner, trail); 17388 type = type.CloneUninstantiated(new_owner, trail);
17272 fun_clone.set_result_type(type); 17389 fun_clone.set_result_type(type);
17273 const intptr_t num_params = fun.NumParameters(); 17390 const intptr_t num_params = fun.NumParameters();
17274 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); 17391 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters());
17275 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), 17392 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(),
17276 fun.HasOptionalPositionalParameters()); 17393 fun.HasOptionalPositionalParameters());
17277 fun_clone.set_parameter_types( 17394 fun_clone.set_parameter_types(
17278 Array::Handle(Array::New(num_params, Heap::kOld))); 17395 Array::Handle(Array::New(num_params, Heap::kOld)));
17279 for (intptr_t i = 0; i < num_params; i++) { 17396 for (intptr_t i = 0; i < num_params; i++) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
17386 ASSERT(type_args.IsNull() || type_args.IsOld()); 17503 ASSERT(type_args.IsNull() || type_args.IsOld());
17387 17504
17388 // In case of a function type, replace the actual function by a signature 17505 // In case of a function type, replace the actual function by a signature
17389 // function. 17506 // function.
17390 if (IsFunctionType()) { 17507 if (IsFunctionType()) {
17391 const Function& fun = Function::Handle(zone, signature()); 17508 const Function& fun = Function::Handle(zone, signature());
17392 if (!fun.IsSignatureFunction()) { 17509 if (!fun.IsSignatureFunction()) {
17393 Function& sig_fun = Function::Handle( 17510 Function& sig_fun = Function::Handle(
17394 zone, 17511 zone,
17395 Function::NewSignatureFunction(cls, TokenPosition::kNoSource)); 17512 Function::NewSignatureFunction(cls, TokenPosition::kNoSource));
17513 sig_fun.set_type_parameters(
17514 TypeArguments::Handle(zone, fun.type_parameters()));
17396 type = fun.result_type(); 17515 type = fun.result_type();
17397 type = type.Canonicalize(trail); 17516 type = type.Canonicalize(trail);
17398 sig_fun.set_result_type(type); 17517 sig_fun.set_result_type(type);
17399 const intptr_t num_params = fun.NumParameters(); 17518 const intptr_t num_params = fun.NumParameters();
17400 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters()); 17519 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters());
17401 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(), 17520 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(),
17402 fun.HasOptionalPositionalParameters()); 17521 fun.HasOptionalPositionalParameters());
17403 sig_fun.set_parameter_types( 17522 sig_fun.set_parameter_types(
17404 Array::Handle(Array::New(num_params, Heap::kOld))); 17523 Array::Handle(Array::New(num_params, Heap::kOld)));
17405 for (intptr_t i = 0; i < num_params; i++) { 17524 for (intptr_t i = 0; i < num_params; i++) {
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
18013 return TypeParameter::New(Class::Handle(parameterized_class()), 18132 return TypeParameter::New(Class::Handle(parameterized_class()),
18014 Function::Handle(parameterized_function()), index(), 18133 Function::Handle(parameterized_function()), index(),
18015 String::Handle(name()), 18134 String::Handle(name()),
18016 AbstractType::Handle(bound()), token_pos()); 18135 AbstractType::Handle(bound()), token_pos());
18017 } 18136 }
18018 18137
18019 18138
18020 RawAbstractType* TypeParameter::CloneUninstantiated(const Class& new_owner, 18139 RawAbstractType* TypeParameter::CloneUninstantiated(const Class& new_owner,
18021 TrailPtr trail) const { 18140 TrailPtr trail) const {
18022 ASSERT(IsFinalized()); 18141 ASSERT(IsFinalized());
18023 TypeParameter& clone = TypeParameter::Handle(); 18142 Thread* thread = Thread::Current();
18143 Zone* zone = thread->zone();
18144 TypeParameter& clone = TypeParameter::Handle(zone);
18024 clone ^= OnlyBuddyInTrail(trail); 18145 clone ^= OnlyBuddyInTrail(trail);
18025 if (!clone.IsNull()) { 18146 if (!clone.IsNull()) {
18026 return clone.raw(); 18147 return clone.raw();
18027 } 18148 }
18028 const Class& old_owner = Class::Handle(parameterized_class()); 18149 intptr_t new_index = index();
18029 if (old_owner.IsNull()) { 18150 AbstractType& upper_bound = AbstractType::Handle(zone, bound());
18151 const Function& fun = Function::Handle(zone, parameterized_function());
18152 Class& cls = Class::Handle(zone, parameterized_class());
18153 if (!cls.IsNull()) {
18154 ASSERT(fun.IsNull());
18155 new_index += new_owner.NumTypeArguments() - cls.NumTypeArguments();
18156 cls = new_owner.raw();
18157 } else {
18030 ASSERT(IsFunctionTypeParameter()); 18158 ASSERT(IsFunctionTypeParameter());
18031 // Function type parameters do not need cloning. 18159 // Only the bounds of function type parameters need cloning.
18032 return raw();
18033 } 18160 }
18034 const intptr_t new_index = 18161 clone = TypeParameter::New(cls, fun, new_index, String::Handle(zone, name()),
18035 index() + new_owner.NumTypeArguments() - old_owner.NumTypeArguments();
18036 AbstractType& upper_bound = AbstractType::Handle(bound());
18037 ASSERT(parameterized_function() == Function::null());
18038 clone = TypeParameter::New(new_owner, Function::Handle(), new_index,
18039 String::Handle(name()),
18040 upper_bound, // Not cloned yet. 18162 upper_bound, // Not cloned yet.
18041 token_pos()); 18163 token_pos());
18042 clone.SetIsFinalized(); 18164 clone.SetIsFinalized();
18043 AddOnlyBuddyToTrail(&trail, clone); 18165 AddOnlyBuddyToTrail(&trail, clone);
18044 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); 18166 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail);
18045 clone.set_bound(upper_bound); 18167 clone.set_bound(upper_bound);
18046 return clone.raw(); 18168 return clone.raw();
18047 } 18169 }
18048 18170
18049 18171
(...skipping 5118 matching lines...) Expand 10 before | Expand all | Expand 10 after
23168 return UserTag::null(); 23290 return UserTag::null();
23169 } 23291 }
23170 23292
23171 23293
23172 const char* UserTag::ToCString() const { 23294 const char* UserTag::ToCString() const {
23173 const String& tag_label = String::Handle(label()); 23295 const String& tag_label = String::Handle(label());
23174 return tag_label.ToCString(); 23296 return tag_label.ToCString();
23175 } 23297 }
23176 23298
23177 } // namespace dart 23299 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698