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

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

Issue 2793033005: Keep types in signatures of function types properly instantiated as the function (Closed)
Patch Set: 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
« runtime/vm/class_finalizer.cc ('K') | « runtime/vm/object.h ('k') | no next file » | 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 4806 matching lines...) Expand 10 before | Expand all | Expand 10 after
4817 4817
4818 4818
4819 bool TypeArguments::IsSubvectorInstantiated(intptr_t from_index, 4819 bool TypeArguments::IsSubvectorInstantiated(intptr_t from_index,
4820 intptr_t len, 4820 intptr_t len,
4821 Genericity genericity, 4821 Genericity genericity,
4822 TrailPtr trail) const { 4822 TrailPtr trail) const {
4823 ASSERT(!IsNull()); 4823 ASSERT(!IsNull());
4824 AbstractType& type = AbstractType::Handle(); 4824 AbstractType& type = AbstractType::Handle();
4825 for (intptr_t i = 0; i < len; i++) { 4825 for (intptr_t i = 0; i < len; i++) {
4826 type = TypeAt(from_index + i); 4826 type = TypeAt(from_index + i);
4827 // If the type argument is null, the type parameterized with this type 4827 // If this type argument T is null, the type A containing T in its flattened
4828 // argument is still being finalized. Skip this null type argument. 4828 // type argument vector V is recursive and is still being finalized.
4829 // T is the type argument of a super type of A. T is being instantiated
4830 // during finalization of V, which is also the instantiator. T depends
4831 // solely on the type parameters of A and will be replaced by a non-null
4832 // type before A is marked as finalized.
4829 if (!type.IsNull() && !type.IsInstantiated(genericity, trail)) { 4833 if (!type.IsNull() && !type.IsInstantiated(genericity, trail)) {
4830 return false; 4834 return false;
4831 } 4835 }
4832 } 4836 }
4833 return true; 4837 return true;
4834 } 4838 }
4835 4839
4836 4840
4837 bool TypeArguments::IsUninstantiatedIdentity() const { 4841 bool TypeArguments::IsUninstantiatedIdentity() const {
4838 ASSERT(!IsInstantiated()); 4842 ASSERT(!IsInstantiated());
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
5078 } 5082 }
5079 // The zero array should have been initialized. 5083 // The zero array should have been initialized.
5080 ASSERT(Object::zero_array().raw() != Array::null()); 5084 ASSERT(Object::zero_array().raw() != Array::null());
5081 COMPILE_ASSERT(StubCode::kNoInstantiator == 0); 5085 COMPILE_ASSERT(StubCode::kNoInstantiator == 0);
5082 result.set_instantiations(Object::zero_array()); 5086 result.set_instantiations(Object::zero_array());
5083 return result.raw(); 5087 return result.raw();
5084 } 5088 }
5085 5089
5086 5090
5087 RawAbstractType* const* TypeArguments::TypeAddr(intptr_t index) const { 5091 RawAbstractType* const* TypeArguments::TypeAddr(intptr_t index) const {
5088 // TODO(iposva): Determine if we should throw an exception here.
5089 ASSERT((index >= 0) && (index < Length())); 5092 ASSERT((index >= 0) && (index < Length()));
5090 return &raw_ptr()->types()[index]; 5093 return &raw_ptr()->types()[index];
5091 } 5094 }
5092 5095
5093 5096
5094 void TypeArguments::SetLength(intptr_t value) const { 5097 void TypeArguments::SetLength(intptr_t value) const {
5095 ASSERT(!IsCanonical()); 5098 ASSERT(!IsCanonical());
5096 // This is only safe because we create a new Smi, which does not cause 5099 // This is only safe because we create a new Smi, which does not cause
5097 // heap allocation. 5100 // heap allocation.
5098 StoreSmi(&raw_ptr()->length_, Smi::New(value)); 5101 StoreSmi(&raw_ptr()->length_, Smi::New(value));
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
5618 Type& type = Type::Handle(); 5621 Type& type = Type::Handle();
5619 const Object& obj = Object::Handle(raw_ptr()->data_); 5622 const Object& obj = Object::Handle(raw_ptr()->data_);
5620 ASSERT(!obj.IsNull()); 5623 ASSERT(!obj.IsNull());
5621 if (IsSignatureFunction()) { 5624 if (IsSignatureFunction()) {
5622 type = SignatureData::Cast(obj).signature_type(); 5625 type = SignatureData::Cast(obj).signature_type();
5623 } else { 5626 } else {
5624 ASSERT(IsClosureFunction()); 5627 ASSERT(IsClosureFunction());
5625 type = ClosureData::Cast(obj).signature_type(); 5628 type = ClosureData::Cast(obj).signature_type();
5626 } 5629 }
5627 if (type.IsNull()) { 5630 if (type.IsNull()) {
5628 // A function type is parameterized in the same way as the owner class of 5631 // The function type of this function is not yet cached and needs to be
5629 // its non-static signature function. 5632 // constructed and cached here.
5630 // It is not type parameterized if its signature function is static. 5633 // A function type is type parameterized in the same way as the owner class
5631 // During type finalization, the type arguments of the super class of the 5634 // of its non-static signature function.
5632 // owner class of its signature function will be prepended to the type 5635 // It is not type parameterized if its signature function is static, or if
5633 // argument vector. Therefore, we only need to set the type arguments 5636 // none of its result type or formal parameter types are type parameterized.
5634 // matching the type parameters here. 5637 // Unless the function type is a generic typedef, the type arguments of the
5635 // In case of a function type alias, the function owner is the alias class, 5638 // function type are not explicitly stored in the function type as a vector
5636 // i.e. the typedef. The signature type is therefore parameterized according 5639 // of type arguments.
5637 // to the alias class declaration, even if the function type is not generic. 5640 // The type class of a non-typedef function type is always the non-generic
5638 // Otherwise, if the function is static or if its signature type is 5641 // _Closure class, whether the type is generic or not.
5639 // non-generic, i.e. it does not depend on any type parameter of the owner 5642 // The type class of a typedef function type is always the typedef class,
5640 // class, then the signature type is not parameterized, although the owner 5643 // which may be generic, in which case the type stores type arguments.
5641 // class may be. In this case, the scope class of the function type is reset
5642 // to _Closure class as well as the owner of the signature function.
5643 // With the introduction of generic functions, we may reach here before the 5644 // With the introduction of generic functions, we may reach here before the
5644 // function type parameters have been resolved. Therefore, we cannot yet 5645 // function type parameters have been resolved. Therefore, we cannot yet
5645 // check whether the function type has an instantiated signature. 5646 // check whether the function type has an instantiated signature.
5646 // We will do it later when resolving the type. 5647 // We can do it only when the signature has been resolved.
5648 // We only set the type class of the function type to the typedef class
5649 // if the signature of the function type is the signature of the typedef.
5650 // Note that a function type can have a typedef class as owner without
5651 // representing the typedef, as in the following example:
5652 // typedef F(f(int x)); where the type of f is a function type with F as
5653 // owner, without representing the function type of F.
5647 Class& scope_class = Class::Handle(Owner()); 5654 Class& scope_class = Class::Handle(Owner());
5648 if (!scope_class.IsTypedefClass() && 5655 if (!scope_class.IsTypedefClass() ||
5649 (is_static() || !scope_class.IsGeneric())) { 5656 (scope_class.signature_function() != raw())) {
5650 scope_class = Isolate::Current()->object_store()->closure_class(); 5657 scope_class = Isolate::Current()->object_store()->closure_class();
5651 if (IsSignatureFunction()) {
5652 set_owner(scope_class);
5653 set_token_pos(TokenPosition::kNoSource);
5654 }
5655 } 5658 }
5656 // TODO(regis): With generic functions, this type is not only parameterized
5657 // with the type parameters of the scope class, but also with those of all
5658 // enclosing generic functions, which may not even have been parsed at this
5659 // point. What actually matters is that a signature type can be expressed in
5660 // a right-hand side type test by name. This is only possible with a typedef
5661 // and the free variables are only the type parameters of the typedef.
5662 const TypeArguments& signature_type_arguments = 5659 const TypeArguments& signature_type_arguments =
5663 TypeArguments::Handle(scope_class.type_parameters()); 5660 TypeArguments::Handle(scope_class.type_parameters());
5664 // Return the still unfinalized signature type. 5661 // Return the still unfinalized signature type.
5665 type = Type::New(scope_class, signature_type_arguments, token_pos()); 5662 type = Type::New(scope_class, signature_type_arguments, token_pos());
5666 type.set_signature(*this); 5663 type.set_signature(*this);
5667 SetSignatureType(type); 5664 SetSignatureType(type);
5668 } 5665 }
5669 return type.raw(); 5666 return type.raw();
5670 } 5667 }
5671 5668
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
6388 return chars; 6385 return chars;
6389 } 6386 }
6390 6387
6391 6388
6392 bool Function::HasCompatibleParametersWith(const Function& other, 6389 bool Function::HasCompatibleParametersWith(const Function& other,
6393 Error* bound_error) const { 6390 Error* bound_error) const {
6394 ASSERT(Isolate::Current()->error_on_bad_override()); 6391 ASSERT(Isolate::Current()->error_on_bad_override());
6395 ASSERT((bound_error != NULL) && bound_error->IsNull()); 6392 ASSERT((bound_error != NULL) && bound_error->IsNull());
6396 // Check that this function's signature type is a subtype of the other 6393 // Check that this function's signature type is a subtype of the other
6397 // function's signature type. 6394 // function's signature type.
6398 if (!TypeTest(kIsSubtypeOf, Object::null_type_arguments(), other, 6395 // Map type parameters in the signature to dynamic before the test.
6399 Object::null_type_arguments(), bound_error, Heap::kOld)) { 6396 Function& this_fun = Function::Handle(raw());
6397 if (!this_fun.HasInstantiatedSignature()) {
6398 // TODO(regis): Should we pass the context explicitly here (i.e. null) once
6399 // we support generic functions?
6400 this_fun = this_fun.InstantiateSignatureFrom(Object::null_type_arguments(),
6401 Heap::kOld);
6402 }
6403 Function& other_fun = Function::Handle(other.raw());
6404 if (!other_fun.HasInstantiatedSignature()) {
6405 // TODO(regis): Should we pass the context explicitly here (i.e. null) once
6406 // we support generic functions?
6407 other_fun = other_fun.InstantiateSignatureFrom(
6408 Object::null_type_arguments(), Heap::kOld);
6409 }
6410 if (!this_fun.TypeTest(kIsSubtypeOf, other_fun, bound_error, Heap::kOld)) {
6400 // For more informative error reporting, use the location of the other 6411 // For more informative error reporting, use the location of the other
6401 // function here, since the caller will use the location of this function. 6412 // function here, since the caller will use the location of this function.
6402 *bound_error = LanguageError::NewFormatted( 6413 *bound_error = LanguageError::NewFormatted(
6403 *bound_error, // A bound error if non null. 6414 *bound_error, // A bound error if non null.
6404 Script::Handle(other.script()), other.token_pos(), Report::AtLocation, 6415 Script::Handle(other.script()), other.token_pos(), Report::AtLocation,
6405 Report::kError, Heap::kNew, 6416 Report::kError, Heap::kNew,
6406 "signature type '%s' of function '%s' is not a subtype of signature " 6417 "signature type '%s' of function '%s' is not a subtype of signature "
6407 "type '%s' of function '%s' where\n%s%s", 6418 "type '%s' of function '%s'\n",
6408 String::Handle(UserVisibleSignature()).ToCString(), 6419 String::Handle(UserVisibleSignature()).ToCString(),
6409 String::Handle(UserVisibleName()).ToCString(), 6420 String::Handle(UserVisibleName()).ToCString(),
6410 String::Handle(other.UserVisibleSignature()).ToCString(), 6421 String::Handle(other.UserVisibleSignature()).ToCString(),
6411 String::Handle(other.UserVisibleName()).ToCString(), 6422 String::Handle(other.UserVisibleName()).ToCString());
6412 String::Handle(Type::Handle(SignatureType()).EnumerateURIs())
6413 .ToCString(),
6414 String::Handle(Type::Handle(other.SignatureType()).EnumerateURIs())
6415 .ToCString());
6416 return false; 6423 return false;
6417 } 6424 }
6418 // We should also check that if the other function explicitly specifies a 6425 // We should also check that if the other function explicitly specifies a
6419 // default value for a formal parameter, this function does not specify a 6426 // default value for a formal parameter, this function does not specify a
6420 // different default value for the same parameter. However, this check is not 6427 // different default value for the same parameter. However, this check is not
6421 // possible in the current implementation, because the default parameter 6428 // possible in the current implementation, because the default parameter
6422 // values are not stored in the Function object, but discarded after a 6429 // values are not stored in the Function object, but discarded after a
6423 // function is compiled. 6430 // function is compiled.
6424 return true; 6431 return true;
6425 } 6432 }
6426 6433
6427 6434
6435 RawFunction* Function::InstantiateSignatureFrom(
6436 const TypeArguments& instantiator_type_arguments,
6437 Heap::Space space) const {
6438 Zone* zone = Thread::Current()->zone();
6439 const Object& owner = Object::Handle(zone, RawOwner());
6440 // TODO(regis): Should we change Function::New() to accept a space, since
6441 // InstantiateFrom is sometimes called with Heap::kNew?
6442 ASSERT(!HasInstantiatedSignature());
6443 Function& sig = Function::Handle(
6444 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource));
6445 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters()));
6446 AbstractType& type = AbstractType::Handle(zone, result_type());
6447 if (!type.IsInstantiated()) {
6448 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL,
6449 space);
6450 }
6451 sig.set_result_type(type);
6452 const intptr_t num_params = NumParameters();
6453 sig.set_num_fixed_parameters(num_fixed_parameters());
6454 sig.SetNumOptionalParameters(NumOptionalParameters(),
6455 HasOptionalPositionalParameters());
6456 sig.set_parameter_types(Array::Handle(Array::New(num_params, space)));
6457 for (intptr_t i = 0; i < num_params; i++) {
6458 type = ParameterTypeAt(i);
6459 if (!type.IsInstantiated()) {
6460 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL,
6461 space);
6462 }
6463 sig.SetParameterTypeAt(i, type);
6464 }
6465 sig.set_parameter_names(Array::Handle(zone, parameter_names()));
6466 return sig.raw();
6467 }
6468
6469
6428 // If test_kind == kIsSubtypeOf, checks if the type of the specified parameter 6470 // If test_kind == kIsSubtypeOf, checks if the type of the specified parameter
6429 // of this function is a subtype or a supertype of the type of the specified 6471 // of this function is a subtype or a supertype of the type of the specified
6430 // parameter of the other function. 6472 // parameter of the other function.
6431 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified 6473 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified
6432 // parameter of this function is more specific than the type of the specified 6474 // parameter of this function is more specific than the type of the specified
6433 // parameter of the other function. 6475 // parameter of the other function.
6434 // Note that we do not apply contravariance of parameter types, but covariance 6476 // Note that we do not apply contravariance of parameter types, but covariance
6435 // of both parameter types and result type. 6477 // of both parameter types and result type.
6436 bool Function::TestParameterType(TypeTestKind test_kind, 6478 bool Function::TestParameterType(TypeTestKind test_kind,
6437 intptr_t parameter_position, 6479 intptr_t parameter_position,
6438 intptr_t other_parameter_position, 6480 intptr_t other_parameter_position,
6439 const TypeArguments& type_arguments,
6440 const Function& other, 6481 const Function& other,
6441 const TypeArguments& other_type_arguments,
6442 Error* bound_error, 6482 Error* bound_error,
6443 Heap::Space space) const { 6483 Heap::Space space) const {
6444 AbstractType& other_param_type = 6484 const AbstractType& other_param_type =
6445 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position)); 6485 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position));
6446 if (!other_param_type.IsInstantiated()) {
6447 other_param_type =
6448 other_param_type.InstantiateFrom(other_type_arguments, bound_error,
6449 NULL, // instantiation_trail
6450 NULL, // bound_trail
6451 space);
6452 ASSERT((bound_error == NULL) || bound_error->IsNull());
6453 }
6454 if (other_param_type.IsDynamicType()) { 6486 if (other_param_type.IsDynamicType()) {
6455 return true; 6487 return true;
6456 } 6488 }
6457 AbstractType& param_type = 6489 const AbstractType& param_type =
6458 AbstractType::Handle(ParameterTypeAt(parameter_position)); 6490 AbstractType::Handle(ParameterTypeAt(parameter_position));
6459 if (!param_type.IsInstantiated()) {
6460 param_type = param_type.InstantiateFrom(type_arguments, bound_error,
6461 NULL, // instantiation_trail
6462 NULL, // bound_trail
6463 space);
6464 ASSERT((bound_error == NULL) || bound_error->IsNull());
6465 }
6466 if (param_type.IsDynamicType()) { 6491 if (param_type.IsDynamicType()) {
6467 return test_kind == kIsSubtypeOf; 6492 return test_kind == kIsSubtypeOf;
6468 } 6493 }
6469 if (test_kind == kIsSubtypeOf) { 6494 if (test_kind == kIsSubtypeOf) {
6470 if (!param_type.IsSubtypeOf(other_param_type, bound_error, NULL, space) && 6495 if (!param_type.IsSubtypeOf(other_param_type, bound_error, NULL, space) &&
6471 !other_param_type.IsSubtypeOf(param_type, bound_error, NULL, space)) { 6496 !other_param_type.IsSubtypeOf(param_type, bound_error, NULL, space)) {
6472 return false; 6497 return false;
6473 } 6498 }
6474 } else { 6499 } else {
6475 ASSERT(test_kind == kIsMoreSpecificThan); 6500 ASSERT(test_kind == kIsMoreSpecificThan);
6476 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error, NULL, 6501 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error, NULL,
6477 space)) { 6502 space)) {
6478 return false; 6503 return false;
6479 } 6504 }
6480 } 6505 }
6481 return true; 6506 return true;
6482 } 6507 }
6483 6508
6484 6509
6485 bool Function::TypeTest(TypeTestKind test_kind, 6510 bool Function::TypeTest(TypeTestKind test_kind,
6486 const TypeArguments& type_arguments,
6487 const Function& other, 6511 const Function& other,
6488 const TypeArguments& other_type_arguments,
6489 Error* bound_error, 6512 Error* bound_error,
6490 Heap::Space space) const { 6513 Heap::Space space) const {
6491 const intptr_t num_fixed_params = num_fixed_parameters(); 6514 const intptr_t num_fixed_params = num_fixed_parameters();
6492 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); 6515 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters();
6493 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); 6516 const intptr_t num_opt_named_params = NumOptionalNamedParameters();
6494 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); 6517 const intptr_t other_num_fixed_params = other.num_fixed_parameters();
6495 const intptr_t other_num_opt_pos_params = 6518 const intptr_t other_num_opt_pos_params =
6496 other.NumOptionalPositionalParameters(); 6519 other.NumOptionalPositionalParameters();
6497 const intptr_t other_num_opt_named_params = 6520 const intptr_t other_num_opt_named_params =
6498 other.NumOptionalNamedParameters(); 6521 other.NumOptionalNamedParameters();
6499 // This function requires the same arguments or less and accepts the same 6522 // This function requires the same arguments or less and accepts the same
6500 // arguments or more. We can ignore implicit parameters. 6523 // arguments or more. We can ignore implicit parameters.
6501 const intptr_t num_ignored_params = NumImplicitParameters(); 6524 const intptr_t num_ignored_params = NumImplicitParameters();
6502 const intptr_t other_num_ignored_params = other.NumImplicitParameters(); 6525 const intptr_t other_num_ignored_params = other.NumImplicitParameters();
6503 if (((num_fixed_params - num_ignored_params) > 6526 if (((num_fixed_params - num_ignored_params) >
6504 (other_num_fixed_params - other_num_ignored_params)) || 6527 (other_num_fixed_params - other_num_ignored_params)) ||
6505 ((num_fixed_params - num_ignored_params + num_opt_pos_params) < 6528 ((num_fixed_params - num_ignored_params + num_opt_pos_params) <
6506 (other_num_fixed_params - other_num_ignored_params + 6529 (other_num_fixed_params - other_num_ignored_params +
6507 other_num_opt_pos_params)) || 6530 other_num_opt_pos_params)) ||
6508 (num_opt_named_params < other_num_opt_named_params)) { 6531 (num_opt_named_params < other_num_opt_named_params)) {
6509 return false; 6532 return false;
6510 } 6533 }
6511 // Check the result type. 6534 // Check the result type.
6512 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); 6535 const AbstractType& other_res_type =
6513 if (!other_res_type.IsInstantiated()) { 6536 AbstractType::Handle(other.result_type());
6514 other_res_type = other_res_type.InstantiateFrom(
6515 other_type_arguments, bound_error, NULL, NULL, space);
6516 ASSERT((bound_error == NULL) || bound_error->IsNull());
6517 }
6518 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { 6537 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) {
6519 AbstractType& res_type = AbstractType::Handle(result_type()); 6538 const AbstractType& res_type = AbstractType::Handle(result_type());
6520 if (!res_type.IsInstantiated()) {
6521 res_type = res_type.InstantiateFrom(type_arguments, bound_error, NULL,
6522 NULL, space);
6523 ASSERT((bound_error == NULL) || bound_error->IsNull());
6524 }
6525 if (res_type.IsVoidType()) { 6539 if (res_type.IsVoidType()) {
6526 return false; 6540 return false;
6527 } 6541 }
6528 if (test_kind == kIsSubtypeOf) { 6542 if (test_kind == kIsSubtypeOf) {
6529 if (!res_type.IsSubtypeOf(other_res_type, bound_error, NULL, space) && 6543 if (!res_type.IsSubtypeOf(other_res_type, bound_error, NULL, space) &&
6530 !other_res_type.IsSubtypeOf(res_type, bound_error, NULL, space)) { 6544 !other_res_type.IsSubtypeOf(res_type, bound_error, NULL, space)) {
6531 return false; 6545 return false;
6532 } 6546 }
6533 } else { 6547 } else {
6534 ASSERT(test_kind == kIsMoreSpecificThan); 6548 ASSERT(test_kind == kIsMoreSpecificThan);
6535 if (!res_type.IsMoreSpecificThan(other_res_type, bound_error, NULL, 6549 if (!res_type.IsMoreSpecificThan(other_res_type, bound_error, NULL,
6536 space)) { 6550 space)) {
6537 return false; 6551 return false;
6538 } 6552 }
6539 } 6553 }
6540 } 6554 }
6541 // Check the types of fixed and optional positional parameters. 6555 // Check the types of fixed and optional positional parameters.
6542 for (intptr_t i = 0; i < (other_num_fixed_params - other_num_ignored_params + 6556 for (intptr_t i = 0; i < (other_num_fixed_params - other_num_ignored_params +
6543 other_num_opt_pos_params); 6557 other_num_opt_pos_params);
6544 i++) { 6558 i++) {
6545 if (!TestParameterType(test_kind, i + num_ignored_params, 6559 if (!TestParameterType(test_kind, i + num_ignored_params,
6546 i + other_num_ignored_params, type_arguments, other, 6560 i + other_num_ignored_params, other, bound_error,
6547 other_type_arguments, bound_error, space)) { 6561 space)) {
6548 return false; 6562 return false;
6549 } 6563 }
6550 } 6564 }
6551 // Check the names and types of optional named parameters. 6565 // Check the names and types of optional named parameters.
6552 if (other_num_opt_named_params == 0) { 6566 if (other_num_opt_named_params == 0) {
6553 return true; 6567 return true;
6554 } 6568 }
6555 // Check that for each optional named parameter of type T of the other 6569 // Check that for each optional named parameter of type T of the other
6556 // function type, there exists an optional named parameter of this function 6570 // function type, there exists an optional named parameter of this function
6557 // type with an identical name and with a type S that is a either a subtype 6571 // type with an identical name and with a type S that is a either a subtype
6558 // or supertype of T (if test_kind == kIsSubtypeOf) or that is more specific 6572 // or supertype of T (if test_kind == kIsSubtypeOf) or that is more specific
6559 // than T (if test_kind == kIsMoreSpecificThan). 6573 // than T (if test_kind == kIsMoreSpecificThan).
6560 // Note that SetParameterNameAt() guarantees that names are symbols, so we 6574 // Note that SetParameterNameAt() guarantees that names are symbols, so we
6561 // can compare their raw pointers. 6575 // can compare their raw pointers.
6562 const int num_params = num_fixed_params + num_opt_named_params; 6576 const int num_params = num_fixed_params + num_opt_named_params;
6563 const int other_num_params = 6577 const int other_num_params =
6564 other_num_fixed_params + other_num_opt_named_params; 6578 other_num_fixed_params + other_num_opt_named_params;
6565 bool found_param_name; 6579 bool found_param_name;
6566 String& other_param_name = String::Handle(); 6580 String& other_param_name = String::Handle();
6567 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { 6581 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) {
6568 other_param_name = other.ParameterNameAt(i); 6582 other_param_name = other.ParameterNameAt(i);
6569 ASSERT(other_param_name.IsSymbol()); 6583 ASSERT(other_param_name.IsSymbol());
6570 found_param_name = false; 6584 found_param_name = false;
6571 for (intptr_t j = num_fixed_params; j < num_params; j++) { 6585 for (intptr_t j = num_fixed_params; j < num_params; j++) {
6572 ASSERT(String::Handle(ParameterNameAt(j)).IsSymbol()); 6586 ASSERT(String::Handle(ParameterNameAt(j)).IsSymbol());
6573 if (ParameterNameAt(j) == other_param_name.raw()) { 6587 if (ParameterNameAt(j) == other_param_name.raw()) {
6574 found_param_name = true; 6588 found_param_name = true;
6575 if (!TestParameterType(test_kind, j, i, type_arguments, other, 6589 if (!TestParameterType(test_kind, j, i, other, bound_error, space)) {
6576 other_type_arguments, bound_error, space)) {
6577 return false; 6590 return false;
6578 } 6591 }
6579 break; 6592 break;
6580 } 6593 }
6581 } 6594 }
6582 if (!found_param_name) { 6595 if (!found_param_name) {
6583 return false; 6596 return false;
6584 } 6597 }
6585 } 6598 }
6586 return true; 6599 return true;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
6635 6648
6636 RawFunction* Function::New(const String& name, 6649 RawFunction* Function::New(const String& name,
6637 RawFunction::Kind kind, 6650 RawFunction::Kind kind,
6638 bool is_static, 6651 bool is_static,
6639 bool is_const, 6652 bool is_const,
6640 bool is_abstract, 6653 bool is_abstract,
6641 bool is_external, 6654 bool is_external,
6642 bool is_native, 6655 bool is_native,
6643 const Object& owner, 6656 const Object& owner,
6644 TokenPosition token_pos) { 6657 TokenPosition token_pos) {
6645 ASSERT(!owner.IsNull()); 6658 ASSERT(!owner.IsNull() || (kind == RawFunction::kSignatureFunction));
6646 const Function& result = Function::Handle(Function::New()); 6659 const Function& result = Function::Handle(Function::New());
6647 result.set_parameter_types(Object::empty_array()); 6660 result.set_parameter_types(Object::empty_array());
6648 result.set_parameter_names(Object::empty_array()); 6661 result.set_parameter_names(Object::empty_array());
6649 result.set_name(name); 6662 result.set_name(name);
6650 result.set_kind(kind); 6663 result.set_kind(kind);
6651 result.set_recognized_kind(MethodRecognizer::kUnknown); 6664 result.set_recognized_kind(MethodRecognizer::kUnknown);
6652 result.set_modifier(RawFunction::kNoModifier); 6665 result.set_modifier(RawFunction::kNoModifier);
6653 result.set_is_static(is_static); 6666 result.set_is_static(is_static);
6654 result.set_is_const(is_const); 6667 result.set_is_const(is_const);
6655 result.set_is_abstract(is_abstract); 6668 result.set_is_abstract(is_abstract);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
6699 const PatchClass& clone_owner = 6712 const PatchClass& clone_owner =
6700 PatchClass::Handle(PatchClass::New(new_owner, origin)); 6713 PatchClass::Handle(PatchClass::New(new_owner, origin));
6701 clone.set_owner(clone_owner); 6714 clone.set_owner(clone_owner);
6702 clone.ClearICDataArray(); 6715 clone.ClearICDataArray();
6703 clone.ClearCode(); 6716 clone.ClearCode();
6704 clone.set_usage_counter(0); 6717 clone.set_usage_counter(0);
6705 clone.set_deoptimization_counter(0); 6718 clone.set_deoptimization_counter(0);
6706 clone.set_optimized_instruction_count(0); 6719 clone.set_optimized_instruction_count(0);
6707 clone.set_optimized_call_site_count(0); 6720 clone.set_optimized_call_site_count(0);
6708 clone.set_kernel_function(kernel_function()); 6721 clone.set_kernel_function(kernel_function());
6722 // TODO(regis): Clone function type parameters (their bounds may change).
6709 if (new_owner.NumTypeParameters() > 0) { 6723 if (new_owner.NumTypeParameters() > 0) {
6710 // Adjust uninstantiated types to refer to type parameters of the new owner. 6724 // Adjust uninstantiated types to refer to type parameters of the new owner.
6711 AbstractType& type = AbstractType::Handle(clone.result_type()); 6725 AbstractType& type = AbstractType::Handle(clone.result_type());
6712 type ^= type.CloneUninstantiated(new_owner); 6726 type ^= type.CloneUninstantiated(new_owner);
6713 clone.set_result_type(type); 6727 clone.set_result_type(type);
6714 const intptr_t num_params = clone.NumParameters(); 6728 const intptr_t num_params = clone.NumParameters();
6715 Array& array = Array::Handle(clone.parameter_types()); 6729 Array& array = Array::Handle(clone.parameter_types());
6716 array ^= Object::Clone(array, Heap::kOld); 6730 array ^= Object::Clone(array, Heap::kOld);
6717 clone.set_parameter_types(array); 6731 clone.set_parameter_types(array);
6718 for (intptr_t i = 0; i < num_params; i++) { 6732 for (intptr_t i = 0; i < num_params; i++) {
(...skipping 18 matching lines...) Expand all
6737 /* is_static = */ parent.is_static(), 6751 /* is_static = */ parent.is_static(),
6738 /* is_const = */ false, 6752 /* is_const = */ false,
6739 /* is_abstract = */ false, 6753 /* is_abstract = */ false,
6740 /* is_external = */ false, 6754 /* is_external = */ false,
6741 /* is_native = */ false, parent_owner, token_pos)); 6755 /* is_native = */ false, parent_owner, token_pos));
6742 result.set_parent_function(parent); 6756 result.set_parent_function(parent);
6743 return result.raw(); 6757 return result.raw();
6744 } 6758 }
6745 6759
6746 6760
6747 RawFunction* Function::NewSignatureFunction(const Class& owner, 6761 RawFunction* Function::NewSignatureFunction(const Object& owner,
6748 TokenPosition token_pos) { 6762 TokenPosition token_pos) {
6749 const Function& result = Function::Handle(Function::New( 6763 const Function& result = Function::Handle(Function::New(
6750 Symbols::AnonymousSignature(), RawFunction::kSignatureFunction, 6764 Symbols::AnonymousSignature(), RawFunction::kSignatureFunction,
6751 /* is_static = */ false, 6765 /* is_static = */ false,
6752 /* is_const = */ false, 6766 /* is_const = */ false,
6753 /* is_abstract = */ false, 6767 /* is_abstract = */ false,
6754 /* is_external = */ false, 6768 /* is_external = */ false,
6755 /* is_native = */ false, 6769 /* is_native = */ false,
6756 owner, // Same as function type scope class. 6770 owner, // Same as function type scope class.
6757 token_pos)); 6771 token_pos));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
6861 } 6875 }
6862 } 6876 }
6863 6877
6864 6878
6865 RawString* Function::UserVisibleFormalParameters() const { 6879 RawString* Function::UserVisibleFormalParameters() const {
6866 Thread* thread = Thread::Current(); 6880 Thread* thread = Thread::Current();
6867 Zone* zone = thread->zone(); 6881 Zone* zone = thread->zone();
6868 // Typically 3, 5,.. elements in 'pieces', e.g.: 6882 // Typically 3, 5,.. elements in 'pieces', e.g.:
6869 // '_LoadRequest', CommaSpace, '_LoadError'. 6883 // '_LoadRequest', CommaSpace, '_LoadError'.
6870 GrowableHandlePtrArray<const String> pieces(zone, 5); 6884 GrowableHandlePtrArray<const String> pieces(zone, 5);
6871 const TypeArguments& instantiator = TypeArguments::Handle(zone); 6885 BuildSignatureParameters(thread, zone, kUserVisibleName, &pieces);
6872 BuildSignatureParameters(thread, zone, false, kUserVisibleName, instantiator,
6873 &pieces);
6874 return Symbols::FromConcatAll(thread, pieces); 6886 return Symbols::FromConcatAll(thread, pieces);
6875 } 6887 }
6876 6888
6877 6889
6878 void Function::BuildSignatureParameters( 6890 void Function::BuildSignatureParameters(
6879 Thread* thread, 6891 Thread* thread,
6880 Zone* zone, 6892 Zone* zone,
6881 bool instantiate,
6882 NameVisibility name_visibility, 6893 NameVisibility name_visibility,
6883 const TypeArguments& instantiator,
6884 GrowableHandlePtrArray<const String>* pieces) const { 6894 GrowableHandlePtrArray<const String>* pieces) const {
6885 AbstractType& param_type = AbstractType::Handle(zone); 6895 AbstractType& param_type = AbstractType::Handle(zone);
6886 const intptr_t num_params = NumParameters(); 6896 const intptr_t num_params = NumParameters();
6887 const intptr_t num_fixed_params = num_fixed_parameters(); 6897 const intptr_t num_fixed_params = num_fixed_parameters();
6888 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); 6898 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters();
6889 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); 6899 const intptr_t num_opt_named_params = NumOptionalNamedParameters();
6890 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; 6900 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params;
6891 ASSERT((num_fixed_params + num_opt_params) == num_params); 6901 ASSERT((num_fixed_params + num_opt_params) == num_params);
6892 intptr_t i = 0; 6902 intptr_t i = 0;
6893 if (name_visibility == kUserVisibleName) { 6903 if (name_visibility == kUserVisibleName) {
6894 // Hide implicit parameters. 6904 // Hide implicit parameters.
6895 i = NumImplicitParameters(); 6905 i = NumImplicitParameters();
6896 } 6906 }
6897 String& name = String::Handle(zone); 6907 String& name = String::Handle(zone);
6898 while (i < num_fixed_params) { 6908 while (i < num_fixed_params) {
6899 param_type = ParameterTypeAt(i); 6909 param_type = ParameterTypeAt(i);
6900 ASSERT(!param_type.IsNull()); 6910 ASSERT(!param_type.IsNull());
6901 if (instantiate && param_type.IsFinalized() &&
6902 !param_type.IsInstantiated()) {
6903 param_type = param_type.InstantiateFrom(instantiator, NULL, NULL, NULL,
6904 Heap::kNew);
6905 }
6906 name = param_type.BuildName(name_visibility); 6911 name = param_type.BuildName(name_visibility);
6907 pieces->Add(name); 6912 pieces->Add(name);
6908 if (i != (num_params - 1)) { 6913 if (i != (num_params - 1)) {
6909 pieces->Add(Symbols::CommaSpace()); 6914 pieces->Add(Symbols::CommaSpace());
6910 } 6915 }
6911 i++; 6916 i++;
6912 } 6917 }
6913 if (num_opt_params > 0) { 6918 if (num_opt_params > 0) {
6914 if (num_opt_pos_params > 0) { 6919 if (num_opt_pos_params > 0) {
6915 pieces->Add(Symbols::LBracket()); 6920 pieces->Add(Symbols::LBracket());
6916 } else { 6921 } else {
6917 pieces->Add(Symbols::LBrace()); 6922 pieces->Add(Symbols::LBrace());
6918 } 6923 }
6919 for (intptr_t i = num_fixed_params; i < num_params; i++) { 6924 for (intptr_t i = num_fixed_params; i < num_params; i++) {
6920 param_type = ParameterTypeAt(i); 6925 param_type = ParameterTypeAt(i);
6921 if (instantiate && param_type.IsFinalized() &&
6922 !param_type.IsInstantiated()) {
6923 param_type = param_type.InstantiateFrom(instantiator, NULL, NULL, NULL,
6924 Heap::kNew);
6925 }
6926 ASSERT(!param_type.IsNull()); 6926 ASSERT(!param_type.IsNull());
6927 name = param_type.BuildName(name_visibility); 6927 name = param_type.BuildName(name_visibility);
6928 pieces->Add(name); 6928 pieces->Add(name);
6929 // The parameter name of an optional positional parameter does not need 6929 // The parameter name of an optional positional parameter does not need
6930 // to be part of the signature, since it is not used. 6930 // to be part of the signature, since it is not used.
6931 if (num_opt_named_params > 0) { 6931 if (num_opt_named_params > 0) {
6932 name = ParameterNameAt(i); 6932 name = ParameterNameAt(i);
6933 pieces->Add(Symbols::Blank()); 6933 pieces->Add(Symbols::Blank());
6934 pieces->Add(name); 6934 pieces->Add(name);
6935 } 6935 }
(...skipping 19 matching lines...) Expand all
6955 zone, Closure::New(instantiator, *this, context, Heap::kOld)); 6955 zone, Closure::New(instantiator, *this, context, Heap::kOld));
6956 set_implicit_static_closure(closure); 6956 set_implicit_static_closure(closure);
6957 } 6957 }
6958 return implicit_static_closure(); 6958 return implicit_static_closure();
6959 } 6959 }
6960 6960
6961 6961
6962 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { 6962 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const {
6963 ASSERT(IsImplicitClosureFunction()); 6963 ASSERT(IsImplicitClosureFunction());
6964 Zone* zone = Thread::Current()->zone(); 6964 Zone* zone = Thread::Current()->zone();
6965 const Type& signature_type = Type::Handle(zone, SignatureType());
6966 const Class& cls = Class::Handle(zone, signature_type.type_class());
6967 const Context& context = Context::Handle(zone, Context::New(1)); 6965 const Context& context = Context::Handle(zone, Context::New(1));
6968 context.SetAt(0, receiver); 6966 context.SetAt(0, receiver);
6969 TypeArguments& instantiator = TypeArguments::Handle(zone); 6967 TypeArguments& instantiator = TypeArguments::Handle(zone);
6970 if (cls.IsGeneric()) { 6968 if (!HasInstantiatedSignature(kClass)) {
6971 instantiator = receiver.GetTypeArguments(); 6969 instantiator = receiver.GetTypeArguments();
6972 } 6970 }
6973 return Closure::New(instantiator, *this, context); 6971 return Closure::New(instantiator, *this, context);
6974 } 6972 }
6975 6973
6976 6974
6977 RawSmi* Function::GetClosureHashCode() const { 6975 RawSmi* Function::GetClosureHashCode() const {
6978 ASSERT(IsClosureFunction()); 6976 ASSERT(IsClosureFunction());
6979 const Object& obj = Object::Handle(raw_ptr()->data_); 6977 const Object& obj = Object::Handle(raw_ptr()->data_);
6980 ASSERT(!obj.IsNull()); 6978 ASSERT(!obj.IsNull());
6981 if (ClosureData::Cast(obj).hash() != Object::null()) { 6979 if (ClosureData::Cast(obj).hash() != Object::null()) {
6982 return Smi::RawCast(ClosureData::Cast(obj).hash()); 6980 return Smi::RawCast(ClosureData::Cast(obj).hash());
6983 } 6981 }
6984 // Hash not yet computed. Compute and cache it. 6982 // Hash not yet computed. Compute and cache it.
6985 const Class& cls = Class::Handle(Owner()); 6983 const Class& cls = Class::Handle(Owner());
6986 intptr_t result = String::Handle(name()).Hash(); 6984 intptr_t result = String::Handle(name()).Hash();
6987 result += String::Handle(Signature()).Hash(); 6985 result += String::Handle(Signature()).Hash();
6988 result += String::Handle(cls.Name()).Hash(); 6986 result += String::Handle(cls.Name()).Hash();
6989 // Finalize hash value like for strings so that it fits into a smi. 6987 // Finalize hash value like for strings so that it fits into a smi.
6990 result += result << 3; 6988 result += result << 3;
6991 result ^= result >> 11; 6989 result ^= result >> 11;
6992 result += result << 15; 6990 result += result << 15;
6993 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); 6991 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1);
6994 ClosureData::Cast(obj).set_hash(result); 6992 ClosureData::Cast(obj).set_hash(result);
6995 return Smi::New(result); 6993 return Smi::New(result);
6996 } 6994 }
6997 6995
6998 6996
6999 RawString* Function::BuildSignature(bool instantiate, 6997 RawString* Function::BuildSignature(NameVisibility name_visibility) const {
7000 NameVisibility name_visibility,
7001 const TypeArguments& instantiator) const {
7002 Thread* thread = Thread::Current(); 6998 Thread* thread = Thread::Current();
7003 Zone* zone = thread->zone(); 6999 Zone* zone = thread->zone();
7004 GrowableHandlePtrArray<const String> pieces(zone, 4); 7000 GrowableHandlePtrArray<const String> pieces(zone, 4);
7005 String& name = String::Handle(zone);
7006 if (!instantiate && !is_static() && (name_visibility == kInternalName)) {
7007 // Prefix the signature with its scope class and type parameters, if any
7008 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the
7009 // scope class name is the alias name.
7010 // The signature of static functions cannot be type parameterized.
7011 const Class& scope_class = Class::Handle(zone, Owner());
7012 ASSERT(!scope_class.IsNull());
7013 if (scope_class.IsGeneric()) {
7014 const TypeArguments& type_parameters =
7015 TypeArguments::Handle(zone, scope_class.type_parameters());
7016 const String& scope_class_name = String::Handle(zone, scope_class.Name());
7017 pieces.Add(scope_class_name);
7018 const intptr_t num_type_parameters = type_parameters.Length();
7019 pieces.Add(Symbols::LAngleBracket());
7020 TypeParameter& type_parameter = TypeParameter::Handle(zone);
7021 AbstractType& bound = AbstractType::Handle(zone);
7022 for (intptr_t i = 0; i < num_type_parameters; i++) {
7023 type_parameter ^= type_parameters.TypeAt(i);
7024 name = type_parameter.name();
7025 pieces.Add(name);
7026 bound = type_parameter.bound();
7027 if (!bound.IsNull() && !bound.IsObjectType()) {
7028 pieces.Add(Symbols::SpaceExtendsSpace());
7029 name = bound.BuildName(name_visibility);
7030 pieces.Add(name);
7031 }
7032 if (i < num_type_parameters - 1) {
7033 pieces.Add(Symbols::CommaSpace());
7034 }
7035 }
7036 pieces.Add(Symbols::RAngleBracket());
7037 }
7038 }
7039 pieces.Add(Symbols::LParen()); 7001 pieces.Add(Symbols::LParen());
7040 BuildSignatureParameters(thread, zone, instantiate, name_visibility, 7002 BuildSignatureParameters(thread, zone, name_visibility, &pieces);
7041 instantiator, &pieces);
7042 pieces.Add(Symbols::RParenArrow()); 7003 pieces.Add(Symbols::RParenArrow());
7043 AbstractType& res_type = AbstractType::Handle(zone, result_type()); 7004 const AbstractType& res_type = AbstractType::Handle(zone, result_type());
7044 if (instantiate && res_type.IsFinalized() && !res_type.IsInstantiated()) { 7005 const String& name =
7045 res_type = 7006 String::Handle(zone, res_type.BuildName(name_visibility));
7046 res_type.InstantiateFrom(instantiator, NULL, NULL, NULL, Heap::kNew);
7047 }
7048 name = res_type.BuildName(name_visibility);
7049 pieces.Add(name); 7007 pieces.Add(name);
7050 return Symbols::FromConcatAll(thread, pieces); 7008 return Symbols::FromConcatAll(thread, pieces);
7051 } 7009 }
7052 7010
7053 7011
7054 bool Function::HasInstantiatedSignature() const { 7012 bool Function::HasInstantiatedSignature(Genericity genericity,
7013 TrailPtr trail) const {
7055 AbstractType& type = AbstractType::Handle(result_type()); 7014 AbstractType& type = AbstractType::Handle(result_type());
7056 if (!type.IsInstantiated()) { 7015 if (!type.IsInstantiated(genericity, trail)) {
7057 return false; 7016 return false;
7058 } 7017 }
7059 const intptr_t num_parameters = NumParameters(); 7018 const intptr_t num_parameters = NumParameters();
7060 for (intptr_t i = 0; i < num_parameters; i++) { 7019 for (intptr_t i = 0; i < num_parameters; i++) {
7061 type = ParameterTypeAt(i); 7020 type = ParameterTypeAt(i);
7062 if (!type.IsInstantiated()) { 7021 if (!type.IsInstantiated(genericity, trail)) {
7063 return false; 7022 return false;
7064 } 7023 }
7065 } 7024 }
7066 return true; 7025 return true;
7067 } 7026 }
7068 7027
7069 7028
7070 RawClass* Function::Owner() const { 7029 RawClass* Function::Owner() const {
7071 if (raw_ptr()->owner_ == Object::null()) { 7030 if (raw_ptr()->owner_ == Object::null()) {
7072 ASSERT(IsSignatureFunction()); 7031 ASSERT(IsSignatureFunction());
(...skipping 8589 matching lines...) Expand 10 before | Expand all | Expand 10 after
15662 15621
15663 RawAbstractType* Instance::GetType(Heap::Space space) const { 15622 RawAbstractType* Instance::GetType(Heap::Space space) const {
15664 if (IsNull()) { 15623 if (IsNull()) {
15665 return Type::NullType(); 15624 return Type::NullType();
15666 } 15625 }
15667 const Class& cls = Class::Handle(clazz()); 15626 const Class& cls = Class::Handle(clazz());
15668 if (cls.IsClosureClass()) { 15627 if (cls.IsClosureClass()) {
15669 const Function& signature = 15628 const Function& signature =
15670 Function::Handle(Closure::Cast(*this).function()); 15629 Function::Handle(Closure::Cast(*this).function());
15671 Type& type = Type::Handle(signature.SignatureType()); 15630 Type& type = Type::Handle(signature.SignatureType());
15672 if (type.type_class() == cls.raw()) { 15631 if (!type.IsInstantiated()) {
15673 // Type is not parameterized. 15632 TypeArguments& instantiator_type_arguments =
15674 if (!type.IsCanonical()) { 15633 TypeArguments::Handle(Closure::Cast(*this).instantiator());
15675 type ^= type.Canonicalize(); 15634 // TODO(regis): Should we pass the context explicitly here (i.e. null)
15676 signature.SetSignatureType(type); 15635 // once we support generic functions?
15677 } 15636 type ^= type.InstantiateFrom(instantiator_type_arguments, NULL, NULL,
15678 return type.raw(); 15637 NULL, space);
15679 } 15638 }
15680 const Class& scope_cls = Class::Handle(type.type_class());
15681 ASSERT(scope_cls.NumTypeArguments() > 0);
15682 TypeArguments& type_arguments =
15683 TypeArguments::Handle(Closure::Cast(*this).instantiator());
15684 type =
15685 Type::New(scope_cls, type_arguments, TokenPosition::kNoSource, space);
15686 type.set_signature(signature);
15687 type.SetIsFinalized();
15688 type ^= type.Canonicalize(); 15639 type ^= type.Canonicalize();
15689 return type.raw(); 15640 return type.raw();
15690 } 15641 }
15691 Type& type = Type::Handle(); 15642 Type& type = Type::Handle();
15692 if (!cls.IsGeneric()) { 15643 if (!cls.IsGeneric()) {
15693 type = cls.CanonicalType(); 15644 type = cls.CanonicalType();
15694 } 15645 }
15695 if (type.IsNull()) { 15646 if (type.IsNull()) {
15696 TypeArguments& type_arguments = TypeArguments::Handle(); 15647 TypeArguments& type_arguments = TypeArguments::Handle();
15697 if (cls.NumTypeArguments() > 0) { 15648 if (cls.NumTypeArguments() > 0) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
15735 if (other.IsVoidType()) { 15686 if (other.IsVoidType()) {
15736 return false; 15687 return false;
15737 } 15688 }
15738 Zone* zone = Thread::Current()->zone(); 15689 Zone* zone = Thread::Current()->zone();
15739 const Class& cls = Class::Handle(zone, clazz()); 15690 const Class& cls = Class::Handle(zone, clazz());
15740 if (cls.IsClosureClass()) { 15691 if (cls.IsClosureClass()) {
15741 if (other.IsObjectType() || other.IsDartFunctionType() || 15692 if (other.IsObjectType() || other.IsDartFunctionType() ||
15742 other.IsDartClosureType()) { 15693 other.IsDartClosureType()) {
15743 return true; 15694 return true;
15744 } 15695 }
15745 Function& other_signature = Function::Handle(zone); 15696 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw());
15746 TypeArguments& other_type_arguments = TypeArguments::Handle(zone);
15747 // Note that we may encounter a bound error in checked mode. 15697 // Note that we may encounter a bound error in checked mode.
15748 if (!other.IsInstantiated()) { 15698 if (!other.IsInstantiated()) {
15749 AbstractType& instantiated_other = AbstractType::Handle( 15699 instantiated_other = other.InstantiateFrom(
15750 zone, other.InstantiateFrom(other_instantiator, bound_error, NULL, 15700 other_instantiator, bound_error, NULL, NULL, Heap::kOld);
15751 NULL, Heap::kOld));
15752 if ((bound_error != NULL) && !bound_error->IsNull()) { 15701 if ((bound_error != NULL) && !bound_error->IsNull()) {
15753 ASSERT(Isolate::Current()->type_checks()); 15702 ASSERT(Isolate::Current()->type_checks());
15754 return false; 15703 return false;
15755 } 15704 }
15756 if (instantiated_other.IsTypeRef()) { 15705 if (instantiated_other.IsTypeRef()) {
15757 instantiated_other = TypeRef::Cast(instantiated_other).type(); 15706 instantiated_other = TypeRef::Cast(instantiated_other).type();
15758 } 15707 }
15759 if (instantiated_other.IsDynamicType() || 15708 if (instantiated_other.IsDynamicType() ||
15760 instantiated_other.IsObjectType() || 15709 instantiated_other.IsObjectType() ||
15761 instantiated_other.IsDartFunctionType()) { 15710 instantiated_other.IsDartFunctionType()) {
15762 return true; 15711 return true;
15763 } 15712 }
15764 if (!instantiated_other.IsFunctionType()) {
15765 return false;
15766 }
15767 other_signature = Type::Cast(instantiated_other).signature();
15768 other_type_arguments = instantiated_other.arguments();
15769 } else {
15770 if (!other.IsFunctionType()) {
15771 return false;
15772 }
15773 other_signature = Type::Cast(other).signature();
15774 other_type_arguments = other.arguments();
15775 } 15713 }
15776 const Function& signature = 15714 if (!instantiated_other.IsFunctionType()) {
15777 Function::Handle(zone, Closure::Cast(*this).function()); 15715 return false;
15778 const TypeArguments& type_arguments = 15716 }
15779 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator()); 15717 Function& other_signature =
15780 // TODO(regis): If signature function is generic, pass its type parameters 15718 Function::Handle(zone, Type::Cast(instantiated_other).signature());
15781 // as function instantiator, otherwise pass null. 15719 Function& sig_fun = Function::Handle(zone, Closure::Cast(*this).function());
15782 // Pass the closure context as well to the the IsSubtypeOf call. 15720 if (!sig_fun.HasInstantiatedSignature()) {
15783 return signature.IsSubtypeOf(type_arguments, other_signature, 15721 const TypeArguments& instantiator_type_arguments =
15784 other_type_arguments, bound_error, Heap::kOld); 15722 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator());
15723 // TODO(regis): If sig_fun is generic, pass its type parameters
15724 // as function instantiator, otherwise pass null.
15725 // Pass the closure context as well to InstantiateSignatureFrom().
15726 // No bound error possible, since the instance exists.
15727 sig_fun = sig_fun.InstantiateSignatureFrom(instantiator_type_arguments,
15728 Heap::kOld);
15729 }
15730 return sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld);
15785 } 15731 }
15786 TypeArguments& type_arguments = TypeArguments::Handle(zone); 15732 TypeArguments& type_arguments = TypeArguments::Handle(zone);
15787 if (cls.NumTypeArguments() > 0) { 15733 if (cls.NumTypeArguments() > 0) {
15788 type_arguments = GetTypeArguments(); 15734 type_arguments = GetTypeArguments();
15789 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); 15735 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical());
15790 // The number of type arguments in the instance must be greater or equal to 15736 // The number of type arguments in the instance must be greater or equal to
15791 // the number of type arguments expected by the instance class. 15737 // the number of type arguments expected by the instance class.
15792 // A discrepancy is allowed for closures, which borrow the type argument 15738 // A discrepancy is allowed for closures, which borrow the type argument
15793 // vector of their instantiator, which may be of a subclass of the class 15739 // vector of their instantiator, which may be of a subclass of the class
15794 // defining the closure. Truncating the vector to the correct length on 15740 // defining the closure. Truncating the vector to the correct length on
(...skipping 18 matching lines...) Expand all
15813 instantiated_other = TypeRef::Cast(instantiated_other).type(); 15759 instantiated_other = TypeRef::Cast(instantiated_other).type();
15814 } 15760 }
15815 if (instantiated_other.IsDynamicType()) { 15761 if (instantiated_other.IsDynamicType()) {
15816 return true; 15762 return true;
15817 } 15763 }
15818 } 15764 }
15819 other_type_arguments = instantiated_other.arguments(); 15765 other_type_arguments = instantiated_other.arguments();
15820 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); 15766 const bool other_is_dart_function = instantiated_other.IsDartFunctionType();
15821 if (other_is_dart_function || instantiated_other.IsFunctionType()) { 15767 if (other_is_dart_function || instantiated_other.IsFunctionType()) {
15822 // Check if this instance understands a call() method of a compatible type. 15768 // Check if this instance understands a call() method of a compatible type.
15823 const Function& call_function = 15769 Function& sig_fun =
15824 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); 15770 Function::Handle(zone, cls.LookupCallFunctionForTypeTest());
15825 if (!call_function.IsNull()) { 15771 if (!sig_fun.IsNull()) {
15826 if (other_is_dart_function) { 15772 if (other_is_dart_function) {
15827 return true; 15773 return true;
15828 } 15774 }
15775 if (!sig_fun.HasInstantiatedSignature()) {
15776 // TODO(regis): If sig_fun is generic, pass its type parameters
15777 // as function instantiator, otherwise pass null.
15778 // Pass the closure context as well to InstantiateSignatureFrom().
15779 // No bound error possible, since the instance exists.
15780 sig_fun = sig_fun.InstantiateSignatureFrom(type_arguments, Heap::kOld);
15781 }
15829 const Function& other_signature = 15782 const Function& other_signature =
15830 Function::Handle(zone, Type::Cast(instantiated_other).signature()); 15783 Function::Handle(zone, Type::Cast(instantiated_other).signature());
15831 if (call_function.IsSubtypeOf(type_arguments, other_signature, 15784 if (sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld)) {
15832 other_type_arguments, bound_error,
15833 Heap::kOld)) {
15834 return true; 15785 return true;
15835 } 15786 }
15836 } 15787 }
15837 } 15788 }
15838 if (!instantiated_other.IsType()) { 15789 if (!instantiated_other.IsType()) {
15839 return false; 15790 return false;
15840 } 15791 }
15841 other_class = instantiated_other.type_class(); 15792 other_class = instantiated_other.type_class();
15842 if (IsNull()) { 15793 if (IsNull()) {
15843 ASSERT(cls.IsNullClass()); 15794 ASSERT(cls.IsNullClass());
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
16332 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); 16283 const TypeArguments& args = TypeArguments::Handle(zone, arguments());
16333 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); 16284 const intptr_t num_args = args.IsNull() ? 0 : args.Length();
16334 String& class_name = String::Handle(zone); 16285 String& class_name = String::Handle(zone);
16335 intptr_t first_type_param_index; 16286 intptr_t first_type_param_index;
16336 intptr_t num_type_params; // Number of type parameters to print. 16287 intptr_t num_type_params; // Number of type parameters to print.
16337 Class& cls = Class::Handle(zone); 16288 Class& cls = Class::Handle(zone);
16338 if (IsFunctionType()) { 16289 if (IsFunctionType()) {
16339 cls = type_class(); 16290 cls = type_class();
16340 const Function& signature_function = 16291 const Function& signature_function =
16341 Function::Handle(zone, Type::Cast(*this).signature()); 16292 Function::Handle(zone, Type::Cast(*this).signature());
16342 if (!cls.IsTypedefClass() || 16293 if (!cls.IsTypedefClass()) {
16343 (cls.signature_function() != signature_function.raw())) { 16294 return signature_function.UserVisibleSignature();
16344 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
16345 return signature_function.UserVisibleSignature();
16346 }
16347 return signature_function.InstantiatedSignatureFrom(args,
16348 name_visibility);
16349 } 16295 }
16296 // Instead of printing the actual signature, use the typedef name with
16297 // its type arguments, if any.
16350 class_name = cls.Name(); // Typedef name. 16298 class_name = cls.Name(); // Typedef name.
16351 // We may be reporting an error about a malformed function type. In that 16299 // We may be reporting an error about a malformed function type. In that
16352 // case, avoid instantiating the signature, since it may cause divergence. 16300 // case, avoid instantiating the signature, since it may cause divergence.
16353 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { 16301 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
16354 return class_name.raw(); 16302 return class_name.raw();
16355 } 16303 }
16356 // Print the name of a typedef as a regular, possibly parameterized, class. 16304 // Print the name of a typedef as a regular, possibly parameterized, class.
16357 } else if (HasResolvedTypeClass()) { 16305 } else if (HasResolvedTypeClass()) {
16358 cls = type_class(); 16306 cls = type_class();
16359 } 16307 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
16626 if (other_is_dart_function_type || other.IsFunctionType()) { 16574 if (other_is_dart_function_type || other.IsFunctionType()) {
16627 if (IsFunctionType()) { 16575 if (IsFunctionType()) {
16628 if (other_is_dart_function_type) { 16576 if (other_is_dart_function_type) {
16629 return true; 16577 return true;
16630 } 16578 }
16631 const Function& other_fun = 16579 const Function& other_fun =
16632 Function::Handle(zone, Type::Cast(other).signature()); 16580 Function::Handle(zone, Type::Cast(other).signature());
16633 // Check for two function types. 16581 // Check for two function types.
16634 const Function& fun = 16582 const Function& fun =
16635 Function::Handle(zone, Type::Cast(*this).signature()); 16583 Function::Handle(zone, Type::Cast(*this).signature());
16636 return fun.TypeTest( 16584 return fun.TypeTest(test_kind, other_fun, bound_error, space);
16637 test_kind, TypeArguments::Handle(zone, arguments()), other_fun,
16638 TypeArguments::Handle(zone, other.arguments()), bound_error, space);
16639 } 16585 }
16640 // Check if type S has a call() method of function type T. 16586 // Check if type S has a call() method of function type T.
16641 const Function& call_function = 16587 const Function& call_function =
16642 Function::Handle(zone, type_cls.LookupCallFunctionForTypeTest()); 16588 Function::Handle(zone, type_cls.LookupCallFunctionForTypeTest());
16643 if (!call_function.IsNull()) { 16589 if (!call_function.IsNull()) {
16644 if (other_is_dart_function_type || 16590 if (other_is_dart_function_type ||
16645 call_function.TypeTest( 16591 call_function.TypeTest(
16646 test_kind, TypeArguments::Handle(zone, arguments()), 16592 test_kind, Function::Handle(zone, Type::Cast(other).signature()),
16647 Function::Handle(zone, Type::Cast(other).signature()), 16593 bound_error, space)) {
16648 TypeArguments::Handle(zone, other.arguments()), bound_error,
16649 space)) {
16650 return true; 16594 return true;
16651 } 16595 }
16652 } 16596 }
16653 } 16597 }
16654 if (IsFunctionType()) { 16598 if (IsFunctionType()) {
16655 return false; 16599 return false;
16656 } 16600 }
16657 return type_cls.TypeTest(test_kind, TypeArguments::Handle(zone, arguments()), 16601 return type_cls.TypeTest(test_kind, TypeArguments::Handle(zone, arguments()),
16658 Class::Handle(zone, other.type_class()), 16602 Class::Handle(zone, other.type_class()),
16659 TypeArguments::Handle(zone, other.arguments()), 16603 TypeArguments::Handle(zone, other.arguments()),
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
16915 16859
16916 16860
16917 bool Type::IsInstantiated(Genericity genericity, TrailPtr trail) const { 16861 bool Type::IsInstantiated(Genericity genericity, TrailPtr trail) const {
16918 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { 16862 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) {
16919 return true; 16863 return true;
16920 } 16864 }
16921 if ((genericity == kAny) && 16865 if ((genericity == kAny) &&
16922 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated)) { 16866 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated)) {
16923 return false; 16867 return false;
16924 } 16868 }
16869 if (IsFunctionType()) {
16870 const Function& sig_fun = Function::Handle(signature());
16871 if (!sig_fun.HasInstantiatedSignature(genericity, trail)) {
16872 return false;
16873 }
16874 // Because a generic typedef with an instantiated signature is considered
16875 // uninstantiated, we still need to check the type arguments, even if the
16876 // signature is instantiated.
16877 }
16925 if (arguments() == TypeArguments::null()) { 16878 if (arguments() == TypeArguments::null()) {
16926 return true; 16879 return true;
16927 } 16880 }
16928 const TypeArguments& args = TypeArguments::Handle(arguments()); 16881 const TypeArguments& args = TypeArguments::Handle(arguments());
16929 intptr_t num_type_args = args.Length(); 16882 intptr_t num_type_args = args.Length();
16930 intptr_t len = num_type_args; // Check the full vector of type args. 16883 intptr_t len = num_type_args; // Check the full vector of type args.
16931 ASSERT(num_type_args > 0); 16884 ASSERT(num_type_args > 0);
16932 // This type is not instantiated if it refers to type parameters. 16885 // This type is not instantiated if it refers to type parameters.
16933 // Although this type may still be unresolved, the type parameters it may 16886 // Although this type may still be unresolved, the type parameters it may
16934 // refer to are resolved by definition. We can therefore return the correct 16887 // refer to are resolved by definition. We can therefore return the correct
(...skipping 20 matching lines...) Expand all
16955 ASSERT(!IsInstantiated()); 16908 ASSERT(!IsInstantiated());
16956 // Return the uninstantiated type unchanged if malformed. No copy needed. 16909 // Return the uninstantiated type unchanged if malformed. No copy needed.
16957 if (IsMalformed()) { 16910 if (IsMalformed()) {
16958 return raw(); 16911 return raw();
16959 } 16912 }
16960 // Note that the type class has to be resolved at this time, but not 16913 // Note that the type class has to be resolved at this time, but not
16961 // necessarily finalized yet. We may be checking bounds at compile time or 16914 // necessarily finalized yet. We may be checking bounds at compile time or
16962 // finalizing the type argument vector of a recursive type. 16915 // finalizing the type argument vector of a recursive type.
16963 const Class& cls = Class::Handle(zone, type_class()); 16916 const Class& cls = Class::Handle(zone, type_class());
16964 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); 16917 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments());
16965 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); 16918 Function& sig_fun = Function::Handle(zone, signature());
16966 type_arguments = 16919 if (!type_arguments.IsNull() &&
16967 type_arguments.InstantiateFrom(instantiator_type_arguments, bound_error, 16920 (sig_fun.IsNull() || !type_arguments.IsInstantiated())) {
16968 instantiation_trail, bound_trail, space); 16921 // This type is uninstantiated because either its type arguments or its
16922 // signature, or both are uninstantiated.
16923 // Note that the type arguments of a function type merely document the
16924 // parameterization of a generic typedef. They are otherwise ignored.
16925 ASSERT(type_arguments.Length() == cls.NumTypeArguments());
16926 type_arguments =
16927 type_arguments.InstantiateFrom(instantiator_type_arguments, bound_error,
16928 instantiation_trail, bound_trail, space);
16929 }
16969 // This uninstantiated type is not modified, as it can be instantiated 16930 // This uninstantiated type is not modified, as it can be instantiated
16970 // with different instantiators. Allocate a new instantiated version of it. 16931 // with different instantiators. Allocate a new instantiated version of it.
16971 const Type& instantiated_type = 16932 const Type& instantiated_type =
16972 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); 16933 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space));
16973 // Preserve the bound error if any. 16934 // Preserve the bound error if any.
16974 if (IsMalbounded()) { 16935 if (IsMalbounded()) {
16975 const LanguageError& bound_error = LanguageError::Handle(zone, error()); 16936 const LanguageError& bound_error = LanguageError::Handle(zone, error());
16976 instantiated_type.set_error(bound_error); 16937 instantiated_type.set_error(bound_error);
16977 } 16938 }
16978 // Preserve the signature if this type represents a function type. 16939 // If this type is a function type, instantiate its signature.
16979 // Note that the types in the signature remain unchanged. They get indirectly
16980 // instantiated by instantiating the type arguments above.
16981 const Function& sig_fun = Function::Handle(zone, signature());
16982 if (!sig_fun.IsNull()) { 16940 if (!sig_fun.IsNull()) {
16941 // If we are finalizing a typedef, do not yet instantiate its signature.
16942 // Other function types should never be instantiated while unfinalized.
16943 if (IsFinalized()) {
16944 // A generic typedef may actually declare an instantiated signature.
16945 if (!sig_fun.HasInstantiatedSignature()) {
16946 sig_fun = sig_fun.InstantiateSignatureFrom(instantiator_type_arguments,
16947 space);
16948 }
16949 } else {
16950 ASSERT(cls.IsTypedefClass());
16951 }
16983 instantiated_type.set_signature(sig_fun); 16952 instantiated_type.set_signature(sig_fun);
16984 } 16953 }
16985 if (IsFinalized()) { 16954 if (IsFinalized()) {
16986 instantiated_type.SetIsFinalized(); 16955 instantiated_type.SetIsFinalized();
16987 } else { 16956 } else {
16988 instantiated_type.SetIsResolved(); 16957 instantiated_type.SetIsResolved();
16989 if (IsBeingFinalized()) { 16958 if (IsBeingFinalized()) {
16990 instantiated_type.SetIsBeingFinalized(); 16959 instantiated_type.SetIsBeingFinalized();
16991 } 16960 }
16992 } 16961 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
17224 if (!clone.IsNull()) { 17193 if (!clone.IsNull()) {
17225 return clone.raw(); 17194 return clone.raw();
17226 } 17195 }
17227 const Class& type_cls = Class::Handle(zone, type_class()); 17196 const Class& type_cls = Class::Handle(zone, type_class());
17228 clone = Type::New(type_cls, TypeArguments::Handle(zone), token_pos()); 17197 clone = Type::New(type_cls, TypeArguments::Handle(zone), token_pos());
17229 // Preserve the bound error if any. 17198 // Preserve the bound error if any.
17230 if (IsMalbounded()) { 17199 if (IsMalbounded()) {
17231 const LanguageError& bound_error = LanguageError::Handle(zone, error()); 17200 const LanguageError& bound_error = LanguageError::Handle(zone, error());
17232 clone.set_error(bound_error); 17201 clone.set_error(bound_error);
17233 } 17202 }
17234 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
17235 bool type_args_cloned = false;
17236 // Clone the signature if this type represents a function type. 17203 // Clone the signature if this type represents a function type.
17237 const Function& fun = Function::Handle(zone, signature()); 17204 const Function& fun = Function::Handle(zone, signature());
17238 if (!fun.IsNull()) { 17205 if (!fun.IsNull()) {
17206 ASSERT(type_cls.IsTypedefClass() || type_cls.IsClosureClass());
17239 // If the scope class is not a typedef and if it is generic, it must be the 17207 // If the scope class is not a typedef and if it is generic, it must be the
17240 // mixin class, set it to the new owner. 17208 // mixin class, set it to the new owner.
17241 if (!type_cls.IsTypedefClass() && type_cls.IsGeneric()) {
17242 clone.set_type_class(new_owner);
17243 AbstractType& decl_type = AbstractType::Handle(zone);
17244 #ifdef DEBUG
17245 decl_type = type_cls.DeclarationType();
17246 ASSERT(decl_type.IsFinalized());
17247 const TypeArguments& decl_type_args =
17248 TypeArguments::Handle(zone, decl_type.arguments());
17249 ASSERT(type_args.Equals(decl_type_args));
17250 #endif // DEBUG
17251 decl_type = new_owner.DeclarationType();
17252 ASSERT(decl_type.IsFinalized());
17253 type_args = decl_type.arguments();
17254 clone.set_arguments(type_args);
17255 type_args_cloned = true;
17256 }
17257 Function& fun_clone = Function::Handle( 17209 Function& fun_clone = Function::Handle(
17258 zone, 17210 zone,
17259 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource)); 17211 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource));
17260 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); 17212 AbstractType& type = AbstractType::Handle(zone, fun.result_type());
17261 type = type.CloneUninstantiated(new_owner, trail); 17213 type = type.CloneUninstantiated(new_owner, trail);
17262 fun_clone.set_result_type(type); 17214 fun_clone.set_result_type(type);
17263 const intptr_t num_params = fun.NumParameters(); 17215 const intptr_t num_params = fun.NumParameters();
17264 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); 17216 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters());
17265 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), 17217 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(),
17266 fun.HasOptionalPositionalParameters()); 17218 fun.HasOptionalPositionalParameters());
17267 fun_clone.set_parameter_types( 17219 fun_clone.set_parameter_types(
17268 Array::Handle(Array::New(num_params, Heap::kOld))); 17220 Array::Handle(Array::New(num_params, Heap::kOld)));
17269 for (intptr_t i = 0; i < num_params; i++) { 17221 for (intptr_t i = 0; i < num_params; i++) {
17270 type = fun.ParameterTypeAt(i); 17222 type = fun.ParameterTypeAt(i);
17271 type = type.CloneUninstantiated(new_owner, trail); 17223 type = type.CloneUninstantiated(new_owner, trail);
17272 fun_clone.SetParameterTypeAt(i, type); 17224 fun_clone.SetParameterTypeAt(i, type);
17273 } 17225 }
17274 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); 17226 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
17275 clone.set_signature(fun_clone); 17227 clone.set_signature(fun_clone);
17276 } 17228 }
17277 if (!type_args_cloned) { 17229 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
17230 if (!type_args.IsNull()) {
17278 // Upper bounds of uninstantiated type arguments may form a cycle. 17231 // Upper bounds of uninstantiated type arguments may form a cycle.
17279 if (type_args.IsRecursive() || !type_args.IsInstantiated()) { 17232 if (type_args.IsRecursive() || !type_args.IsInstantiated()) {
17280 AddOnlyBuddyToTrail(&trail, clone); 17233 AddOnlyBuddyToTrail(&trail, clone);
17281 } 17234 }
17282 type_args = type_args.CloneUninstantiated(new_owner, trail); 17235 type_args = type_args.CloneUninstantiated(new_owner, trail);
17283 clone.set_arguments(type_args); 17236 clone.set_arguments(type_args);
17284 } 17237 }
17285 clone.SetIsFinalized(); 17238 clone.SetIsFinalized();
17286 clone ^= clone.Canonicalize(); 17239 clone ^= clone.Canonicalize();
17287 return clone.raw(); 17240 return clone.raw();
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
17595 Class& cls = Class::Handle(zone); 17548 Class& cls = Class::Handle(zone);
17596 const char* class_name; 17549 const char* class_name;
17597 if (HasResolvedTypeClass()) { 17550 if (HasResolvedTypeClass()) {
17598 cls = type_class(); 17551 cls = type_class();
17599 class_name = String::Handle(zone, cls.Name()).ToCString(); 17552 class_name = String::Handle(zone, cls.Name()).ToCString();
17600 } else { 17553 } else {
17601 class_name = UnresolvedClass::Handle(zone, unresolved_class()).ToCString(); 17554 class_name = UnresolvedClass::Handle(zone, unresolved_class()).ToCString();
17602 } 17555 }
17603 if (IsFunctionType()) { 17556 if (IsFunctionType()) {
17604 const Function& sig_fun = Function::Handle(zone, signature()); 17557 const Function& sig_fun = Function::Handle(zone, signature());
17605 const String& sig = 17558 const String& sig = String::Handle(zone, sig_fun.Signature());
17606 IsFinalized() ? String::Handle(zone, sig_fun.InstantiatedSignatureFrom(
17607 type_args, kInternalName))
17608 : String::Handle(zone, sig_fun.Signature());
17609 if (cls.IsClosureClass()) { 17559 if (cls.IsClosureClass()) {
17610 ASSERT(type_args.IsNull()); 17560 ASSERT(type_args.IsNull());
17611 return OS::SCreate(zone, "%sFunction Type: %s", unresolved, 17561 return OS::SCreate(zone, "%sFunction Type: %s", unresolved,
17612 sig.ToCString()); 17562 sig.ToCString());
17613 } 17563 }
17614 return OS::SCreate(zone, "%s Function Type: %s (class: %s, args: %s)", 17564 return OS::SCreate(zone, "%s Function Type: %s (class: %s, args: %s)",
17615 unresolved, sig.ToCString(), class_name, args_cstr); 17565 unresolved, sig.ToCString(), class_name, args_cstr);
17616 } 17566 }
17617 if (type_args.IsNull()) { 17567 if (type_args.IsNull()) {
17618 return OS::SCreate(zone, "%sType: class '%s'", unresolved, class_name); 17568 return OS::SCreate(zone, "%sType: class '%s'", unresolved, class_name);
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
18263 if (!instantiated_bounded_type.IsFinalized() || 18213 if (!instantiated_bounded_type.IsFinalized() ||
18264 !instantiated_upper_bound.IsFinalized() || 18214 !instantiated_upper_bound.IsFinalized() ||
18265 (!type_param.CheckBound(instantiated_bounded_type, 18215 (!type_param.CheckBound(instantiated_bounded_type,
18266 instantiated_upper_bound, bound_error, 18216 instantiated_upper_bound, bound_error,
18267 bound_trail, space) && 18217 bound_trail, space) &&
18268 bound_error->IsNull())) { 18218 bound_error->IsNull())) {
18269 // We cannot determine yet whether the bounded_type is below the 18219 // We cannot determine yet whether the bounded_type is below the
18270 // upper_bound, because one or both of them is still being finalized or 18220 // upper_bound, because one or both of them is still being finalized or
18271 // uninstantiated. For example, instantiated_bounded_type may be the 18221 // uninstantiated. For example, instantiated_bounded_type may be the
18272 // still unfinalized cloned type parameter of a mixin application class. 18222 // still unfinalized cloned type parameter of a mixin application class.
18223 // There is another special case where we do not want to report a bound
18224 // error yet: if the upper bound is a function type, but the bounded
18225 // type is not and its class is not compiled yet, i.e. we cannot look
18226 // for a call method yet.
18273 ASSERT(instantiated_bounded_type.IsBeingFinalized() || 18227 ASSERT(instantiated_bounded_type.IsBeingFinalized() ||
18274 instantiated_upper_bound.IsBeingFinalized() || 18228 instantiated_upper_bound.IsBeingFinalized() ||
18275 !instantiated_bounded_type.IsInstantiated() || 18229 !instantiated_bounded_type.IsInstantiated() ||
18276 !instantiated_upper_bound.IsInstantiated()); 18230 !instantiated_upper_bound.IsInstantiated() ||
18231 (!instantiated_bounded_type.IsFunctionType() &&
18232 instantiated_upper_bound.IsFunctionType() &&
18233 instantiated_bounded_type.HasResolvedTypeClass() &&
18234 !Class::Handle(instantiated_bounded_type.type_class())
18235 .is_finalized()));
18277 // Postpone bound check by returning a new BoundedType with unfinalized 18236 // Postpone bound check by returning a new BoundedType with unfinalized
18278 // or partially instantiated bounded_type and upper_bound, but keeping 18237 // or partially instantiated bounded_type and upper_bound, but keeping
18279 // type_param. 18238 // type_param.
18280 instantiated_bounded_type = BoundedType::New( 18239 instantiated_bounded_type = BoundedType::New(
18281 instantiated_bounded_type, instantiated_upper_bound, type_param); 18240 instantiated_bounded_type, instantiated_upper_bound, type_param);
18282 } 18241 }
18283 } 18242 }
18284 } 18243 }
18285 return instantiated_bounded_type.raw(); 18244 return instantiated_bounded_type.raw();
18286 } 18245 }
(...skipping 4844 matching lines...) Expand 10 before | Expand all | Expand 10 after
23131 return UserTag::null(); 23090 return UserTag::null();
23132 } 23091 }
23133 23092
23134 23093
23135 const char* UserTag::ToCString() const { 23094 const char* UserTag::ToCString() const {
23136 const String& tag_label = String::Handle(label()); 23095 const String& tag_label = String::Handle(label());
23137 return tag_label.ToCString(); 23096 return tag_label.ToCString();
23138 } 23097 }
23139 23098
23140 } // namespace dart 23099 } // namespace dart
OLDNEW
« runtime/vm/class_finalizer.cc ('K') | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698