OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6377 return chars; | 6374 return chars; |
6378 } | 6375 } |
6379 | 6376 |
6380 | 6377 |
6381 bool Function::HasCompatibleParametersWith(const Function& other, | 6378 bool Function::HasCompatibleParametersWith(const Function& other, |
6382 Error* bound_error) const { | 6379 Error* bound_error) const { |
6383 ASSERT(Isolate::Current()->error_on_bad_override()); | 6380 ASSERT(Isolate::Current()->error_on_bad_override()); |
6384 ASSERT((bound_error != NULL) && bound_error->IsNull()); | 6381 ASSERT((bound_error != NULL) && bound_error->IsNull()); |
6385 // Check that this function's signature type is a subtype of the other | 6382 // Check that this function's signature type is a subtype of the other |
6386 // function's signature type. | 6383 // function's signature type. |
6387 if (!TypeTest(kIsSubtypeOf, Object::null_type_arguments(), other, | 6384 // Map type parameters in the signature to dynamic before the test. |
6388 Object::null_type_arguments(), bound_error, Heap::kOld)) { | 6385 Function& this_fun = Function::Handle(raw()); |
| 6386 if (!this_fun.HasInstantiatedSignature()) { |
| 6387 // TODO(regis): Should we pass the context explicitly here (i.e. null) once |
| 6388 // we support generic functions? |
| 6389 this_fun = this_fun.InstantiateSignatureFrom(Object::null_type_arguments(), |
| 6390 Heap::kOld); |
| 6391 } |
| 6392 Function& other_fun = Function::Handle(other.raw()); |
| 6393 if (!other_fun.HasInstantiatedSignature()) { |
| 6394 // TODO(regis): Should we pass the context explicitly here (i.e. null) once |
| 6395 // we support generic functions? |
| 6396 other_fun = other_fun.InstantiateSignatureFrom( |
| 6397 Object::null_type_arguments(), Heap::kOld); |
| 6398 } |
| 6399 if (!this_fun.TypeTest(kIsSubtypeOf, other_fun, bound_error, Heap::kOld)) { |
6389 // For more informative error reporting, use the location of the other | 6400 // For more informative error reporting, use the location of the other |
6390 // function here, since the caller will use the location of this function. | 6401 // function here, since the caller will use the location of this function. |
6391 *bound_error = LanguageError::NewFormatted( | 6402 *bound_error = LanguageError::NewFormatted( |
6392 *bound_error, // A bound error if non null. | 6403 *bound_error, // A bound error if non null. |
6393 Script::Handle(other.script()), other.token_pos(), Report::AtLocation, | 6404 Script::Handle(other.script()), other.token_pos(), Report::AtLocation, |
6394 Report::kError, Heap::kNew, | 6405 Report::kError, Heap::kNew, |
6395 "signature type '%s' of function '%s' is not a subtype of signature " | 6406 "signature type '%s' of function '%s' is not a subtype of signature " |
6396 "type '%s' of function '%s' where\n%s%s", | 6407 "type '%s' of function '%s'\n", |
6397 String::Handle(UserVisibleSignature()).ToCString(), | 6408 String::Handle(UserVisibleSignature()).ToCString(), |
6398 String::Handle(UserVisibleName()).ToCString(), | 6409 String::Handle(UserVisibleName()).ToCString(), |
6399 String::Handle(other.UserVisibleSignature()).ToCString(), | 6410 String::Handle(other.UserVisibleSignature()).ToCString(), |
6400 String::Handle(other.UserVisibleName()).ToCString(), | 6411 String::Handle(other.UserVisibleName()).ToCString()); |
6401 String::Handle(Type::Handle(SignatureType()).EnumerateURIs()) | |
6402 .ToCString(), | |
6403 String::Handle(Type::Handle(other.SignatureType()).EnumerateURIs()) | |
6404 .ToCString()); | |
6405 return false; | 6412 return false; |
6406 } | 6413 } |
6407 // We should also check that if the other function explicitly specifies a | 6414 // We should also check that if the other function explicitly specifies a |
6408 // default value for a formal parameter, this function does not specify a | 6415 // default value for a formal parameter, this function does not specify a |
6409 // different default value for the same parameter. However, this check is not | 6416 // different default value for the same parameter. However, this check is not |
6410 // possible in the current implementation, because the default parameter | 6417 // possible in the current implementation, because the default parameter |
6411 // values are not stored in the Function object, but discarded after a | 6418 // values are not stored in the Function object, but discarded after a |
6412 // function is compiled. | 6419 // function is compiled. |
6413 return true; | 6420 return true; |
6414 } | 6421 } |
6415 | 6422 |
6416 | 6423 |
| 6424 RawFunction* Function::InstantiateSignatureFrom( |
| 6425 const TypeArguments& instantiator_type_arguments, |
| 6426 Heap::Space space) const { |
| 6427 Zone* zone = Thread::Current()->zone(); |
| 6428 const Object& owner = Object::Handle(zone, RawOwner()); |
| 6429 // TODO(regis): Should we change Function::New() to accept a space, since |
| 6430 // InstantiateFrom is sometimes called with Heap::kNew? |
| 6431 ASSERT(!HasInstantiatedSignature()); |
| 6432 Function& sig = Function::Handle( |
| 6433 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); |
| 6434 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); |
| 6435 AbstractType& type = AbstractType::Handle(zone, result_type()); |
| 6436 if (!type.IsInstantiated()) { |
| 6437 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL, |
| 6438 space); |
| 6439 } |
| 6440 sig.set_result_type(type); |
| 6441 const intptr_t num_params = NumParameters(); |
| 6442 sig.set_num_fixed_parameters(num_fixed_parameters()); |
| 6443 sig.SetNumOptionalParameters(NumOptionalParameters(), |
| 6444 HasOptionalPositionalParameters()); |
| 6445 sig.set_parameter_types(Array::Handle(Array::New(num_params, space))); |
| 6446 for (intptr_t i = 0; i < num_params; i++) { |
| 6447 type = ParameterTypeAt(i); |
| 6448 if (!type.IsInstantiated()) { |
| 6449 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL, |
| 6450 space); |
| 6451 } |
| 6452 sig.SetParameterTypeAt(i, type); |
| 6453 } |
| 6454 sig.set_parameter_names(Array::Handle(zone, parameter_names())); |
| 6455 return sig.raw(); |
| 6456 } |
| 6457 |
| 6458 |
6417 // If test_kind == kIsSubtypeOf, checks if the type of the specified parameter | 6459 // If test_kind == kIsSubtypeOf, checks if the type of the specified parameter |
6418 // of this function is a subtype or a supertype of the type of the specified | 6460 // of this function is a subtype or a supertype of the type of the specified |
6419 // parameter of the other function. | 6461 // parameter of the other function. |
6420 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified | 6462 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified |
6421 // parameter of this function is more specific than the type of the specified | 6463 // parameter of this function is more specific than the type of the specified |
6422 // parameter of the other function. | 6464 // parameter of the other function. |
6423 // Note that we do not apply contravariance of parameter types, but covariance | 6465 // Note that we do not apply contravariance of parameter types, but covariance |
6424 // of both parameter types and result type. | 6466 // of both parameter types and result type. |
6425 bool Function::TestParameterType(TypeTestKind test_kind, | 6467 bool Function::TestParameterType(TypeTestKind test_kind, |
6426 intptr_t parameter_position, | 6468 intptr_t parameter_position, |
6427 intptr_t other_parameter_position, | 6469 intptr_t other_parameter_position, |
6428 const TypeArguments& type_arguments, | |
6429 const Function& other, | 6470 const Function& other, |
6430 const TypeArguments& other_type_arguments, | |
6431 Error* bound_error, | 6471 Error* bound_error, |
6432 Heap::Space space) const { | 6472 Heap::Space space) const { |
6433 AbstractType& other_param_type = | 6473 const AbstractType& other_param_type = |
6434 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position)); | 6474 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position)); |
6435 if (!other_param_type.IsInstantiated()) { | |
6436 other_param_type = | |
6437 other_param_type.InstantiateFrom(other_type_arguments, bound_error, | |
6438 NULL, // instantiation_trail | |
6439 NULL, // bound_trail | |
6440 space); | |
6441 ASSERT((bound_error == NULL) || bound_error->IsNull()); | |
6442 } | |
6443 if (other_param_type.IsDynamicType()) { | 6475 if (other_param_type.IsDynamicType()) { |
6444 return true; | 6476 return true; |
6445 } | 6477 } |
6446 AbstractType& param_type = | 6478 const AbstractType& param_type = |
6447 AbstractType::Handle(ParameterTypeAt(parameter_position)); | 6479 AbstractType::Handle(ParameterTypeAt(parameter_position)); |
6448 if (!param_type.IsInstantiated()) { | |
6449 param_type = param_type.InstantiateFrom(type_arguments, bound_error, | |
6450 NULL, // instantiation_trail | |
6451 NULL, // bound_trail | |
6452 space); | |
6453 ASSERT((bound_error == NULL) || bound_error->IsNull()); | |
6454 } | |
6455 if (param_type.IsDynamicType()) { | 6480 if (param_type.IsDynamicType()) { |
6456 return test_kind == kIsSubtypeOf; | 6481 return test_kind == kIsSubtypeOf; |
6457 } | 6482 } |
6458 if (test_kind == kIsSubtypeOf) { | 6483 if (test_kind == kIsSubtypeOf) { |
6459 if (!param_type.IsSubtypeOf(other_param_type, bound_error, NULL, space) && | 6484 if (!param_type.IsSubtypeOf(other_param_type, bound_error, NULL, space) && |
6460 !other_param_type.IsSubtypeOf(param_type, bound_error, NULL, space)) { | 6485 !other_param_type.IsSubtypeOf(param_type, bound_error, NULL, space)) { |
6461 return false; | 6486 return false; |
6462 } | 6487 } |
6463 } else { | 6488 } else { |
6464 ASSERT(test_kind == kIsMoreSpecificThan); | 6489 ASSERT(test_kind == kIsMoreSpecificThan); |
6465 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error, NULL, | 6490 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error, NULL, |
6466 space)) { | 6491 space)) { |
6467 return false; | 6492 return false; |
6468 } | 6493 } |
6469 } | 6494 } |
6470 return true; | 6495 return true; |
6471 } | 6496 } |
6472 | 6497 |
6473 | 6498 |
6474 bool Function::TypeTest(TypeTestKind test_kind, | 6499 bool Function::TypeTest(TypeTestKind test_kind, |
6475 const TypeArguments& type_arguments, | |
6476 const Function& other, | 6500 const Function& other, |
6477 const TypeArguments& other_type_arguments, | |
6478 Error* bound_error, | 6501 Error* bound_error, |
6479 Heap::Space space) const { | 6502 Heap::Space space) const { |
6480 const intptr_t num_fixed_params = num_fixed_parameters(); | 6503 const intptr_t num_fixed_params = num_fixed_parameters(); |
6481 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 6504 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
6482 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 6505 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
6483 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); | 6506 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); |
6484 const intptr_t other_num_opt_pos_params = | 6507 const intptr_t other_num_opt_pos_params = |
6485 other.NumOptionalPositionalParameters(); | 6508 other.NumOptionalPositionalParameters(); |
6486 const intptr_t other_num_opt_named_params = | 6509 const intptr_t other_num_opt_named_params = |
6487 other.NumOptionalNamedParameters(); | 6510 other.NumOptionalNamedParameters(); |
6488 // This function requires the same arguments or less and accepts the same | 6511 // This function requires the same arguments or less and accepts the same |
6489 // arguments or more. We can ignore implicit parameters. | 6512 // arguments or more. We can ignore implicit parameters. |
6490 const intptr_t num_ignored_params = NumImplicitParameters(); | 6513 const intptr_t num_ignored_params = NumImplicitParameters(); |
6491 const intptr_t other_num_ignored_params = other.NumImplicitParameters(); | 6514 const intptr_t other_num_ignored_params = other.NumImplicitParameters(); |
6492 if (((num_fixed_params - num_ignored_params) > | 6515 if (((num_fixed_params - num_ignored_params) > |
6493 (other_num_fixed_params - other_num_ignored_params)) || | 6516 (other_num_fixed_params - other_num_ignored_params)) || |
6494 ((num_fixed_params - num_ignored_params + num_opt_pos_params) < | 6517 ((num_fixed_params - num_ignored_params + num_opt_pos_params) < |
6495 (other_num_fixed_params - other_num_ignored_params + | 6518 (other_num_fixed_params - other_num_ignored_params + |
6496 other_num_opt_pos_params)) || | 6519 other_num_opt_pos_params)) || |
6497 (num_opt_named_params < other_num_opt_named_params)) { | 6520 (num_opt_named_params < other_num_opt_named_params)) { |
6498 return false; | 6521 return false; |
6499 } | 6522 } |
6500 // Check the result type. | 6523 // Check the result type. |
6501 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); | 6524 const AbstractType& other_res_type = |
6502 if (!other_res_type.IsInstantiated()) { | 6525 AbstractType::Handle(other.result_type()); |
6503 other_res_type = other_res_type.InstantiateFrom( | |
6504 other_type_arguments, bound_error, NULL, NULL, space); | |
6505 ASSERT((bound_error == NULL) || bound_error->IsNull()); | |
6506 } | |
6507 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { | 6526 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { |
6508 AbstractType& res_type = AbstractType::Handle(result_type()); | 6527 const AbstractType& res_type = AbstractType::Handle(result_type()); |
6509 if (!res_type.IsInstantiated()) { | |
6510 res_type = res_type.InstantiateFrom(type_arguments, bound_error, NULL, | |
6511 NULL, space); | |
6512 ASSERT((bound_error == NULL) || bound_error->IsNull()); | |
6513 } | |
6514 if (res_type.IsVoidType()) { | 6528 if (res_type.IsVoidType()) { |
6515 return false; | 6529 return false; |
6516 } | 6530 } |
6517 if (test_kind == kIsSubtypeOf) { | 6531 if (test_kind == kIsSubtypeOf) { |
6518 if (!res_type.IsSubtypeOf(other_res_type, bound_error, NULL, space) && | 6532 if (!res_type.IsSubtypeOf(other_res_type, bound_error, NULL, space) && |
6519 !other_res_type.IsSubtypeOf(res_type, bound_error, NULL, space)) { | 6533 !other_res_type.IsSubtypeOf(res_type, bound_error, NULL, space)) { |
6520 return false; | 6534 return false; |
6521 } | 6535 } |
6522 } else { | 6536 } else { |
6523 ASSERT(test_kind == kIsMoreSpecificThan); | 6537 ASSERT(test_kind == kIsMoreSpecificThan); |
6524 if (!res_type.IsMoreSpecificThan(other_res_type, bound_error, NULL, | 6538 if (!res_type.IsMoreSpecificThan(other_res_type, bound_error, NULL, |
6525 space)) { | 6539 space)) { |
6526 return false; | 6540 return false; |
6527 } | 6541 } |
6528 } | 6542 } |
6529 } | 6543 } |
6530 // Check the types of fixed and optional positional parameters. | 6544 // Check the types of fixed and optional positional parameters. |
6531 for (intptr_t i = 0; i < (other_num_fixed_params - other_num_ignored_params + | 6545 for (intptr_t i = 0; i < (other_num_fixed_params - other_num_ignored_params + |
6532 other_num_opt_pos_params); | 6546 other_num_opt_pos_params); |
6533 i++) { | 6547 i++) { |
6534 if (!TestParameterType(test_kind, i + num_ignored_params, | 6548 if (!TestParameterType(test_kind, i + num_ignored_params, |
6535 i + other_num_ignored_params, type_arguments, other, | 6549 i + other_num_ignored_params, other, bound_error, |
6536 other_type_arguments, bound_error, space)) { | 6550 space)) { |
6537 return false; | 6551 return false; |
6538 } | 6552 } |
6539 } | 6553 } |
6540 // Check the names and types of optional named parameters. | 6554 // Check the names and types of optional named parameters. |
6541 if (other_num_opt_named_params == 0) { | 6555 if (other_num_opt_named_params == 0) { |
6542 return true; | 6556 return true; |
6543 } | 6557 } |
6544 // Check that for each optional named parameter of type T of the other | 6558 // Check that for each optional named parameter of type T of the other |
6545 // function type, there exists an optional named parameter of this function | 6559 // function type, there exists an optional named parameter of this function |
6546 // type with an identical name and with a type S that is a either a subtype | 6560 // type with an identical name and with a type S that is a either a subtype |
6547 // or supertype of T (if test_kind == kIsSubtypeOf) or that is more specific | 6561 // or supertype of T (if test_kind == kIsSubtypeOf) or that is more specific |
6548 // than T (if test_kind == kIsMoreSpecificThan). | 6562 // than T (if test_kind == kIsMoreSpecificThan). |
6549 // Note that SetParameterNameAt() guarantees that names are symbols, so we | 6563 // Note that SetParameterNameAt() guarantees that names are symbols, so we |
6550 // can compare their raw pointers. | 6564 // can compare their raw pointers. |
6551 const int num_params = num_fixed_params + num_opt_named_params; | 6565 const int num_params = num_fixed_params + num_opt_named_params; |
6552 const int other_num_params = | 6566 const int other_num_params = |
6553 other_num_fixed_params + other_num_opt_named_params; | 6567 other_num_fixed_params + other_num_opt_named_params; |
6554 bool found_param_name; | 6568 bool found_param_name; |
6555 String& other_param_name = String::Handle(); | 6569 String& other_param_name = String::Handle(); |
6556 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { | 6570 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { |
6557 other_param_name = other.ParameterNameAt(i); | 6571 other_param_name = other.ParameterNameAt(i); |
6558 ASSERT(other_param_name.IsSymbol()); | 6572 ASSERT(other_param_name.IsSymbol()); |
6559 found_param_name = false; | 6573 found_param_name = false; |
6560 for (intptr_t j = num_fixed_params; j < num_params; j++) { | 6574 for (intptr_t j = num_fixed_params; j < num_params; j++) { |
6561 ASSERT(String::Handle(ParameterNameAt(j)).IsSymbol()); | 6575 ASSERT(String::Handle(ParameterNameAt(j)).IsSymbol()); |
6562 if (ParameterNameAt(j) == other_param_name.raw()) { | 6576 if (ParameterNameAt(j) == other_param_name.raw()) { |
6563 found_param_name = true; | 6577 found_param_name = true; |
6564 if (!TestParameterType(test_kind, j, i, type_arguments, other, | 6578 if (!TestParameterType(test_kind, j, i, other, bound_error, space)) { |
6565 other_type_arguments, bound_error, space)) { | |
6566 return false; | 6579 return false; |
6567 } | 6580 } |
6568 break; | 6581 break; |
6569 } | 6582 } |
6570 } | 6583 } |
6571 if (!found_param_name) { | 6584 if (!found_param_name) { |
6572 return false; | 6585 return false; |
6573 } | 6586 } |
6574 } | 6587 } |
6575 return true; | 6588 return true; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6624 | 6637 |
6625 RawFunction* Function::New(const String& name, | 6638 RawFunction* Function::New(const String& name, |
6626 RawFunction::Kind kind, | 6639 RawFunction::Kind kind, |
6627 bool is_static, | 6640 bool is_static, |
6628 bool is_const, | 6641 bool is_const, |
6629 bool is_abstract, | 6642 bool is_abstract, |
6630 bool is_external, | 6643 bool is_external, |
6631 bool is_native, | 6644 bool is_native, |
6632 const Object& owner, | 6645 const Object& owner, |
6633 TokenPosition token_pos) { | 6646 TokenPosition token_pos) { |
6634 ASSERT(!owner.IsNull()); | 6647 ASSERT(!owner.IsNull() || (kind == RawFunction::kSignatureFunction)); |
6635 const Function& result = Function::Handle(Function::New()); | 6648 const Function& result = Function::Handle(Function::New()); |
6636 result.set_parameter_types(Object::empty_array()); | 6649 result.set_parameter_types(Object::empty_array()); |
6637 result.set_parameter_names(Object::empty_array()); | 6650 result.set_parameter_names(Object::empty_array()); |
6638 result.set_name(name); | 6651 result.set_name(name); |
6639 result.set_kind(kind); | 6652 result.set_kind(kind); |
6640 result.set_recognized_kind(MethodRecognizer::kUnknown); | 6653 result.set_recognized_kind(MethodRecognizer::kUnknown); |
6641 result.set_modifier(RawFunction::kNoModifier); | 6654 result.set_modifier(RawFunction::kNoModifier); |
6642 result.set_is_static(is_static); | 6655 result.set_is_static(is_static); |
6643 result.set_is_const(is_const); | 6656 result.set_is_const(is_const); |
6644 result.set_is_abstract(is_abstract); | 6657 result.set_is_abstract(is_abstract); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6688 const PatchClass& clone_owner = | 6701 const PatchClass& clone_owner = |
6689 PatchClass::Handle(PatchClass::New(new_owner, origin)); | 6702 PatchClass::Handle(PatchClass::New(new_owner, origin)); |
6690 clone.set_owner(clone_owner); | 6703 clone.set_owner(clone_owner); |
6691 clone.ClearICDataArray(); | 6704 clone.ClearICDataArray(); |
6692 clone.ClearCode(); | 6705 clone.ClearCode(); |
6693 clone.set_usage_counter(0); | 6706 clone.set_usage_counter(0); |
6694 clone.set_deoptimization_counter(0); | 6707 clone.set_deoptimization_counter(0); |
6695 clone.set_optimized_instruction_count(0); | 6708 clone.set_optimized_instruction_count(0); |
6696 clone.set_optimized_call_site_count(0); | 6709 clone.set_optimized_call_site_count(0); |
6697 clone.set_kernel_function(kernel_function()); | 6710 clone.set_kernel_function(kernel_function()); |
| 6711 // TODO(regis): Clone function type parameters (their bounds may change). |
6698 if (new_owner.NumTypeParameters() > 0) { | 6712 if (new_owner.NumTypeParameters() > 0) { |
6699 // Adjust uninstantiated types to refer to type parameters of the new owner. | 6713 // Adjust uninstantiated types to refer to type parameters of the new owner. |
6700 AbstractType& type = AbstractType::Handle(clone.result_type()); | 6714 AbstractType& type = AbstractType::Handle(clone.result_type()); |
6701 type ^= type.CloneUninstantiated(new_owner); | 6715 type ^= type.CloneUninstantiated(new_owner); |
6702 clone.set_result_type(type); | 6716 clone.set_result_type(type); |
6703 const intptr_t num_params = clone.NumParameters(); | 6717 const intptr_t num_params = clone.NumParameters(); |
6704 Array& array = Array::Handle(clone.parameter_types()); | 6718 Array& array = Array::Handle(clone.parameter_types()); |
6705 array ^= Object::Clone(array, Heap::kOld); | 6719 array ^= Object::Clone(array, Heap::kOld); |
6706 clone.set_parameter_types(array); | 6720 clone.set_parameter_types(array); |
6707 for (intptr_t i = 0; i < num_params; i++) { | 6721 for (intptr_t i = 0; i < num_params; i++) { |
(...skipping 18 matching lines...) Expand all Loading... |
6726 /* is_static = */ parent.is_static(), | 6740 /* is_static = */ parent.is_static(), |
6727 /* is_const = */ false, | 6741 /* is_const = */ false, |
6728 /* is_abstract = */ false, | 6742 /* is_abstract = */ false, |
6729 /* is_external = */ false, | 6743 /* is_external = */ false, |
6730 /* is_native = */ false, parent_owner, token_pos)); | 6744 /* is_native = */ false, parent_owner, token_pos)); |
6731 result.set_parent_function(parent); | 6745 result.set_parent_function(parent); |
6732 return result.raw(); | 6746 return result.raw(); |
6733 } | 6747 } |
6734 | 6748 |
6735 | 6749 |
6736 RawFunction* Function::NewSignatureFunction(const Class& owner, | 6750 RawFunction* Function::NewSignatureFunction(const Object& owner, |
6737 TokenPosition token_pos) { | 6751 TokenPosition token_pos) { |
6738 const Function& result = Function::Handle(Function::New( | 6752 const Function& result = Function::Handle(Function::New( |
6739 Symbols::AnonymousSignature(), RawFunction::kSignatureFunction, | 6753 Symbols::AnonymousSignature(), RawFunction::kSignatureFunction, |
6740 /* is_static = */ false, | 6754 /* is_static = */ false, |
6741 /* is_const = */ false, | 6755 /* is_const = */ false, |
6742 /* is_abstract = */ false, | 6756 /* is_abstract = */ false, |
6743 /* is_external = */ false, | 6757 /* is_external = */ false, |
6744 /* is_native = */ false, | 6758 /* is_native = */ false, |
6745 owner, // Same as function type scope class. | 6759 owner, // Same as function type scope class. |
6746 token_pos)); | 6760 token_pos)); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6850 } | 6864 } |
6851 } | 6865 } |
6852 | 6866 |
6853 | 6867 |
6854 RawString* Function::UserVisibleFormalParameters() const { | 6868 RawString* Function::UserVisibleFormalParameters() const { |
6855 Thread* thread = Thread::Current(); | 6869 Thread* thread = Thread::Current(); |
6856 Zone* zone = thread->zone(); | 6870 Zone* zone = thread->zone(); |
6857 // Typically 3, 5,.. elements in 'pieces', e.g.: | 6871 // Typically 3, 5,.. elements in 'pieces', e.g.: |
6858 // '_LoadRequest', CommaSpace, '_LoadError'. | 6872 // '_LoadRequest', CommaSpace, '_LoadError'. |
6859 GrowableHandlePtrArray<const String> pieces(zone, 5); | 6873 GrowableHandlePtrArray<const String> pieces(zone, 5); |
6860 const TypeArguments& instantiator = TypeArguments::Handle(zone); | 6874 BuildSignatureParameters(thread, zone, kUserVisibleName, &pieces); |
6861 BuildSignatureParameters(thread, zone, false, kUserVisibleName, instantiator, | |
6862 &pieces); | |
6863 return Symbols::FromConcatAll(thread, pieces); | 6875 return Symbols::FromConcatAll(thread, pieces); |
6864 } | 6876 } |
6865 | 6877 |
6866 | 6878 |
6867 void Function::BuildSignatureParameters( | 6879 void Function::BuildSignatureParameters( |
6868 Thread* thread, | 6880 Thread* thread, |
6869 Zone* zone, | 6881 Zone* zone, |
6870 bool instantiate, | |
6871 NameVisibility name_visibility, | 6882 NameVisibility name_visibility, |
6872 const TypeArguments& instantiator, | |
6873 GrowableHandlePtrArray<const String>* pieces) const { | 6883 GrowableHandlePtrArray<const String>* pieces) const { |
6874 AbstractType& param_type = AbstractType::Handle(zone); | 6884 AbstractType& param_type = AbstractType::Handle(zone); |
6875 const intptr_t num_params = NumParameters(); | 6885 const intptr_t num_params = NumParameters(); |
6876 const intptr_t num_fixed_params = num_fixed_parameters(); | 6886 const intptr_t num_fixed_params = num_fixed_parameters(); |
6877 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 6887 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
6878 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 6888 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
6879 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; | 6889 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; |
6880 ASSERT((num_fixed_params + num_opt_params) == num_params); | 6890 ASSERT((num_fixed_params + num_opt_params) == num_params); |
6881 intptr_t i = 0; | 6891 intptr_t i = 0; |
6882 if (name_visibility == kUserVisibleName) { | 6892 if (name_visibility == kUserVisibleName) { |
6883 // Hide implicit parameters. | 6893 // Hide implicit parameters. |
6884 i = NumImplicitParameters(); | 6894 i = NumImplicitParameters(); |
6885 } | 6895 } |
6886 String& name = String::Handle(zone); | 6896 String& name = String::Handle(zone); |
6887 while (i < num_fixed_params) { | 6897 while (i < num_fixed_params) { |
6888 param_type = ParameterTypeAt(i); | 6898 param_type = ParameterTypeAt(i); |
6889 ASSERT(!param_type.IsNull()); | 6899 ASSERT(!param_type.IsNull()); |
6890 if (instantiate && param_type.IsFinalized() && | |
6891 !param_type.IsInstantiated()) { | |
6892 param_type = param_type.InstantiateFrom(instantiator, NULL, NULL, NULL, | |
6893 Heap::kNew); | |
6894 } | |
6895 name = param_type.BuildName(name_visibility); | 6900 name = param_type.BuildName(name_visibility); |
6896 pieces->Add(name); | 6901 pieces->Add(name); |
6897 if (i != (num_params - 1)) { | 6902 if (i != (num_params - 1)) { |
6898 pieces->Add(Symbols::CommaSpace()); | 6903 pieces->Add(Symbols::CommaSpace()); |
6899 } | 6904 } |
6900 i++; | 6905 i++; |
6901 } | 6906 } |
6902 if (num_opt_params > 0) { | 6907 if (num_opt_params > 0) { |
6903 if (num_opt_pos_params > 0) { | 6908 if (num_opt_pos_params > 0) { |
6904 pieces->Add(Symbols::LBracket()); | 6909 pieces->Add(Symbols::LBracket()); |
6905 } else { | 6910 } else { |
6906 pieces->Add(Symbols::LBrace()); | 6911 pieces->Add(Symbols::LBrace()); |
6907 } | 6912 } |
6908 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 6913 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
6909 param_type = ParameterTypeAt(i); | 6914 param_type = ParameterTypeAt(i); |
6910 if (instantiate && param_type.IsFinalized() && | |
6911 !param_type.IsInstantiated()) { | |
6912 param_type = param_type.InstantiateFrom(instantiator, NULL, NULL, NULL, | |
6913 Heap::kNew); | |
6914 } | |
6915 ASSERT(!param_type.IsNull()); | 6915 ASSERT(!param_type.IsNull()); |
6916 name = param_type.BuildName(name_visibility); | 6916 name = param_type.BuildName(name_visibility); |
6917 pieces->Add(name); | 6917 pieces->Add(name); |
6918 // The parameter name of an optional positional parameter does not need | 6918 // The parameter name of an optional positional parameter does not need |
6919 // to be part of the signature, since it is not used. | 6919 // to be part of the signature, since it is not used. |
6920 if (num_opt_named_params > 0) { | 6920 if (num_opt_named_params > 0) { |
6921 name = ParameterNameAt(i); | 6921 name = ParameterNameAt(i); |
6922 pieces->Add(Symbols::Blank()); | 6922 pieces->Add(Symbols::Blank()); |
6923 pieces->Add(name); | 6923 pieces->Add(name); |
6924 } | 6924 } |
(...skipping 19 matching lines...) Expand all Loading... |
6944 zone, Closure::New(instantiator, *this, context, Heap::kOld)); | 6944 zone, Closure::New(instantiator, *this, context, Heap::kOld)); |
6945 set_implicit_static_closure(closure); | 6945 set_implicit_static_closure(closure); |
6946 } | 6946 } |
6947 return implicit_static_closure(); | 6947 return implicit_static_closure(); |
6948 } | 6948 } |
6949 | 6949 |
6950 | 6950 |
6951 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { | 6951 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { |
6952 ASSERT(IsImplicitClosureFunction()); | 6952 ASSERT(IsImplicitClosureFunction()); |
6953 Zone* zone = Thread::Current()->zone(); | 6953 Zone* zone = Thread::Current()->zone(); |
6954 const Type& signature_type = Type::Handle(zone, SignatureType()); | |
6955 const Class& cls = Class::Handle(zone, signature_type.type_class()); | |
6956 const Context& context = Context::Handle(zone, Context::New(1)); | 6954 const Context& context = Context::Handle(zone, Context::New(1)); |
6957 context.SetAt(0, receiver); | 6955 context.SetAt(0, receiver); |
6958 TypeArguments& instantiator = TypeArguments::Handle(zone); | 6956 TypeArguments& instantiator = TypeArguments::Handle(zone); |
6959 if (cls.IsGeneric()) { | 6957 if (!HasInstantiatedSignature(kCurrentClass)) { |
6960 instantiator = receiver.GetTypeArguments(); | 6958 instantiator = receiver.GetTypeArguments(); |
6961 } | 6959 } |
6962 return Closure::New(instantiator, *this, context); | 6960 return Closure::New(instantiator, *this, context); |
6963 } | 6961 } |
6964 | 6962 |
6965 | 6963 |
6966 RawSmi* Function::GetClosureHashCode() const { | 6964 RawSmi* Function::GetClosureHashCode() const { |
6967 ASSERT(IsClosureFunction()); | 6965 ASSERT(IsClosureFunction()); |
6968 const Object& obj = Object::Handle(raw_ptr()->data_); | 6966 const Object& obj = Object::Handle(raw_ptr()->data_); |
6969 ASSERT(!obj.IsNull()); | 6967 ASSERT(!obj.IsNull()); |
6970 if (ClosureData::Cast(obj).hash() != Object::null()) { | 6968 if (ClosureData::Cast(obj).hash() != Object::null()) { |
6971 return Smi::RawCast(ClosureData::Cast(obj).hash()); | 6969 return Smi::RawCast(ClosureData::Cast(obj).hash()); |
6972 } | 6970 } |
6973 // Hash not yet computed. Compute and cache it. | 6971 // Hash not yet computed. Compute and cache it. |
6974 const Class& cls = Class::Handle(Owner()); | 6972 const Class& cls = Class::Handle(Owner()); |
6975 intptr_t result = String::Handle(name()).Hash(); | 6973 intptr_t result = String::Handle(name()).Hash(); |
6976 result += String::Handle(Signature()).Hash(); | 6974 result += String::Handle(Signature()).Hash(); |
6977 result += String::Handle(cls.Name()).Hash(); | 6975 result += String::Handle(cls.Name()).Hash(); |
6978 // Finalize hash value like for strings so that it fits into a smi. | 6976 // Finalize hash value like for strings so that it fits into a smi. |
6979 result += result << 3; | 6977 result += result << 3; |
6980 result ^= result >> 11; | 6978 result ^= result >> 11; |
6981 result += result << 15; | 6979 result += result << 15; |
6982 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); | 6980 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); |
6983 ClosureData::Cast(obj).set_hash(result); | 6981 ClosureData::Cast(obj).set_hash(result); |
6984 return Smi::New(result); | 6982 return Smi::New(result); |
6985 } | 6983 } |
6986 | 6984 |
6987 | 6985 |
6988 RawString* Function::BuildSignature(bool instantiate, | 6986 RawString* Function::BuildSignature(NameVisibility name_visibility) const { |
6989 NameVisibility name_visibility, | |
6990 const TypeArguments& instantiator) const { | |
6991 Thread* thread = Thread::Current(); | 6987 Thread* thread = Thread::Current(); |
6992 Zone* zone = thread->zone(); | 6988 Zone* zone = thread->zone(); |
6993 GrowableHandlePtrArray<const String> pieces(zone, 4); | 6989 GrowableHandlePtrArray<const String> pieces(zone, 4); |
6994 String& name = String::Handle(zone); | |
6995 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { | |
6996 // Prefix the signature with its scope class and type parameters, if any | |
6997 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the | |
6998 // scope class name is the alias name. | |
6999 // The signature of static functions cannot be type parameterized. | |
7000 const Class& scope_class = Class::Handle(zone, Owner()); | |
7001 ASSERT(!scope_class.IsNull()); | |
7002 if (scope_class.IsGeneric()) { | |
7003 const TypeArguments& type_parameters = | |
7004 TypeArguments::Handle(zone, scope_class.type_parameters()); | |
7005 const String& scope_class_name = String::Handle(zone, scope_class.Name()); | |
7006 pieces.Add(scope_class_name); | |
7007 const intptr_t num_type_parameters = type_parameters.Length(); | |
7008 pieces.Add(Symbols::LAngleBracket()); | |
7009 TypeParameter& type_parameter = TypeParameter::Handle(zone); | |
7010 AbstractType& bound = AbstractType::Handle(zone); | |
7011 for (intptr_t i = 0; i < num_type_parameters; i++) { | |
7012 type_parameter ^= type_parameters.TypeAt(i); | |
7013 name = type_parameter.name(); | |
7014 pieces.Add(name); | |
7015 bound = type_parameter.bound(); | |
7016 if (!bound.IsNull() && !bound.IsObjectType()) { | |
7017 pieces.Add(Symbols::SpaceExtendsSpace()); | |
7018 name = bound.BuildName(name_visibility); | |
7019 pieces.Add(name); | |
7020 } | |
7021 if (i < num_type_parameters - 1) { | |
7022 pieces.Add(Symbols::CommaSpace()); | |
7023 } | |
7024 } | |
7025 pieces.Add(Symbols::RAngleBracket()); | |
7026 } | |
7027 } | |
7028 pieces.Add(Symbols::LParen()); | 6990 pieces.Add(Symbols::LParen()); |
7029 BuildSignatureParameters(thread, zone, instantiate, name_visibility, | 6991 BuildSignatureParameters(thread, zone, name_visibility, &pieces); |
7030 instantiator, &pieces); | |
7031 pieces.Add(Symbols::RParenArrow()); | 6992 pieces.Add(Symbols::RParenArrow()); |
7032 AbstractType& res_type = AbstractType::Handle(zone, result_type()); | 6993 const AbstractType& res_type = AbstractType::Handle(zone, result_type()); |
7033 if (instantiate && res_type.IsFinalized() && !res_type.IsInstantiated()) { | 6994 const String& name = |
7034 res_type = | 6995 String::Handle(zone, res_type.BuildName(name_visibility)); |
7035 res_type.InstantiateFrom(instantiator, NULL, NULL, NULL, Heap::kNew); | |
7036 } | |
7037 name = res_type.BuildName(name_visibility); | |
7038 pieces.Add(name); | 6996 pieces.Add(name); |
7039 return Symbols::FromConcatAll(thread, pieces); | 6997 return Symbols::FromConcatAll(thread, pieces); |
7040 } | 6998 } |
7041 | 6999 |
7042 | 7000 |
7043 bool Function::HasInstantiatedSignature() const { | 7001 bool Function::HasInstantiatedSignature(Genericity genericity, |
| 7002 TrailPtr trail) const { |
7044 AbstractType& type = AbstractType::Handle(result_type()); | 7003 AbstractType& type = AbstractType::Handle(result_type()); |
7045 if (!type.IsInstantiated()) { | 7004 if (!type.IsInstantiated(genericity, trail)) { |
7046 return false; | 7005 return false; |
7047 } | 7006 } |
7048 const intptr_t num_parameters = NumParameters(); | 7007 const intptr_t num_parameters = NumParameters(); |
7049 for (intptr_t i = 0; i < num_parameters; i++) { | 7008 for (intptr_t i = 0; i < num_parameters; i++) { |
7050 type = ParameterTypeAt(i); | 7009 type = ParameterTypeAt(i); |
7051 if (!type.IsInstantiated()) { | 7010 if (!type.IsInstantiated(genericity, trail)) { |
7052 return false; | 7011 return false; |
7053 } | 7012 } |
7054 } | 7013 } |
7055 return true; | 7014 return true; |
7056 } | 7015 } |
7057 | 7016 |
7058 | 7017 |
7059 RawClass* Function::Owner() const { | 7018 RawClass* Function::Owner() const { |
7060 if (raw_ptr()->owner_ == Object::null()) { | 7019 if (raw_ptr()->owner_ == Object::null()) { |
7061 ASSERT(IsSignatureFunction()); | 7020 ASSERT(IsSignatureFunction()); |
(...skipping 8589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15651 | 15610 |
15652 RawAbstractType* Instance::GetType(Heap::Space space) const { | 15611 RawAbstractType* Instance::GetType(Heap::Space space) const { |
15653 if (IsNull()) { | 15612 if (IsNull()) { |
15654 return Type::NullType(); | 15613 return Type::NullType(); |
15655 } | 15614 } |
15656 const Class& cls = Class::Handle(clazz()); | 15615 const Class& cls = Class::Handle(clazz()); |
15657 if (cls.IsClosureClass()) { | 15616 if (cls.IsClosureClass()) { |
15658 const Function& signature = | 15617 const Function& signature = |
15659 Function::Handle(Closure::Cast(*this).function()); | 15618 Function::Handle(Closure::Cast(*this).function()); |
15660 Type& type = Type::Handle(signature.SignatureType()); | 15619 Type& type = Type::Handle(signature.SignatureType()); |
15661 if (type.type_class() == cls.raw()) { | 15620 if (!type.IsInstantiated()) { |
15662 // Type is not parameterized. | 15621 TypeArguments& instantiator_type_arguments = |
15663 if (!type.IsCanonical()) { | 15622 TypeArguments::Handle(Closure::Cast(*this).instantiator()); |
15664 type ^= type.Canonicalize(); | 15623 // TODO(regis): Should we pass the context explicitly here (i.e. null) |
15665 signature.SetSignatureType(type); | 15624 // once we support generic functions? |
15666 } | 15625 type ^= type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, |
15667 return type.raw(); | 15626 NULL, space); |
15668 } | 15627 } |
15669 const Class& scope_cls = Class::Handle(type.type_class()); | |
15670 ASSERT(scope_cls.NumTypeArguments() > 0); | |
15671 TypeArguments& type_arguments = | |
15672 TypeArguments::Handle(Closure::Cast(*this).instantiator()); | |
15673 type = | |
15674 Type::New(scope_cls, type_arguments, TokenPosition::kNoSource, space); | |
15675 type.set_signature(signature); | |
15676 type.SetIsFinalized(); | |
15677 type ^= type.Canonicalize(); | 15628 type ^= type.Canonicalize(); |
15678 return type.raw(); | 15629 return type.raw(); |
15679 } | 15630 } |
15680 Type& type = Type::Handle(); | 15631 Type& type = Type::Handle(); |
15681 if (!cls.IsGeneric()) { | 15632 if (!cls.IsGeneric()) { |
15682 type = cls.CanonicalType(); | 15633 type = cls.CanonicalType(); |
15683 } | 15634 } |
15684 if (type.IsNull()) { | 15635 if (type.IsNull()) { |
15685 TypeArguments& type_arguments = TypeArguments::Handle(); | 15636 TypeArguments& type_arguments = TypeArguments::Handle(); |
15686 if (cls.NumTypeArguments() > 0) { | 15637 if (cls.NumTypeArguments() > 0) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15724 if (other.IsVoidType()) { | 15675 if (other.IsVoidType()) { |
15725 return false; | 15676 return false; |
15726 } | 15677 } |
15727 Zone* zone = Thread::Current()->zone(); | 15678 Zone* zone = Thread::Current()->zone(); |
15728 const Class& cls = Class::Handle(zone, clazz()); | 15679 const Class& cls = Class::Handle(zone, clazz()); |
15729 if (cls.IsClosureClass()) { | 15680 if (cls.IsClosureClass()) { |
15730 if (other.IsObjectType() || other.IsDartFunctionType() || | 15681 if (other.IsObjectType() || other.IsDartFunctionType() || |
15731 other.IsDartClosureType()) { | 15682 other.IsDartClosureType()) { |
15732 return true; | 15683 return true; |
15733 } | 15684 } |
15734 Function& other_signature = Function::Handle(zone); | 15685 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); |
15735 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); | |
15736 // Note that we may encounter a bound error in checked mode. | 15686 // Note that we may encounter a bound error in checked mode. |
15737 if (!other.IsInstantiated()) { | 15687 if (!other.IsInstantiated()) { |
15738 AbstractType& instantiated_other = AbstractType::Handle( | 15688 instantiated_other = other.InstantiateFrom( |
15739 zone, other.InstantiateFrom(other_instantiator, bound_error, NULL, | 15689 other_instantiator, bound_error, NULL, NULL, Heap::kOld); |
15740 NULL, Heap::kOld)); | |
15741 if ((bound_error != NULL) && !bound_error->IsNull()) { | 15690 if ((bound_error != NULL) && !bound_error->IsNull()) { |
15742 ASSERT(Isolate::Current()->type_checks()); | 15691 ASSERT(Isolate::Current()->type_checks()); |
15743 return false; | 15692 return false; |
15744 } | 15693 } |
15745 if (instantiated_other.IsTypeRef()) { | 15694 if (instantiated_other.IsTypeRef()) { |
15746 instantiated_other = TypeRef::Cast(instantiated_other).type(); | 15695 instantiated_other = TypeRef::Cast(instantiated_other).type(); |
15747 } | 15696 } |
15748 if (instantiated_other.IsDynamicType() || | 15697 if (instantiated_other.IsDynamicType() || |
15749 instantiated_other.IsObjectType() || | 15698 instantiated_other.IsObjectType() || |
15750 instantiated_other.IsDartFunctionType()) { | 15699 instantiated_other.IsDartFunctionType()) { |
15751 return true; | 15700 return true; |
15752 } | 15701 } |
15753 if (!instantiated_other.IsFunctionType()) { | |
15754 return false; | |
15755 } | |
15756 other_signature = Type::Cast(instantiated_other).signature(); | |
15757 other_type_arguments = instantiated_other.arguments(); | |
15758 } else { | |
15759 if (!other.IsFunctionType()) { | |
15760 return false; | |
15761 } | |
15762 other_signature = Type::Cast(other).signature(); | |
15763 other_type_arguments = other.arguments(); | |
15764 } | 15702 } |
15765 const Function& signature = | 15703 if (!instantiated_other.IsFunctionType()) { |
15766 Function::Handle(zone, Closure::Cast(*this).function()); | 15704 return false; |
15767 const TypeArguments& type_arguments = | 15705 } |
15768 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator()); | 15706 Function& other_signature = |
15769 // TODO(regis): If signature function is generic, pass its type parameters | 15707 Function::Handle(zone, Type::Cast(instantiated_other).signature()); |
15770 // as function instantiator, otherwise pass null. | 15708 Function& sig_fun = Function::Handle(zone, Closure::Cast(*this).function()); |
15771 // Pass the closure context as well to the the IsSubtypeOf call. | 15709 if (!sig_fun.HasInstantiatedSignature()) { |
15772 return signature.IsSubtypeOf(type_arguments, other_signature, | 15710 const TypeArguments& instantiator_type_arguments = |
15773 other_type_arguments, bound_error, Heap::kOld); | 15711 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator()); |
| 15712 // TODO(regis): If sig_fun is generic, pass its type parameters |
| 15713 // as function instantiator, otherwise pass null. |
| 15714 // Pass the closure context as well to InstantiateSignatureFrom(). |
| 15715 // No bound error possible, since the instance exists. |
| 15716 sig_fun = sig_fun.InstantiateSignatureFrom(instantiator_type_arguments, |
| 15717 Heap::kOld); |
| 15718 } |
| 15719 return sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld); |
15774 } | 15720 } |
15775 TypeArguments& type_arguments = TypeArguments::Handle(zone); | 15721 TypeArguments& type_arguments = TypeArguments::Handle(zone); |
15776 if (cls.NumTypeArguments() > 0) { | 15722 if (cls.NumTypeArguments() > 0) { |
15777 type_arguments = GetTypeArguments(); | 15723 type_arguments = GetTypeArguments(); |
15778 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); | 15724 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); |
15779 // The number of type arguments in the instance must be greater or equal to | 15725 // The number of type arguments in the instance must be greater or equal to |
15780 // the number of type arguments expected by the instance class. | 15726 // the number of type arguments expected by the instance class. |
15781 // A discrepancy is allowed for closures, which borrow the type argument | 15727 // A discrepancy is allowed for closures, which borrow the type argument |
15782 // vector of their instantiator, which may be of a subclass of the class | 15728 // vector of their instantiator, which may be of a subclass of the class |
15783 // defining the closure. Truncating the vector to the correct length on | 15729 // defining the closure. Truncating the vector to the correct length on |
(...skipping 18 matching lines...) Expand all Loading... |
15802 instantiated_other = TypeRef::Cast(instantiated_other).type(); | 15748 instantiated_other = TypeRef::Cast(instantiated_other).type(); |
15803 } | 15749 } |
15804 if (instantiated_other.IsDynamicType()) { | 15750 if (instantiated_other.IsDynamicType()) { |
15805 return true; | 15751 return true; |
15806 } | 15752 } |
15807 } | 15753 } |
15808 other_type_arguments = instantiated_other.arguments(); | 15754 other_type_arguments = instantiated_other.arguments(); |
15809 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); | 15755 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); |
15810 if (other_is_dart_function || instantiated_other.IsFunctionType()) { | 15756 if (other_is_dart_function || instantiated_other.IsFunctionType()) { |
15811 // Check if this instance understands a call() method of a compatible type. | 15757 // Check if this instance understands a call() method of a compatible type. |
15812 const Function& call_function = | 15758 Function& sig_fun = |
15813 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); | 15759 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); |
15814 if (!call_function.IsNull()) { | 15760 if (!sig_fun.IsNull()) { |
15815 if (other_is_dart_function) { | 15761 if (other_is_dart_function) { |
15816 return true; | 15762 return true; |
15817 } | 15763 } |
| 15764 if (!sig_fun.HasInstantiatedSignature()) { |
| 15765 // TODO(regis): If sig_fun is generic, pass its type parameters |
| 15766 // as function instantiator, otherwise pass null. |
| 15767 // Pass the closure context as well to InstantiateSignatureFrom(). |
| 15768 // No bound error possible, since the instance exists. |
| 15769 sig_fun = sig_fun.InstantiateSignatureFrom(type_arguments, Heap::kOld); |
| 15770 } |
15818 const Function& other_signature = | 15771 const Function& other_signature = |
15819 Function::Handle(zone, Type::Cast(instantiated_other).signature()); | 15772 Function::Handle(zone, Type::Cast(instantiated_other).signature()); |
15820 if (call_function.IsSubtypeOf(type_arguments, other_signature, | 15773 if (sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld)) { |
15821 other_type_arguments, bound_error, | |
15822 Heap::kOld)) { | |
15823 return true; | 15774 return true; |
15824 } | 15775 } |
15825 } | 15776 } |
15826 } | 15777 } |
15827 if (!instantiated_other.IsType()) { | 15778 if (!instantiated_other.IsType()) { |
15828 return false; | 15779 return false; |
15829 } | 15780 } |
15830 other_class = instantiated_other.type_class(); | 15781 other_class = instantiated_other.type_class(); |
15831 if (IsNull()) { | 15782 if (IsNull()) { |
15832 ASSERT(cls.IsNullClass()); | 15783 ASSERT(cls.IsNullClass()); |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16321 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); | 16272 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); |
16322 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 16273 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
16323 String& class_name = String::Handle(zone); | 16274 String& class_name = String::Handle(zone); |
16324 intptr_t first_type_param_index; | 16275 intptr_t first_type_param_index; |
16325 intptr_t num_type_params; // Number of type parameters to print. | 16276 intptr_t num_type_params; // Number of type parameters to print. |
16326 Class& cls = Class::Handle(zone); | 16277 Class& cls = Class::Handle(zone); |
16327 if (IsFunctionType()) { | 16278 if (IsFunctionType()) { |
16328 cls = type_class(); | 16279 cls = type_class(); |
16329 const Function& signature_function = | 16280 const Function& signature_function = |
16330 Function::Handle(zone, Type::Cast(*this).signature()); | 16281 Function::Handle(zone, Type::Cast(*this).signature()); |
16331 if (!cls.IsTypedefClass() || | 16282 if (!cls.IsTypedefClass()) { |
16332 (cls.signature_function() != signature_function.raw())) { | 16283 return signature_function.UserVisibleSignature(); |
16333 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { | |
16334 return signature_function.UserVisibleSignature(); | |
16335 } | |
16336 return signature_function.InstantiatedSignatureFrom(args, | |
16337 name_visibility); | |
16338 } | 16284 } |
| 16285 // Instead of printing the actual signature, use the typedef name with |
| 16286 // its type arguments, if any. |
16339 class_name = cls.Name(); // Typedef name. | 16287 class_name = cls.Name(); // Typedef name. |
16340 // We may be reporting an error about a malformed function type. In that | 16288 // We may be reporting an error about a malformed function type. In that |
16341 // case, avoid instantiating the signature, since it may cause divergence. | 16289 // case, avoid instantiating the signature, since it may cause divergence. |
16342 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { | 16290 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { |
16343 return class_name.raw(); | 16291 return class_name.raw(); |
16344 } | 16292 } |
16345 // Print the name of a typedef as a regular, possibly parameterized, class. | 16293 // Print the name of a typedef as a regular, possibly parameterized, class. |
16346 } else if (HasResolvedTypeClass()) { | 16294 } else if (HasResolvedTypeClass()) { |
16347 cls = type_class(); | 16295 cls = type_class(); |
16348 } | 16296 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16615 if (other_is_dart_function_type || other.IsFunctionType()) { | 16563 if (other_is_dart_function_type || other.IsFunctionType()) { |
16616 if (IsFunctionType()) { | 16564 if (IsFunctionType()) { |
16617 if (other_is_dart_function_type) { | 16565 if (other_is_dart_function_type) { |
16618 return true; | 16566 return true; |
16619 } | 16567 } |
16620 const Function& other_fun = | 16568 const Function& other_fun = |
16621 Function::Handle(zone, Type::Cast(other).signature()); | 16569 Function::Handle(zone, Type::Cast(other).signature()); |
16622 // Check for two function types. | 16570 // Check for two function types. |
16623 const Function& fun = | 16571 const Function& fun = |
16624 Function::Handle(zone, Type::Cast(*this).signature()); | 16572 Function::Handle(zone, Type::Cast(*this).signature()); |
16625 return fun.TypeTest( | 16573 return fun.TypeTest(test_kind, other_fun, bound_error, space); |
16626 test_kind, TypeArguments::Handle(zone, arguments()), other_fun, | |
16627 TypeArguments::Handle(zone, other.arguments()), bound_error, space); | |
16628 } | 16574 } |
16629 // Check if type S has a call() method of function type T. | 16575 // Check if type S has a call() method of function type T. |
16630 const Function& call_function = | 16576 const Function& call_function = |
16631 Function::Handle(zone, type_cls.LookupCallFunctionForTypeTest()); | 16577 Function::Handle(zone, type_cls.LookupCallFunctionForTypeTest()); |
16632 if (!call_function.IsNull()) { | 16578 if (!call_function.IsNull()) { |
16633 if (other_is_dart_function_type || | 16579 if (other_is_dart_function_type || |
16634 call_function.TypeTest( | 16580 call_function.TypeTest( |
16635 test_kind, TypeArguments::Handle(zone, arguments()), | 16581 test_kind, Function::Handle(zone, Type::Cast(other).signature()), |
16636 Function::Handle(zone, Type::Cast(other).signature()), | 16582 bound_error, space)) { |
16637 TypeArguments::Handle(zone, other.arguments()), bound_error, | |
16638 space)) { | |
16639 return true; | 16583 return true; |
16640 } | 16584 } |
16641 } | 16585 } |
16642 } | 16586 } |
16643 if (IsFunctionType()) { | 16587 if (IsFunctionType()) { |
16644 return false; | 16588 return false; |
16645 } | 16589 } |
16646 return type_cls.TypeTest(test_kind, TypeArguments::Handle(zone, arguments()), | 16590 return type_cls.TypeTest(test_kind, TypeArguments::Handle(zone, arguments()), |
16647 Class::Handle(zone, other.type_class()), | 16591 Class::Handle(zone, other.type_class()), |
16648 TypeArguments::Handle(zone, other.arguments()), | 16592 TypeArguments::Handle(zone, other.arguments()), |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16904 | 16848 |
16905 | 16849 |
16906 bool Type::IsInstantiated(Genericity genericity, TrailPtr trail) const { | 16850 bool Type::IsInstantiated(Genericity genericity, TrailPtr trail) const { |
16907 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { | 16851 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { |
16908 return true; | 16852 return true; |
16909 } | 16853 } |
16910 if ((genericity == kAny) && | 16854 if ((genericity == kAny) && |
16911 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated)) { | 16855 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated)) { |
16912 return false; | 16856 return false; |
16913 } | 16857 } |
| 16858 if (IsFunctionType()) { |
| 16859 const Function& sig_fun = Function::Handle(signature()); |
| 16860 if (!sig_fun.HasInstantiatedSignature(genericity, trail)) { |
| 16861 return false; |
| 16862 } |
| 16863 // Because a generic typedef with an instantiated signature is considered |
| 16864 // uninstantiated, we still need to check the type arguments, even if the |
| 16865 // signature is instantiated. |
| 16866 } |
16914 if (arguments() == TypeArguments::null()) { | 16867 if (arguments() == TypeArguments::null()) { |
16915 return true; | 16868 return true; |
16916 } | 16869 } |
16917 const TypeArguments& args = TypeArguments::Handle(arguments()); | 16870 const TypeArguments& args = TypeArguments::Handle(arguments()); |
16918 intptr_t num_type_args = args.Length(); | 16871 intptr_t num_type_args = args.Length(); |
16919 intptr_t len = num_type_args; // Check the full vector of type args. | 16872 intptr_t len = num_type_args; // Check the full vector of type args. |
16920 ASSERT(num_type_args > 0); | 16873 ASSERT(num_type_args > 0); |
16921 // This type is not instantiated if it refers to type parameters. | 16874 // This type is not instantiated if it refers to type parameters. |
16922 // Although this type may still be unresolved, the type parameters it may | 16875 // Although this type may still be unresolved, the type parameters it may |
16923 // refer to are resolved by definition. We can therefore return the correct | 16876 // refer to are resolved by definition. We can therefore return the correct |
(...skipping 20 matching lines...) Expand all Loading... |
16944 ASSERT(!IsInstantiated()); | 16897 ASSERT(!IsInstantiated()); |
16945 // Return the uninstantiated type unchanged if malformed. No copy needed. | 16898 // Return the uninstantiated type unchanged if malformed. No copy needed. |
16946 if (IsMalformed()) { | 16899 if (IsMalformed()) { |
16947 return raw(); | 16900 return raw(); |
16948 } | 16901 } |
16949 // Note that the type class has to be resolved at this time, but not | 16902 // Note that the type class has to be resolved at this time, but not |
16950 // necessarily finalized yet. We may be checking bounds at compile time or | 16903 // necessarily finalized yet. We may be checking bounds at compile time or |
16951 // finalizing the type argument vector of a recursive type. | 16904 // finalizing the type argument vector of a recursive type. |
16952 const Class& cls = Class::Handle(zone, type_class()); | 16905 const Class& cls = Class::Handle(zone, type_class()); |
16953 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); | 16906 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); |
16954 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); | 16907 Function& sig_fun = Function::Handle(zone, signature()); |
16955 type_arguments = | 16908 if (!type_arguments.IsNull() && |
16956 type_arguments.InstantiateFrom(instantiator_type_arguments, bound_error, | 16909 (sig_fun.IsNull() || !type_arguments.IsInstantiated())) { |
16957 instantiation_trail, bound_trail, space); | 16910 // This type is uninstantiated because either its type arguments or its |
| 16911 // signature, or both are uninstantiated. |
| 16912 // Note that the type arguments of a function type merely document the |
| 16913 // parameterization of a generic typedef. They are otherwise ignored. |
| 16914 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); |
| 16915 type_arguments = |
| 16916 type_arguments.InstantiateFrom(instantiator_type_arguments, bound_error, |
| 16917 instantiation_trail, bound_trail, space); |
| 16918 } |
16958 // This uninstantiated type is not modified, as it can be instantiated | 16919 // This uninstantiated type is not modified, as it can be instantiated |
16959 // with different instantiators. Allocate a new instantiated version of it. | 16920 // with different instantiators. Allocate a new instantiated version of it. |
16960 const Type& instantiated_type = | 16921 const Type& instantiated_type = |
16961 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); | 16922 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); |
16962 // Preserve the bound error if any. | 16923 // Preserve the bound error if any. |
16963 if (IsMalbounded()) { | 16924 if (IsMalbounded()) { |
16964 const LanguageError& bound_error = LanguageError::Handle(zone, error()); | 16925 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
16965 instantiated_type.set_error(bound_error); | 16926 instantiated_type.set_error(bound_error); |
16966 } | 16927 } |
16967 // Preserve the signature if this type represents a function type. | 16928 // If this type is a function type, instantiate its signature. |
16968 // Note that the types in the signature remain unchanged. They get indirectly | |
16969 // instantiated by instantiating the type arguments above. | |
16970 const Function& sig_fun = Function::Handle(zone, signature()); | |
16971 if (!sig_fun.IsNull()) { | 16929 if (!sig_fun.IsNull()) { |
| 16930 // If we are finalizing a typedef, do not yet instantiate its signature. |
| 16931 // Other function types should never be instantiated while unfinalized. |
| 16932 if (IsFinalized()) { |
| 16933 // A generic typedef may actually declare an instantiated signature. |
| 16934 if (!sig_fun.HasInstantiatedSignature()) { |
| 16935 sig_fun = sig_fun.InstantiateSignatureFrom(instantiator_type_arguments, |
| 16936 space); |
| 16937 } |
| 16938 } else { |
| 16939 ASSERT(cls.IsTypedefClass()); |
| 16940 } |
16972 instantiated_type.set_signature(sig_fun); | 16941 instantiated_type.set_signature(sig_fun); |
16973 } | 16942 } |
16974 if (IsFinalized()) { | 16943 if (IsFinalized()) { |
16975 instantiated_type.SetIsFinalized(); | 16944 instantiated_type.SetIsFinalized(); |
16976 } else { | 16945 } else { |
16977 instantiated_type.SetIsResolved(); | 16946 instantiated_type.SetIsResolved(); |
16978 if (IsBeingFinalized()) { | 16947 if (IsBeingFinalized()) { |
16979 instantiated_type.SetIsBeingFinalized(); | 16948 instantiated_type.SetIsBeingFinalized(); |
16980 } | 16949 } |
16981 } | 16950 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17213 if (!clone.IsNull()) { | 17182 if (!clone.IsNull()) { |
17214 return clone.raw(); | 17183 return clone.raw(); |
17215 } | 17184 } |
17216 const Class& type_cls = Class::Handle(zone, type_class()); | 17185 const Class& type_cls = Class::Handle(zone, type_class()); |
17217 clone = Type::New(type_cls, TypeArguments::Handle(zone), token_pos()); | 17186 clone = Type::New(type_cls, TypeArguments::Handle(zone), token_pos()); |
17218 // Preserve the bound error if any. | 17187 // Preserve the bound error if any. |
17219 if (IsMalbounded()) { | 17188 if (IsMalbounded()) { |
17220 const LanguageError& bound_error = LanguageError::Handle(zone, error()); | 17189 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
17221 clone.set_error(bound_error); | 17190 clone.set_error(bound_error); |
17222 } | 17191 } |
17223 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | |
17224 bool type_args_cloned = false; | |
17225 // Clone the signature if this type represents a function type. | 17192 // Clone the signature if this type represents a function type. |
17226 const Function& fun = Function::Handle(zone, signature()); | 17193 const Function& fun = Function::Handle(zone, signature()); |
17227 if (!fun.IsNull()) { | 17194 if (!fun.IsNull()) { |
| 17195 ASSERT(type_cls.IsTypedefClass() || type_cls.IsClosureClass()); |
17228 // If the scope class is not a typedef and if it is generic, it must be the | 17196 // If the scope class is not a typedef and if it is generic, it must be the |
17229 // mixin class, set it to the new owner. | 17197 // mixin class, set it to the new owner. |
17230 if (!type_cls.IsTypedefClass() && type_cls.IsGeneric()) { | |
17231 clone.set_type_class(new_owner); | |
17232 AbstractType& decl_type = AbstractType::Handle(zone); | |
17233 #ifdef DEBUG | |
17234 decl_type = type_cls.DeclarationType(); | |
17235 ASSERT(decl_type.IsFinalized()); | |
17236 const TypeArguments& decl_type_args = | |
17237 TypeArguments::Handle(zone, decl_type.arguments()); | |
17238 ASSERT(type_args.Equals(decl_type_args)); | |
17239 #endif // DEBUG | |
17240 decl_type = new_owner.DeclarationType(); | |
17241 ASSERT(decl_type.IsFinalized()); | |
17242 type_args = decl_type.arguments(); | |
17243 clone.set_arguments(type_args); | |
17244 type_args_cloned = true; | |
17245 } | |
17246 Function& fun_clone = Function::Handle( | 17198 Function& fun_clone = Function::Handle( |
17247 zone, | 17199 zone, |
17248 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource)); | 17200 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource)); |
17249 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); | 17201 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); |
17250 type = type.CloneUninstantiated(new_owner, trail); | 17202 type = type.CloneUninstantiated(new_owner, trail); |
17251 fun_clone.set_result_type(type); | 17203 fun_clone.set_result_type(type); |
17252 const intptr_t num_params = fun.NumParameters(); | 17204 const intptr_t num_params = fun.NumParameters(); |
17253 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); | 17205 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); |
17254 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), | 17206 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), |
17255 fun.HasOptionalPositionalParameters()); | 17207 fun.HasOptionalPositionalParameters()); |
17256 fun_clone.set_parameter_types( | 17208 fun_clone.set_parameter_types( |
17257 Array::Handle(Array::New(num_params, Heap::kOld))); | 17209 Array::Handle(Array::New(num_params, Heap::kOld))); |
17258 for (intptr_t i = 0; i < num_params; i++) { | 17210 for (intptr_t i = 0; i < num_params; i++) { |
17259 type = fun.ParameterTypeAt(i); | 17211 type = fun.ParameterTypeAt(i); |
17260 type = type.CloneUninstantiated(new_owner, trail); | 17212 type = type.CloneUninstantiated(new_owner, trail); |
17261 fun_clone.SetParameterTypeAt(i, type); | 17213 fun_clone.SetParameterTypeAt(i, type); |
17262 } | 17214 } |
17263 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); | 17215 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
17264 clone.set_signature(fun_clone); | 17216 clone.set_signature(fun_clone); |
17265 } | 17217 } |
17266 if (!type_args_cloned) { | 17218 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
| 17219 if (!type_args.IsNull()) { |
17267 // Upper bounds of uninstantiated type arguments may form a cycle. | 17220 // Upper bounds of uninstantiated type arguments may form a cycle. |
17268 if (type_args.IsRecursive() || !type_args.IsInstantiated()) { | 17221 if (type_args.IsRecursive() || !type_args.IsInstantiated()) { |
17269 AddOnlyBuddyToTrail(&trail, clone); | 17222 AddOnlyBuddyToTrail(&trail, clone); |
17270 } | 17223 } |
17271 type_args = type_args.CloneUninstantiated(new_owner, trail); | 17224 type_args = type_args.CloneUninstantiated(new_owner, trail); |
17272 clone.set_arguments(type_args); | 17225 clone.set_arguments(type_args); |
17273 } | 17226 } |
17274 clone.SetIsFinalized(); | 17227 clone.SetIsFinalized(); |
17275 clone ^= clone.Canonicalize(); | 17228 clone ^= clone.Canonicalize(); |
17276 return clone.raw(); | 17229 return clone.raw(); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17584 Class& cls = Class::Handle(zone); | 17537 Class& cls = Class::Handle(zone); |
17585 const char* class_name; | 17538 const char* class_name; |
17586 if (HasResolvedTypeClass()) { | 17539 if (HasResolvedTypeClass()) { |
17587 cls = type_class(); | 17540 cls = type_class(); |
17588 class_name = String::Handle(zone, cls.Name()).ToCString(); | 17541 class_name = String::Handle(zone, cls.Name()).ToCString(); |
17589 } else { | 17542 } else { |
17590 class_name = UnresolvedClass::Handle(zone, unresolved_class()).ToCString(); | 17543 class_name = UnresolvedClass::Handle(zone, unresolved_class()).ToCString(); |
17591 } | 17544 } |
17592 if (IsFunctionType()) { | 17545 if (IsFunctionType()) { |
17593 const Function& sig_fun = Function::Handle(zone, signature()); | 17546 const Function& sig_fun = Function::Handle(zone, signature()); |
17594 const String& sig = | 17547 const String& sig = String::Handle(zone, sig_fun.Signature()); |
17595 IsFinalized() ? String::Handle(zone, sig_fun.InstantiatedSignatureFrom( | |
17596 type_args, kInternalName)) | |
17597 : String::Handle(zone, sig_fun.Signature()); | |
17598 if (cls.IsClosureClass()) { | 17548 if (cls.IsClosureClass()) { |
17599 ASSERT(type_args.IsNull()); | 17549 ASSERT(type_args.IsNull()); |
17600 return OS::SCreate(zone, "%sFunction Type: %s", unresolved, | 17550 return OS::SCreate(zone, "%sFunction Type: %s", unresolved, |
17601 sig.ToCString()); | 17551 sig.ToCString()); |
17602 } | 17552 } |
17603 return OS::SCreate(zone, "%s Function Type: %s (class: %s, args: %s)", | 17553 return OS::SCreate(zone, "%s Function Type: %s (class: %s, args: %s)", |
17604 unresolved, sig.ToCString(), class_name, args_cstr); | 17554 unresolved, sig.ToCString(), class_name, args_cstr); |
17605 } | 17555 } |
17606 if (type_args.IsNull()) { | 17556 if (type_args.IsNull()) { |
17607 return OS::SCreate(zone, "%sType: class '%s'", unresolved, class_name); | 17557 return OS::SCreate(zone, "%sType: class '%s'", unresolved, class_name); |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18252 if (!instantiated_bounded_type.IsFinalized() || | 18202 if (!instantiated_bounded_type.IsFinalized() || |
18253 !instantiated_upper_bound.IsFinalized() || | 18203 !instantiated_upper_bound.IsFinalized() || |
18254 (!type_param.CheckBound(instantiated_bounded_type, | 18204 (!type_param.CheckBound(instantiated_bounded_type, |
18255 instantiated_upper_bound, bound_error, | 18205 instantiated_upper_bound, bound_error, |
18256 bound_trail, space) && | 18206 bound_trail, space) && |
18257 bound_error->IsNull())) { | 18207 bound_error->IsNull())) { |
18258 // We cannot determine yet whether the bounded_type is below the | 18208 // We cannot determine yet whether the bounded_type is below the |
18259 // upper_bound, because one or both of them is still being finalized or | 18209 // upper_bound, because one or both of them is still being finalized or |
18260 // uninstantiated. For example, instantiated_bounded_type may be the | 18210 // uninstantiated. For example, instantiated_bounded_type may be the |
18261 // still unfinalized cloned type parameter of a mixin application class. | 18211 // still unfinalized cloned type parameter of a mixin application class. |
| 18212 // There is another special case where we do not want to report a bound |
| 18213 // error yet: if the upper bound is a function type, but the bounded |
| 18214 // type is not and its class is not compiled yet, i.e. we cannot look |
| 18215 // for a call method yet. |
18262 ASSERT(instantiated_bounded_type.IsBeingFinalized() || | 18216 ASSERT(instantiated_bounded_type.IsBeingFinalized() || |
18263 instantiated_upper_bound.IsBeingFinalized() || | 18217 instantiated_upper_bound.IsBeingFinalized() || |
18264 !instantiated_bounded_type.IsInstantiated() || | 18218 !instantiated_bounded_type.IsInstantiated() || |
18265 !instantiated_upper_bound.IsInstantiated()); | 18219 !instantiated_upper_bound.IsInstantiated() || |
| 18220 (!instantiated_bounded_type.IsFunctionType() && |
| 18221 instantiated_upper_bound.IsFunctionType() && |
| 18222 instantiated_bounded_type.HasResolvedTypeClass() && |
| 18223 !Class::Handle(instantiated_bounded_type.type_class()) |
| 18224 .is_finalized())); |
18266 // Postpone bound check by returning a new BoundedType with unfinalized | 18225 // Postpone bound check by returning a new BoundedType with unfinalized |
18267 // or partially instantiated bounded_type and upper_bound, but keeping | 18226 // or partially instantiated bounded_type and upper_bound, but keeping |
18268 // type_param. | 18227 // type_param. |
18269 instantiated_bounded_type = BoundedType::New( | 18228 instantiated_bounded_type = BoundedType::New( |
18270 instantiated_bounded_type, instantiated_upper_bound, type_param); | 18229 instantiated_bounded_type, instantiated_upper_bound, type_param); |
18271 } | 18230 } |
18272 } | 18231 } |
18273 } | 18232 } |
18274 return instantiated_bounded_type.raw(); | 18233 return instantiated_bounded_type.raw(); |
18275 } | 18234 } |
(...skipping 4844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23120 return UserTag::null(); | 23079 return UserTag::null(); |
23121 } | 23080 } |
23122 | 23081 |
23123 | 23082 |
23124 const char* UserTag::ToCString() const { | 23083 const char* UserTag::ToCString() const { |
23125 const String& tag_label = String::Handle(label()); | 23084 const String& tag_label = String::Handle(label()); |
23126 return tag_label.ToCString(); | 23085 return tag_label.ToCString(); |
23127 } | 23086 } |
23128 | 23087 |
23129 } // namespace dart | 23088 } // namespace dart |
OLD | NEW |