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

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

Issue 2951803005: Set and keep parent function of signature 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 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 6507 matching lines...) Expand 10 before | Expand all | Expand 10 after
6518 return true; 6518 return true;
6519 } 6519 }
6520 6520
6521 6521
6522 RawFunction* Function::InstantiateSignatureFrom( 6522 RawFunction* Function::InstantiateSignatureFrom(
6523 const TypeArguments& instantiator_type_arguments, 6523 const TypeArguments& instantiator_type_arguments,
6524 const TypeArguments& function_type_arguments, 6524 const TypeArguments& function_type_arguments,
6525 Heap::Space space) const { 6525 Heap::Space space) const {
6526 Zone* zone = Thread::Current()->zone(); 6526 Zone* zone = Thread::Current()->zone();
6527 const Object& owner = Object::Handle(zone, RawOwner()); 6527 const Object& owner = Object::Handle(zone, RawOwner());
6528 const Function& parent = Function::Handle(zone, parent_function());
6528 ASSERT(!HasInstantiatedSignature()); 6529 ASSERT(!HasInstantiatedSignature());
6529 Function& sig = Function::Handle( 6530 Function& sig = Function::Handle(
6530 zone, 6531 zone, Function::NewSignatureFunction(owner, parent,
6531 Function::NewSignatureFunction(owner, TokenPosition::kNoSource, space)); 6532 TokenPosition::kNoSource, space));
6532 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); 6533 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters()));
6533 AbstractType& type = AbstractType::Handle(zone, result_type()); 6534 AbstractType& type = AbstractType::Handle(zone, result_type());
6534 if (!type.IsInstantiated()) { 6535 if (!type.IsInstantiated()) {
6535 type = 6536 type =
6536 type.InstantiateFrom(instantiator_type_arguments, 6537 type.InstantiateFrom(instantiator_type_arguments,
6537 function_type_arguments, NULL, NULL, NULL, space); 6538 function_type_arguments, NULL, NULL, NULL, space);
6538 } 6539 }
6539 sig.set_result_type(type); 6540 sig.set_result_type(type);
6540 const intptr_t num_params = NumParameters(); 6541 const intptr_t num_params = NumParameters();
6541 sig.set_num_fixed_parameters(num_fixed_parameters()); 6542 sig.set_num_fixed_parameters(num_fixed_parameters());
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
6912 /* is_const = */ false, 6913 /* is_const = */ false,
6913 /* is_abstract = */ false, 6914 /* is_abstract = */ false,
6914 /* is_external = */ false, 6915 /* is_external = */ false,
6915 /* is_native = */ false, parent_owner, token_pos)); 6916 /* is_native = */ false, parent_owner, token_pos));
6916 result.set_parent_function(parent); 6917 result.set_parent_function(parent);
6917 return result.raw(); 6918 return result.raw();
6918 } 6919 }
6919 6920
6920 6921
6921 RawFunction* Function::NewSignatureFunction(const Object& owner, 6922 RawFunction* Function::NewSignatureFunction(const Object& owner,
6923 const Function& parent,
6922 TokenPosition token_pos, 6924 TokenPosition token_pos,
6923 Heap::Space space) { 6925 Heap::Space space) {
6924 const Function& result = Function::Handle(Function::New( 6926 const Function& result = Function::Handle(Function::New(
6925 Symbols::AnonymousSignature(), RawFunction::kSignatureFunction, 6927 Symbols::AnonymousSignature(), RawFunction::kSignatureFunction,
6926 /* is_static = */ false, 6928 /* is_static = */ false,
6927 /* is_const = */ false, 6929 /* is_const = */ false,
6928 /* is_abstract = */ false, 6930 /* is_abstract = */ false,
6929 /* is_external = */ false, 6931 /* is_external = */ false,
6930 /* is_native = */ false, 6932 /* is_native = */ false,
6931 owner, // Same as function type scope class. 6933 owner, // Same as function type scope class.
6932 token_pos, space)); 6934 token_pos, space));
6935 result.set_parent_function(parent);
6933 result.set_is_reflectable(false); 6936 result.set_is_reflectable(false);
6934 result.set_is_visible(false); 6937 result.set_is_visible(false);
6935 result.set_is_debuggable(false); 6938 result.set_is_debuggable(false);
6936 return result.raw(); 6939 return result.raw();
6937 } 6940 }
6938 6941
6939 6942
6940 RawFunction* Function::NewEvalFunction(const Class& owner, 6943 RawFunction* Function::NewEvalFunction(const Class& owner,
6941 const Script& script, 6944 const Script& script,
6942 bool is_static) { 6945 bool is_static) {
(...skipping 9865 matching lines...) Expand 10 before | Expand all | Expand 10 after
16808 if (IsTypeParameter()) { 16811 if (IsTypeParameter()) {
16809 const TypeParameter& type_param = TypeParameter::Cast(*this); 16812 const TypeParameter& type_param = TypeParameter::Cast(*this);
16810 if (other.IsTypeParameter()) { 16813 if (other.IsTypeParameter()) {
16811 const TypeParameter& other_type_param = TypeParameter::Cast(other); 16814 const TypeParameter& other_type_param = TypeParameter::Cast(other);
16812 if (type_param.Equals(other_type_param)) { 16815 if (type_param.Equals(other_type_param)) {
16813 return true; 16816 return true;
16814 } 16817 }
16815 // TODO(regis): Should we update TypeParameter::IsEquivalent() instead? 16818 // TODO(regis): Should we update TypeParameter::IsEquivalent() instead?
16816 if (type_param.IsFunctionTypeParameter() && 16819 if (type_param.IsFunctionTypeParameter() &&
16817 other_type_param.IsFunctionTypeParameter() && 16820 other_type_param.IsFunctionTypeParameter() &&
16818 type_param.IsFinalized() && other_type_param.IsFinalized() && 16821 type_param.IsFinalized() && other_type_param.IsFinalized()) {
16819 (type_param.index() == other_type_param.index())) { 16822 // To be compatible, the function type parameters should be declared at
16820 return true; 16823 // the same position in the generic function. Their index therefore
16824 // needs adjustement before comparison.
16825 // Example: 'foo<F>(bar<B>(B b)) { }' and 'baz<Z>(Z z) { }', baz can be
16826 // assigned to bar, although B has index 1 and Z index 0.
16827 const Function& sig_fun =
16828 Function::Handle(zone, type_param.parameterized_function());
16829 const Function& other_sig_fun =
16830 Function::Handle(zone, other_type_param.parameterized_function());
16831 const int offset = sig_fun.NumParentTypeParameters();
16832 const int other_offset = other_sig_fun.NumParentTypeParameters();
16833 if (type_param.index() - offset ==
16834 other_type_param.index() - other_offset) {
16835 return true;
16836 }
16821 } 16837 }
16822 } 16838 }
16823 const AbstractType& bound = AbstractType::Handle(zone, type_param.bound()); 16839 const AbstractType& bound = AbstractType::Handle(zone, type_param.bound());
16824 // We may be checking bounds at finalization time and can encounter 16840 // We may be checking bounds at finalization time and can encounter
16825 // a still unfinalized bound. Finalizing the bound here may lead to cycles. 16841 // a still unfinalized bound. Finalizing the bound here may lead to cycles.
16826 if (!bound.IsFinalized()) { 16842 if (!bound.IsFinalized()) {
16827 return false; // TODO(regis): Return "maybe after instantiation". 16843 return false; // TODO(regis): Return "maybe after instantiation".
16828 } 16844 }
16829 // The current bound_trail cannot be used, because operands are swapped and 16845 // The current bound_trail cannot be used, because operands are swapped and
16830 // the test is different anyway (more specific vs. subtype). 16846 // the test is different anyway (more specific vs. subtype).
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
17438 Type::New(Class::Handle(zone, type_class()), type_args, token_pos())); 17454 Type::New(Class::Handle(zone, type_class()), type_args, token_pos()));
17439 // Preserve the bound error if any. 17455 // Preserve the bound error if any.
17440 if (IsMalbounded()) { 17456 if (IsMalbounded()) {
17441 const LanguageError& bound_error = LanguageError::Handle(zone, error()); 17457 const LanguageError& bound_error = LanguageError::Handle(zone, error());
17442 clone.set_error(bound_error); 17458 clone.set_error(bound_error);
17443 } 17459 }
17444 // Clone the signature if this type represents a function type. 17460 // Clone the signature if this type represents a function type.
17445 Function& fun = Function::Handle(zone, signature()); 17461 Function& fun = Function::Handle(zone, signature());
17446 if (!fun.IsNull()) { 17462 if (!fun.IsNull()) {
17447 const Class& owner = Class::Handle(zone, fun.Owner()); 17463 const Class& owner = Class::Handle(zone, fun.Owner());
17448 Function& fun_clone = Function::Handle( 17464 const Function& parent = Function::Handle(zone, fun.parent_function());
17449 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); 17465 Function& fun_clone =
17466 Function::Handle(zone, Function::NewSignatureFunction(
17467 owner, parent, TokenPosition::kNoSource));
17450 const TypeArguments& type_params = 17468 const TypeArguments& type_params =
17451 TypeArguments::Handle(zone, fun.type_parameters()); 17469 TypeArguments::Handle(zone, fun.type_parameters());
17452 if (!type_params.IsNull()) { 17470 if (!type_params.IsNull()) {
17453 const intptr_t num_type_params = type_params.Length(); 17471 const intptr_t num_type_params = type_params.Length();
17454 const TypeArguments& type_params_clone = 17472 const TypeArguments& type_params_clone =
17455 TypeArguments::Handle(zone, TypeArguments::New(num_type_params)); 17473 TypeArguments::Handle(zone, TypeArguments::New(num_type_params));
17456 TypeParameter& type_param = TypeParameter::Handle(zone); 17474 TypeParameter& type_param = TypeParameter::Handle(zone);
17457 for (intptr_t i = 0; i < num_type_params; i++) { 17475 for (intptr_t i = 0; i < num_type_params; i++) {
17458 type_param ^= type_params.TypeAt(i); 17476 type_param ^= type_params.TypeAt(i);
17459 type_param ^= type_param.CloneUnfinalized(); 17477 type_param ^= type_param.CloneUnfinalized();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
17506 if (IsMalbounded()) { 17524 if (IsMalbounded()) {
17507 const LanguageError& bound_error = LanguageError::Handle(zone, error()); 17525 const LanguageError& bound_error = LanguageError::Handle(zone, error());
17508 clone.set_error(bound_error); 17526 clone.set_error(bound_error);
17509 } 17527 }
17510 // Clone the signature if this type represents a function type. 17528 // Clone the signature if this type represents a function type.
17511 const Function& fun = Function::Handle(zone, signature()); 17529 const Function& fun = Function::Handle(zone, signature());
17512 if (!fun.IsNull()) { 17530 if (!fun.IsNull()) {
17513 ASSERT(type_cls.IsTypedefClass() || type_cls.IsClosureClass()); 17531 ASSERT(type_cls.IsTypedefClass() || type_cls.IsClosureClass());
17514 // If the scope class is not a typedef and if it is generic, it must be the 17532 // If the scope class is not a typedef and if it is generic, it must be the
17515 // mixin class, set it to the new owner. 17533 // mixin class, set it to the new owner.
17534 const Function& parent = Function::Handle(zone, fun.parent_function());
17535 // TODO(regis): Is it safe to reuse the parent function with the old owner?
17516 Function& fun_clone = Function::Handle( 17536 Function& fun_clone = Function::Handle(
17517 zone, 17537 zone, Function::NewSignatureFunction(new_owner, parent,
17518 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource)); 17538 TokenPosition::kNoSource));
17519 const TypeArguments& type_params = 17539 const TypeArguments& type_params =
17520 TypeArguments::Handle(zone, fun.type_parameters()); 17540 TypeArguments::Handle(zone, fun.type_parameters());
17521 if (!type_params.IsNull()) { 17541 if (!type_params.IsNull()) {
17522 const intptr_t num_type_params = type_params.Length(); 17542 const intptr_t num_type_params = type_params.Length();
17523 const TypeArguments& type_params_clone = 17543 const TypeArguments& type_params_clone =
17524 TypeArguments::Handle(zone, TypeArguments::New(num_type_params)); 17544 TypeArguments::Handle(zone, TypeArguments::New(num_type_params));
17525 TypeParameter& type_param = TypeParameter::Handle(zone); 17545 TypeParameter& type_param = TypeParameter::Handle(zone);
17526 for (intptr_t i = 0; i < num_type_params; i++) { 17546 for (intptr_t i = 0; i < num_type_params; i++) {
17527 type_param ^= type_params.TypeAt(i); 17547 type_param ^= type_params.TypeAt(i);
17528 type_param ^= type_param.CloneUninstantiated(new_owner, trail); 17548 type_param ^= type_param.CloneUninstantiated(new_owner, trail);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
17653 return this->raw(); 17673 return this->raw();
17654 } 17674 }
17655 set_arguments(type_args); 17675 set_arguments(type_args);
17656 ASSERT(type_args.IsNull() || type_args.IsOld()); 17676 ASSERT(type_args.IsNull() || type_args.IsOld());
17657 17677
17658 // In case of a function type, replace the actual function by a signature 17678 // In case of a function type, replace the actual function by a signature
17659 // function. 17679 // function.
17660 if (IsFunctionType()) { 17680 if (IsFunctionType()) {
17661 const Function& fun = Function::Handle(zone, signature()); 17681 const Function& fun = Function::Handle(zone, signature());
17662 if (!fun.IsSignatureFunction()) { 17682 if (!fun.IsSignatureFunction()) {
17663 Function& sig_fun = Function::Handle( 17683 // In case of a generic function, the function type parameters in the
17664 zone, 17684 // signature will still refer to the original function. This should not
17665 Function::NewSignatureFunction(cls, TokenPosition::kNoSource)); 17685 // be a problem, since they are finalized and the indices remain
17686 // unchanged.
17687 const Function& parent = Function::Handle(zone, fun.parent_function());
17688 Function& sig_fun =
17689 Function::Handle(zone, Function::NewSignatureFunction(
17690 cls, parent, TokenPosition::kNoSource));
17666 sig_fun.set_type_parameters( 17691 sig_fun.set_type_parameters(
17667 TypeArguments::Handle(zone, fun.type_parameters())); 17692 TypeArguments::Handle(zone, fun.type_parameters()));
17693 ASSERT(fun.HasGenericParent() == sig_fun.HasGenericParent());
17694 ASSERT(fun.IsGeneric() == sig_fun.IsGeneric());
17668 type = fun.result_type(); 17695 type = fun.result_type();
17669 type = type.Canonicalize(trail); 17696 type = type.Canonicalize(trail);
17670 sig_fun.set_result_type(type); 17697 sig_fun.set_result_type(type);
17671 const intptr_t num_params = fun.NumParameters(); 17698 const intptr_t num_params = fun.NumParameters();
17672 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters()); 17699 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters());
17673 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(), 17700 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(),
17674 fun.HasOptionalPositionalParameters()); 17701 fun.HasOptionalPositionalParameters());
17675 sig_fun.set_parameter_types( 17702 sig_fun.set_parameter_types(
17676 Array::Handle(Array::New(num_params, Heap::kOld))); 17703 Array::Handle(Array::New(num_params, Heap::kOld)));
17677 for (intptr_t i = 0; i < num_params; i++) { 17704 for (intptr_t i = 0; i < num_params; i++) {
(...skipping 5772 matching lines...) Expand 10 before | Expand all | Expand 10 after
23450 return UserTag::null(); 23477 return UserTag::null();
23451 } 23478 }
23452 23479
23453 23480
23454 const char* UserTag::ToCString() const { 23481 const char* UserTag::ToCString() const {
23455 const String& tag_label = String::Handle(label()); 23482 const String& tag_label = String::Handle(label());
23456 return tag_label.ToCString(); 23483 return tag_label.ToCString();
23457 } 23484 }
23458 23485
23459 } // namespace dart 23486 } // 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