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 3880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3891 // This type class implements an interface that is parameterized with | 3891 // This type class implements an interface that is parameterized with |
3892 // generic type(s), e.g. it implements List<T>. | 3892 // generic type(s), e.g. it implements List<T>. |
3893 // The uninstantiated type T must be instantiated using the type | 3893 // The uninstantiated type T must be instantiated using the type |
3894 // parameters of this type before performing the type test. | 3894 // parameters of this type before performing the type test. |
3895 // The type arguments of this type that are referred to by the type | 3895 // The type arguments of this type that are referred to by the type |
3896 // parameters of the interface are at the end of the type vector, | 3896 // parameters of the interface are at the end of the type vector, |
3897 // after the type arguments of the super type of this type. | 3897 // after the type arguments of the super type of this type. |
3898 // The index of the type parameters is adjusted upon finalization. | 3898 // The index of the type parameters is adjusted upon finalization. |
3899 error = Error::null(); | 3899 error = Error::null(); |
3900 interface_args = interface_args.InstantiateFrom( | 3900 interface_args = interface_args.InstantiateFrom( |
3901 type_arguments, &error, NULL, bound_trail, space); | 3901 type_arguments, Object::null_type_arguments(), &error, NULL, |
| 3902 bound_trail, space); |
3902 if (!error.IsNull()) { | 3903 if (!error.IsNull()) { |
3903 // Return the first bound error to the caller if it requests it. | 3904 // Return the first bound error to the caller if it requests it. |
3904 if ((bound_error != NULL) && bound_error->IsNull()) { | 3905 if ((bound_error != NULL) && bound_error->IsNull()) { |
3905 *bound_error = error.raw(); | 3906 *bound_error = error.raw(); |
3906 } | 3907 } |
3907 continue; // Another interface may work better. | 3908 continue; // Another interface may work better. |
3908 } | 3909 } |
3909 } | 3910 } |
3910 if (interface_class.TypeTest(test_kind, interface_args, other, | 3911 if (interface_class.TypeTest(test_kind, interface_args, other, |
3911 other_type_arguments, bound_error, | 3912 other_type_arguments, bound_error, |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4709 bool TypeArguments::IsDynamicTypes(bool raw_instantiated, | 4710 bool TypeArguments::IsDynamicTypes(bool raw_instantiated, |
4710 intptr_t from_index, | 4711 intptr_t from_index, |
4711 intptr_t len) const { | 4712 intptr_t len) const { |
4712 ASSERT(Length() >= (from_index + len)); | 4713 ASSERT(Length() >= (from_index + len)); |
4713 AbstractType& type = AbstractType::Handle(); | 4714 AbstractType& type = AbstractType::Handle(); |
4714 Class& type_class = Class::Handle(); | 4715 Class& type_class = Class::Handle(); |
4715 for (intptr_t i = 0; i < len; i++) { | 4716 for (intptr_t i = 0; i < len; i++) { |
4716 type = TypeAt(from_index + i); | 4717 type = TypeAt(from_index + i); |
4717 if (!type.HasResolvedTypeClass()) { | 4718 if (!type.HasResolvedTypeClass()) { |
4718 if (raw_instantiated && type.IsTypeParameter()) { | 4719 if (raw_instantiated && type.IsTypeParameter()) { |
4719 // An uninstantiated type parameter is equivalent to dynamic (even in | 4720 const TypeParameter& type_param = TypeParameter::Cast(type); |
4720 // the presence of a malformed bound in checked mode). | 4721 if (type_param.IsClassTypeParameter() || |
4721 continue; | 4722 (type_param.IsFunctionTypeParameter() && |
| 4723 type_param.parent_level() == 0)) { |
| 4724 // An uninstantiated type parameter is equivalent to dynamic (even in |
| 4725 // the presence of a malformed bound in checked mode). |
| 4726 continue; |
| 4727 } |
4722 } | 4728 } |
4723 return false; | 4729 return false; |
4724 } | 4730 } |
4725 type_class = type.type_class(); | 4731 type_class = type.type_class(); |
4726 if (!type_class.IsDynamicClass()) { | 4732 if (!type_class.IsDynamicClass()) { |
4727 return false; | 4733 return false; |
4728 } | 4734 } |
4729 } | 4735 } |
4730 return true; | 4736 return true; |
4731 } | 4737 } |
(...skipping 28 matching lines...) Expand all Loading... |
4760 bool TypeArguments::HasInstantiations() const { | 4766 bool TypeArguments::HasInstantiations() const { |
4761 const Array& prior_instantiations = Array::Handle(instantiations()); | 4767 const Array& prior_instantiations = Array::Handle(instantiations()); |
4762 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. | 4768 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. |
4763 return prior_instantiations.Length() > 1; | 4769 return prior_instantiations.Length() > 1; |
4764 } | 4770 } |
4765 | 4771 |
4766 | 4772 |
4767 intptr_t TypeArguments::NumInstantiations() const { | 4773 intptr_t TypeArguments::NumInstantiations() const { |
4768 const Array& prior_instantiations = Array::Handle(instantiations()); | 4774 const Array& prior_instantiations = Array::Handle(instantiations()); |
4769 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. | 4775 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. |
| 4776 intptr_t num = 0; |
4770 intptr_t i = 0; | 4777 intptr_t i = 0; |
4771 while (prior_instantiations.At(i) != Smi::New(StubCode::kNoInstantiator)) { | 4778 while (prior_instantiations.At(i) != Smi::New(StubCode::kNoInstantiator)) { |
4772 i += 2; | 4779 i += StubCode::kInstantiationSizeInWords; |
| 4780 num++; |
4773 } | 4781 } |
4774 return i / 2; | 4782 return num; |
4775 } | 4783 } |
4776 | 4784 |
4777 | 4785 |
4778 RawArray* TypeArguments::instantiations() const { | 4786 RawArray* TypeArguments::instantiations() const { |
4779 return raw_ptr()->instantiations_; | 4787 return raw_ptr()->instantiations_; |
4780 } | 4788 } |
4781 | 4789 |
4782 | 4790 |
4783 void TypeArguments::set_instantiations(const Array& value) const { | 4791 void TypeArguments::set_instantiations(const Array& value) const { |
4784 ASSERT(!value.IsNull()); | 4792 ASSERT(!value.IsNull()); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4973 if (!type_args.IsNull() && type_args.IsBounded()) { | 4981 if (!type_args.IsNull() && type_args.IsBounded()) { |
4974 return true; | 4982 return true; |
4975 } | 4983 } |
4976 } | 4984 } |
4977 return false; | 4985 return false; |
4978 } | 4986 } |
4979 | 4987 |
4980 | 4988 |
4981 RawTypeArguments* TypeArguments::InstantiateFrom( | 4989 RawTypeArguments* TypeArguments::InstantiateFrom( |
4982 const TypeArguments& instantiator_type_arguments, | 4990 const TypeArguments& instantiator_type_arguments, |
| 4991 const TypeArguments& function_type_arguments, |
4983 Error* bound_error, | 4992 Error* bound_error, |
4984 TrailPtr instantiation_trail, | 4993 TrailPtr instantiation_trail, |
4985 TrailPtr bound_trail, | 4994 TrailPtr bound_trail, |
4986 Heap::Space space) const { | 4995 Heap::Space space) const { |
4987 ASSERT(!IsInstantiated()); | 4996 ASSERT(!IsInstantiated()); |
4988 if (!instantiator_type_arguments.IsNull() && IsUninstantiatedIdentity() && | 4997 if (!instantiator_type_arguments.IsNull() && IsUninstantiatedIdentity() && |
4989 (instantiator_type_arguments.Length() == Length())) { | 4998 (instantiator_type_arguments.Length() == Length())) { |
4990 return instantiator_type_arguments.raw(); | 4999 return instantiator_type_arguments.raw(); |
4991 } | 5000 } |
4992 const intptr_t num_types = Length(); | 5001 const intptr_t num_types = Length(); |
4993 TypeArguments& instantiated_array = | 5002 TypeArguments& instantiated_array = |
4994 TypeArguments::Handle(TypeArguments::New(num_types, space)); | 5003 TypeArguments::Handle(TypeArguments::New(num_types, space)); |
4995 AbstractType& type = AbstractType::Handle(); | 5004 AbstractType& type = AbstractType::Handle(); |
4996 for (intptr_t i = 0; i < num_types; i++) { | 5005 for (intptr_t i = 0; i < num_types; i++) { |
4997 type = TypeAt(i); | 5006 type = TypeAt(i); |
4998 // If this type argument T is null, the type A containing T in its flattened | 5007 // If this type argument T is null, the type A containing T in its flattened |
4999 // type argument vector V is recursive and is still being finalized. | 5008 // type argument vector V is recursive and is still being finalized. |
5000 // T is the type argument of a super type of A. T is being instantiated | 5009 // T is the type argument of a super type of A. T is being instantiated |
5001 // during finalization of V, which is also the instantiator. T depends | 5010 // during finalization of V, which is also the instantiator. T depends |
5002 // solely on the type parameters of A and will be replaced by a non-null | 5011 // solely on the type parameters of A and will be replaced by a non-null |
5003 // type before A is marked as finalized. | 5012 // type before A is marked as finalized. |
5004 if (!type.IsNull() && !type.IsInstantiated()) { | 5013 if (!type.IsNull() && !type.IsInstantiated()) { |
5005 type = type.InstantiateFrom(instantiator_type_arguments, bound_error, | 5014 type = type.InstantiateFrom(instantiator_type_arguments, |
| 5015 function_type_arguments, bound_error, |
5006 instantiation_trail, bound_trail, space); | 5016 instantiation_trail, bound_trail, space); |
5007 } | 5017 } |
5008 instantiated_array.SetTypeAt(i, type); | 5018 instantiated_array.SetTypeAt(i, type); |
5009 } | 5019 } |
5010 return instantiated_array.raw(); | 5020 return instantiated_array.raw(); |
5011 } | 5021 } |
5012 | 5022 |
5013 | 5023 |
5014 RawTypeArguments* TypeArguments::InstantiateAndCanonicalizeFrom( | 5024 RawTypeArguments* TypeArguments::InstantiateAndCanonicalizeFrom( |
5015 const TypeArguments& instantiator_type_arguments, | 5025 const TypeArguments& instantiator_type_arguments, |
| 5026 const TypeArguments& function_type_arguments, |
5016 Error* bound_error) const { | 5027 Error* bound_error) const { |
5017 ASSERT(!IsInstantiated()); | 5028 ASSERT(!IsInstantiated()); |
5018 ASSERT(instantiator_type_arguments.IsNull() || | 5029 ASSERT(instantiator_type_arguments.IsNull() || |
5019 instantiator_type_arguments.IsCanonical()); | 5030 instantiator_type_arguments.IsCanonical()); |
| 5031 ASSERT(function_type_arguments.IsNull() || |
| 5032 function_type_arguments.IsCanonical()); |
5020 // Lookup instantiator and, if found, return paired instantiated result. | 5033 // Lookup instantiator and, if found, return paired instantiated result. |
5021 Array& prior_instantiations = Array::Handle(instantiations()); | 5034 Array& prior_instantiations = Array::Handle(instantiations()); |
5022 ASSERT(!prior_instantiations.IsNull() && prior_instantiations.IsArray()); | 5035 ASSERT(!prior_instantiations.IsNull() && prior_instantiations.IsArray()); |
5023 // The instantiations cache is initialized with Object::zero_array() and is | 5036 // The instantiations cache is initialized with Object::zero_array() and is |
5024 // therefore guaranteed to contain kNoInstantiator. No length check needed. | 5037 // therefore guaranteed to contain kNoInstantiator. No length check needed. |
5025 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. | 5038 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. |
5026 intptr_t index = 0; | 5039 intptr_t index = 0; |
5027 while (true) { | 5040 while (true) { |
5028 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) { | 5041 if ((prior_instantiations.At(index) == instantiator_type_arguments.raw()) && |
5029 return TypeArguments::RawCast(prior_instantiations.At(index + 1)); | 5042 (prior_instantiations.At(index + 1) == function_type_arguments.raw())) { |
| 5043 return TypeArguments::RawCast(prior_instantiations.At(index + 2)); |
5030 } | 5044 } |
5031 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { | 5045 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { |
5032 break; | 5046 break; |
5033 } | 5047 } |
5034 index += 2; | 5048 index += StubCode::kInstantiationSizeInWords; |
5035 } | 5049 } |
5036 // Cache lookup failed. Instantiate the type arguments. | 5050 // Cache lookup failed. Instantiate the type arguments. |
5037 TypeArguments& result = TypeArguments::Handle(); | 5051 TypeArguments& result = TypeArguments::Handle(); |
5038 result = InstantiateFrom(instantiator_type_arguments, bound_error, NULL, NULL, | 5052 result = InstantiateFrom(instantiator_type_arguments, function_type_arguments, |
5039 Heap::kOld); | 5053 bound_error, NULL, NULL, Heap::kOld); |
5040 if ((bound_error != NULL) && !bound_error->IsNull()) { | 5054 if ((bound_error != NULL) && !bound_error->IsNull()) { |
5041 return result.raw(); | 5055 return result.raw(); |
5042 } | 5056 } |
5043 // Instantiation did not result in bound error. Canonicalize type arguments. | 5057 // Instantiation did not result in bound error. Canonicalize type arguments. |
5044 result = result.Canonicalize(); | 5058 result = result.Canonicalize(); |
5045 // InstantiateAndCanonicalizeFrom is not reentrant. It cannot have been called | 5059 // InstantiateAndCanonicalizeFrom is not reentrant. It cannot have been called |
5046 // indirectly, so the prior_instantiations array cannot have grown. | 5060 // indirectly, so the prior_instantiations array cannot have grown. |
5047 ASSERT(prior_instantiations.raw() == instantiations()); | 5061 ASSERT(prior_instantiations.raw() == instantiations()); |
5048 // Add instantiator and result to instantiations array. | 5062 // Do not cache result if the context is required to instantiate the |
| 5063 // type arguments, i.e. they refer to the type parameters of parent functions. |
| 5064 if (!IsInstantiated(kParentFunctions)) { |
| 5065 return result.raw(); |
| 5066 } |
| 5067 // Add instantiator and function type args and result to instantiations array. |
5049 intptr_t length = prior_instantiations.Length(); | 5068 intptr_t length = prior_instantiations.Length(); |
5050 if ((index + 2) >= length) { | 5069 if ((index + StubCode::kInstantiationSizeInWords) >= length) { |
| 5070 // TODO(regis): Should we limit the number of cached instantiations? |
5051 // Grow the instantiations array. | 5071 // Grow the instantiations array. |
5052 // The initial array is Object::zero_array() of length 1. | 5072 // The initial array is Object::zero_array() of length 1. |
5053 length = (length > 64) ? (length + 64) | 5073 length = (length > 64) |
5054 : ((length == 1) ? 3 : ((length - 1) * 2 + 1)); | 5074 ? (length + 64) |
| 5075 : ((length == 1) ? StubCode::kInstantiationSizeInWords + 1 |
| 5076 : ((length - 1) * 2 + 1)); |
5055 prior_instantiations = | 5077 prior_instantiations = |
5056 Array::Grow(prior_instantiations, length, Heap::kOld); | 5078 Array::Grow(prior_instantiations, length, Heap::kOld); |
5057 set_instantiations(prior_instantiations); | 5079 set_instantiations(prior_instantiations); |
5058 ASSERT((index + 2) < length); | 5080 ASSERT((index + StubCode::kInstantiationSizeInWords) < length); |
5059 } | 5081 } |
5060 prior_instantiations.SetAt(index, instantiator_type_arguments); | 5082 prior_instantiations.SetAt(index + 0, instantiator_type_arguments); |
5061 prior_instantiations.SetAt(index + 1, result); | 5083 prior_instantiations.SetAt(index + 1, function_type_arguments); |
5062 prior_instantiations.SetAt(index + 2, | 5084 prior_instantiations.SetAt(index + 2, result); |
| 5085 prior_instantiations.SetAt(index + 3, |
5063 Smi::Handle(Smi::New(StubCode::kNoInstantiator))); | 5086 Smi::Handle(Smi::New(StubCode::kNoInstantiator))); |
5064 return result.raw(); | 5087 return result.raw(); |
5065 } | 5088 } |
5066 | 5089 |
5067 | 5090 |
5068 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { | 5091 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { |
5069 if (len < 0 || len > kMaxElements) { | 5092 if (len < 0 || len > kMaxElements) { |
5070 // This should be caught before we reach here. | 5093 // This should be caught before we reach here. |
5071 FATAL1("Fatal error in TypeArguments::New: invalid len %" Pd "\n", len); | 5094 FATAL1("Fatal error in TypeArguments::New: invalid len %" Pd "\n", len); |
5072 } | 5095 } |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5953 } | 5976 } |
5954 | 5977 |
5955 | 5978 |
5956 intptr_t Function::NumTypeParameters(Thread* thread) const { | 5979 intptr_t Function::NumTypeParameters(Thread* thread) const { |
5957 if (type_parameters() == TypeArguments::null()) { | 5980 if (type_parameters() == TypeArguments::null()) { |
5958 return 0; | 5981 return 0; |
5959 } | 5982 } |
5960 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 5983 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
5961 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 5984 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
5962 type_params = type_parameters(); | 5985 type_params = type_parameters(); |
| 5986 // We require null to represent a non-generic function. |
| 5987 ASSERT(type_params.Length() != 0); |
5963 return type_params.Length(); | 5988 return type_params.Length(); |
5964 } | 5989 } |
5965 | 5990 |
5966 | 5991 |
5967 RawTypeParameter* Function::LookupTypeParameter( | 5992 RawTypeParameter* Function::LookupTypeParameter( |
5968 const String& type_name, | 5993 const String& type_name, |
5969 intptr_t* function_level) const { | 5994 intptr_t* function_level) const { |
5970 ASSERT(!type_name.IsNull()); | 5995 ASSERT(!type_name.IsNull()); |
5971 Thread* thread = Thread::Current(); | 5996 Thread* thread = Thread::Current(); |
5972 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 5997 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6380 ASSERT(Isolate::Current()->error_on_bad_override()); | 6405 ASSERT(Isolate::Current()->error_on_bad_override()); |
6381 ASSERT((bound_error != NULL) && bound_error->IsNull()); | 6406 ASSERT((bound_error != NULL) && bound_error->IsNull()); |
6382 // Check that this function's signature type is a subtype of the other | 6407 // Check that this function's signature type is a subtype of the other |
6383 // function's signature type. | 6408 // function's signature type. |
6384 // Map type parameters in the signature to dynamic before the test. | 6409 // Map type parameters in the signature to dynamic before the test. |
6385 Function& this_fun = Function::Handle(raw()); | 6410 Function& this_fun = Function::Handle(raw()); |
6386 if (!this_fun.HasInstantiatedSignature()) { | 6411 if (!this_fun.HasInstantiatedSignature()) { |
6387 // TODO(regis): Should we pass the context explicitly here (i.e. null) once | 6412 // TODO(regis): Should we pass the context explicitly here (i.e. null) once |
6388 // we support generic functions? | 6413 // we support generic functions? |
6389 this_fun = this_fun.InstantiateSignatureFrom(Object::null_type_arguments(), | 6414 this_fun = this_fun.InstantiateSignatureFrom(Object::null_type_arguments(), |
| 6415 Object::null_type_arguments(), |
6390 Heap::kOld); | 6416 Heap::kOld); |
6391 } | 6417 } |
6392 Function& other_fun = Function::Handle(other.raw()); | 6418 Function& other_fun = Function::Handle(other.raw()); |
6393 if (!other_fun.HasInstantiatedSignature()) { | 6419 if (!other_fun.HasInstantiatedSignature()) { |
6394 // TODO(regis): Should we pass the context explicitly here (i.e. null) once | 6420 // TODO(regis): Should we pass the context explicitly here (i.e. null) once |
6395 // we support generic functions? | 6421 // we support generic functions? |
6396 other_fun = other_fun.InstantiateSignatureFrom( | 6422 other_fun = other_fun.InstantiateSignatureFrom( |
6397 Object::null_type_arguments(), Heap::kOld); | 6423 Object::null_type_arguments(), Object::null_type_arguments(), |
| 6424 Heap::kOld); |
6398 } | 6425 } |
6399 if (!this_fun.TypeTest(kIsSubtypeOf, other_fun, bound_error, Heap::kOld)) { | 6426 if (!this_fun.TypeTest(kIsSubtypeOf, other_fun, bound_error, Heap::kOld)) { |
6400 // For more informative error reporting, use the location of the other | 6427 // For more informative error reporting, use the location of the other |
6401 // function here, since the caller will use the location of this function. | 6428 // function here, since the caller will use the location of this function. |
6402 *bound_error = LanguageError::NewFormatted( | 6429 *bound_error = LanguageError::NewFormatted( |
6403 *bound_error, // A bound error if non null. | 6430 *bound_error, // A bound error if non null. |
6404 Script::Handle(other.script()), other.token_pos(), Report::AtLocation, | 6431 Script::Handle(other.script()), other.token_pos(), Report::AtLocation, |
6405 Report::kError, Heap::kNew, | 6432 Report::kError, Heap::kNew, |
6406 "signature type '%s' of function '%s' is not a subtype of signature " | 6433 "signature type '%s' of function '%s' is not a subtype of signature " |
6407 "type '%s' of function '%s'\n", | 6434 "type '%s' of function '%s'\n", |
6408 String::Handle(UserVisibleSignature()).ToCString(), | 6435 String::Handle(UserVisibleSignature()).ToCString(), |
6409 String::Handle(UserVisibleName()).ToCString(), | 6436 String::Handle(UserVisibleName()).ToCString(), |
6410 String::Handle(other.UserVisibleSignature()).ToCString(), | 6437 String::Handle(other.UserVisibleSignature()).ToCString(), |
6411 String::Handle(other.UserVisibleName()).ToCString()); | 6438 String::Handle(other.UserVisibleName()).ToCString()); |
6412 return false; | 6439 return false; |
6413 } | 6440 } |
6414 // We should also check that if the other function explicitly specifies a | 6441 // We should also check that if the other function explicitly specifies a |
6415 // default value for a formal parameter, this function does not specify a | 6442 // default value for a formal parameter, this function does not specify a |
6416 // different default value for the same parameter. However, this check is not | 6443 // different default value for the same parameter. However, this check is not |
6417 // possible in the current implementation, because the default parameter | 6444 // possible in the current implementation, because the default parameter |
6418 // values are not stored in the Function object, but discarded after a | 6445 // values are not stored in the Function object, but discarded after a |
6419 // function is compiled. | 6446 // function is compiled. |
6420 return true; | 6447 return true; |
6421 } | 6448 } |
6422 | 6449 |
6423 | 6450 |
6424 RawFunction* Function::InstantiateSignatureFrom( | 6451 RawFunction* Function::InstantiateSignatureFrom( |
6425 const TypeArguments& instantiator_type_arguments, | 6452 const TypeArguments& instantiator_type_arguments, |
| 6453 const TypeArguments& function_type_arguments, |
6426 Heap::Space space) const { | 6454 Heap::Space space) const { |
6427 Zone* zone = Thread::Current()->zone(); | 6455 Zone* zone = Thread::Current()->zone(); |
6428 const Object& owner = Object::Handle(zone, RawOwner()); | 6456 const Object& owner = Object::Handle(zone, RawOwner()); |
6429 // TODO(regis): Should we change Function::New() to accept a space, since | 6457 // TODO(regis): Should we change Function::New() to accept a space, since |
6430 // InstantiateFrom is sometimes called with Heap::kNew? | 6458 // InstantiateFrom is sometimes called with Heap::kNew? |
6431 ASSERT(!HasInstantiatedSignature()); | 6459 ASSERT(!HasInstantiatedSignature()); |
6432 Function& sig = Function::Handle( | 6460 Function& sig = Function::Handle( |
6433 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); | 6461 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); |
6434 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); | 6462 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); |
6435 AbstractType& type = AbstractType::Handle(zone, result_type()); | 6463 AbstractType& type = AbstractType::Handle(zone, result_type()); |
6436 if (!type.IsInstantiated()) { | 6464 if (!type.IsInstantiated()) { |
6437 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL, | 6465 type = |
6438 space); | 6466 type.InstantiateFrom(instantiator_type_arguments, |
| 6467 function_type_arguments, NULL, NULL, NULL, space); |
6439 } | 6468 } |
6440 sig.set_result_type(type); | 6469 sig.set_result_type(type); |
6441 const intptr_t num_params = NumParameters(); | 6470 const intptr_t num_params = NumParameters(); |
6442 sig.set_num_fixed_parameters(num_fixed_parameters()); | 6471 sig.set_num_fixed_parameters(num_fixed_parameters()); |
6443 sig.SetNumOptionalParameters(NumOptionalParameters(), | 6472 sig.SetNumOptionalParameters(NumOptionalParameters(), |
6444 HasOptionalPositionalParameters()); | 6473 HasOptionalPositionalParameters()); |
6445 sig.set_parameter_types(Array::Handle(Array::New(num_params, space))); | 6474 sig.set_parameter_types(Array::Handle(Array::New(num_params, space))); |
6446 for (intptr_t i = 0; i < num_params; i++) { | 6475 for (intptr_t i = 0; i < num_params; i++) { |
6447 type = ParameterTypeAt(i); | 6476 type = ParameterTypeAt(i); |
6448 if (!type.IsInstantiated()) { | 6477 if (!type.IsInstantiated()) { |
6449 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL, | 6478 type = type.InstantiateFrom(instantiator_type_arguments, |
| 6479 function_type_arguments, NULL, NULL, NULL, |
6450 space); | 6480 space); |
6451 } | 6481 } |
6452 sig.SetParameterTypeAt(i, type); | 6482 sig.SetParameterTypeAt(i, type); |
6453 } | 6483 } |
6454 sig.set_parameter_names(Array::Handle(zone, parameter_names())); | 6484 sig.set_parameter_names(Array::Handle(zone, parameter_names())); |
6455 return sig.raw(); | 6485 return sig.raw(); |
6456 } | 6486 } |
6457 | 6487 |
6458 | 6488 |
6459 // If test_kind == kIsSubtypeOf, checks if the type of the specified parameter | 6489 // If test_kind == kIsSubtypeOf, checks if the type of the specified parameter |
(...skipping 8612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15072 NoSafepointScope no_safepoint; | 15102 NoSafepointScope no_safepoint; |
15073 // Do not count the sentinel; | 15103 // Do not count the sentinel; |
15074 return (Smi::Value(cache()->ptr()->length_) / kTestEntryLength) - 1; | 15104 return (Smi::Value(cache()->ptr()->length_) / kTestEntryLength) - 1; |
15075 } | 15105 } |
15076 | 15106 |
15077 | 15107 |
15078 void SubtypeTestCache::AddCheck( | 15108 void SubtypeTestCache::AddCheck( |
15079 const Object& instance_class_id_or_function, | 15109 const Object& instance_class_id_or_function, |
15080 const TypeArguments& instance_type_arguments, | 15110 const TypeArguments& instance_type_arguments, |
15081 const TypeArguments& instantiator_type_arguments, | 15111 const TypeArguments& instantiator_type_arguments, |
| 15112 const TypeArguments& function_type_arguments, |
15082 const Bool& test_result) const { | 15113 const Bool& test_result) const { |
15083 intptr_t old_num = NumberOfChecks(); | 15114 intptr_t old_num = NumberOfChecks(); |
15084 Array& data = Array::Handle(cache()); | 15115 Array& data = Array::Handle(cache()); |
15085 intptr_t new_len = data.Length() + kTestEntryLength; | 15116 intptr_t new_len = data.Length() + kTestEntryLength; |
15086 data = Array::Grow(data, new_len); | 15117 data = Array::Grow(data, new_len); |
15087 set_cache(data); | 15118 set_cache(data); |
15088 intptr_t data_pos = old_num * kTestEntryLength; | 15119 intptr_t data_pos = old_num * kTestEntryLength; |
15089 data.SetAt(data_pos + kInstanceClassIdOrFunction, | 15120 data.SetAt(data_pos + kInstanceClassIdOrFunction, |
15090 instance_class_id_or_function); | 15121 instance_class_id_or_function); |
15091 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments); | 15122 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments); |
15092 data.SetAt(data_pos + kInstantiatorTypeArguments, | 15123 data.SetAt(data_pos + kInstantiatorTypeArguments, |
15093 instantiator_type_arguments); | 15124 instantiator_type_arguments); |
| 15125 data.SetAt(data_pos + kFunctionTypeArguments, function_type_arguments); |
15094 data.SetAt(data_pos + kTestResult, test_result); | 15126 data.SetAt(data_pos + kTestResult, test_result); |
15095 } | 15127 } |
15096 | 15128 |
15097 | 15129 |
15098 void SubtypeTestCache::GetCheck(intptr_t ix, | 15130 void SubtypeTestCache::GetCheck(intptr_t ix, |
15099 Object* instance_class_id_or_function, | 15131 Object* instance_class_id_or_function, |
15100 TypeArguments* instance_type_arguments, | 15132 TypeArguments* instance_type_arguments, |
15101 TypeArguments* instantiator_type_arguments, | 15133 TypeArguments* instantiator_type_arguments, |
| 15134 TypeArguments* function_type_arguments, |
15102 Bool* test_result) const { | 15135 Bool* test_result) const { |
15103 Array& data = Array::Handle(cache()); | 15136 Array& data = Array::Handle(cache()); |
15104 intptr_t data_pos = ix * kTestEntryLength; | 15137 intptr_t data_pos = ix * kTestEntryLength; |
15105 *instance_class_id_or_function = | 15138 *instance_class_id_or_function = |
15106 data.At(data_pos + kInstanceClassIdOrFunction); | 15139 data.At(data_pos + kInstanceClassIdOrFunction); |
15107 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); | 15140 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); |
15108 *instantiator_type_arguments ^= | 15141 *instantiator_type_arguments ^= |
15109 data.At(data_pos + kInstantiatorTypeArguments); | 15142 data.At(data_pos + kInstantiatorTypeArguments); |
| 15143 *function_type_arguments ^= data.At(data_pos + kFunctionTypeArguments); |
15110 *test_result ^= data.At(data_pos + kTestResult); | 15144 *test_result ^= data.At(data_pos + kTestResult); |
15111 } | 15145 } |
15112 | 15146 |
15113 | 15147 |
15114 const char* SubtypeTestCache::ToCString() const { | 15148 const char* SubtypeTestCache::ToCString() const { |
15115 return "SubtypeTestCache"; | 15149 return "SubtypeTestCache"; |
15116 } | 15150 } |
15117 | 15151 |
15118 | 15152 |
15119 const char* Error::ToErrorCString() const { | 15153 const char* Error::ToErrorCString() const { |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15609 return Type::NullType(); | 15643 return Type::NullType(); |
15610 } | 15644 } |
15611 const Class& cls = Class::Handle(clazz()); | 15645 const Class& cls = Class::Handle(clazz()); |
15612 if (cls.IsClosureClass()) { | 15646 if (cls.IsClosureClass()) { |
15613 const Function& signature = | 15647 const Function& signature = |
15614 Function::Handle(Closure::Cast(*this).function()); | 15648 Function::Handle(Closure::Cast(*this).function()); |
15615 Type& type = Type::Handle(signature.SignatureType()); | 15649 Type& type = Type::Handle(signature.SignatureType()); |
15616 if (!type.IsInstantiated()) { | 15650 if (!type.IsInstantiated()) { |
15617 TypeArguments& instantiator_type_arguments = | 15651 TypeArguments& instantiator_type_arguments = |
15618 TypeArguments::Handle(Closure::Cast(*this).instantiator()); | 15652 TypeArguments::Handle(Closure::Cast(*this).instantiator()); |
15619 // TODO(regis): Should we pass the context explicitly here (i.e. null) | 15653 const TypeArguments& function_type_arguments = |
15620 // once we support generic functions? | 15654 TypeArguments::Handle(signature.type_parameters()); |
15621 type ^= type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, | 15655 // TODO(regis): Pass the closure context to InstantiateSignatureFrom(). |
15622 NULL, space); | 15656 // No bound error possible, since the instance exists. |
| 15657 type ^= type.InstantiateFrom(instantiator_type_arguments, |
| 15658 function_type_arguments, NULL, NULL, NULL, |
| 15659 space); |
15623 } | 15660 } |
15624 type ^= type.Canonicalize(); | 15661 type ^= type.Canonicalize(); |
15625 return type.raw(); | 15662 return type.raw(); |
15626 } | 15663 } |
15627 Type& type = Type::Handle(); | 15664 Type& type = Type::Handle(); |
15628 if (!cls.IsGeneric()) { | 15665 if (!cls.IsGeneric()) { |
15629 type = cls.CanonicalType(); | 15666 type = cls.CanonicalType(); |
15630 } | 15667 } |
15631 if (type.IsNull()) { | 15668 if (type.IsNull()) { |
15632 TypeArguments& type_arguments = TypeArguments::Handle(); | 15669 TypeArguments& type_arguments = TypeArguments::Handle(); |
(...skipping 20 matching lines...) Expand all Loading... |
15653 | 15690 |
15654 void Instance::SetTypeArguments(const TypeArguments& value) const { | 15691 void Instance::SetTypeArguments(const TypeArguments& value) const { |
15655 ASSERT(value.IsNull() || value.IsCanonical()); | 15692 ASSERT(value.IsNull() || value.IsCanonical()); |
15656 const Class& cls = Class::Handle(clazz()); | 15693 const Class& cls = Class::Handle(clazz()); |
15657 intptr_t field_offset = cls.type_arguments_field_offset(); | 15694 intptr_t field_offset = cls.type_arguments_field_offset(); |
15658 ASSERT(field_offset != Class::kNoTypeArguments); | 15695 ASSERT(field_offset != Class::kNoTypeArguments); |
15659 SetFieldAtOffset(field_offset, value); | 15696 SetFieldAtOffset(field_offset, value); |
15660 } | 15697 } |
15661 | 15698 |
15662 | 15699 |
15663 bool Instance::IsInstanceOf(const AbstractType& other, | 15700 bool Instance::IsInstanceOf( |
15664 const TypeArguments& other_instantiator, | 15701 const AbstractType& other, |
15665 Error* bound_error) const { | 15702 const TypeArguments& other_instantiator_type_arguments, |
| 15703 const TypeArguments& other_function_type_arguments, |
| 15704 Error* bound_error) const { |
15666 ASSERT(other.IsFinalized()); | 15705 ASSERT(other.IsFinalized()); |
15667 ASSERT(!other.IsDynamicType()); | 15706 ASSERT(!other.IsDynamicType()); |
15668 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time. | 15707 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time. |
15669 ASSERT(!other.IsMalformed()); | 15708 ASSERT(!other.IsMalformed()); |
15670 ASSERT(!other.IsMalbounded()); | 15709 ASSERT(!other.IsMalbounded()); |
15671 if (other.IsVoidType()) { | 15710 if (other.IsVoidType()) { |
15672 return false; | 15711 return false; |
15673 } | 15712 } |
15674 Zone* zone = Thread::Current()->zone(); | 15713 Zone* zone = Thread::Current()->zone(); |
15675 const Class& cls = Class::Handle(zone, clazz()); | 15714 const Class& cls = Class::Handle(zone, clazz()); |
15676 if (cls.IsClosureClass()) { | 15715 if (cls.IsClosureClass()) { |
15677 if (other.IsObjectType() || other.IsDartFunctionType() || | 15716 if (other.IsObjectType() || other.IsDartFunctionType() || |
15678 other.IsDartClosureType()) { | 15717 other.IsDartClosureType()) { |
15679 return true; | 15718 return true; |
15680 } | 15719 } |
15681 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); | 15720 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); |
15682 // Note that we may encounter a bound error in checked mode. | 15721 // Note that we may encounter a bound error in checked mode. |
15683 if (!other.IsInstantiated()) { | 15722 if (!other.IsInstantiated()) { |
15684 instantiated_other = other.InstantiateFrom( | 15723 instantiated_other = other.InstantiateFrom( |
15685 other_instantiator, bound_error, NULL, NULL, Heap::kOld); | 15724 other_instantiator_type_arguments, other_function_type_arguments, |
| 15725 bound_error, NULL, NULL, Heap::kOld); |
15686 if ((bound_error != NULL) && !bound_error->IsNull()) { | 15726 if ((bound_error != NULL) && !bound_error->IsNull()) { |
15687 ASSERT(Isolate::Current()->type_checks()); | 15727 ASSERT(Isolate::Current()->type_checks()); |
15688 return false; | 15728 return false; |
15689 } | 15729 } |
15690 if (instantiated_other.IsTypeRef()) { | 15730 if (instantiated_other.IsTypeRef()) { |
15691 instantiated_other = TypeRef::Cast(instantiated_other).type(); | 15731 instantiated_other = TypeRef::Cast(instantiated_other).type(); |
15692 } | 15732 } |
15693 if (instantiated_other.IsDynamicType() || | 15733 if (instantiated_other.IsDynamicType() || |
15694 instantiated_other.IsObjectType() || | 15734 instantiated_other.IsObjectType() || |
15695 instantiated_other.IsDartFunctionType()) { | 15735 instantiated_other.IsDartFunctionType()) { |
15696 return true; | 15736 return true; |
15697 } | 15737 } |
15698 } | 15738 } |
15699 if (!instantiated_other.IsFunctionType()) { | 15739 if (!instantiated_other.IsFunctionType()) { |
15700 return false; | 15740 return false; |
15701 } | 15741 } |
15702 Function& other_signature = | 15742 Function& other_signature = |
15703 Function::Handle(zone, Type::Cast(instantiated_other).signature()); | 15743 Function::Handle(zone, Type::Cast(instantiated_other).signature()); |
15704 Function& sig_fun = Function::Handle(zone, Closure::Cast(*this).function()); | 15744 Function& sig_fun = Function::Handle(zone, Closure::Cast(*this).function()); |
15705 if (!sig_fun.HasInstantiatedSignature()) { | 15745 if (!sig_fun.HasInstantiatedSignature()) { |
15706 const TypeArguments& instantiator_type_arguments = | 15746 const TypeArguments& instantiator_type_arguments = |
15707 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator()); | 15747 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator()); |
15708 // TODO(regis): If sig_fun is generic, pass its type parameters | 15748 const TypeArguments& function_type_arguments = |
15709 // as function instantiator, otherwise pass null. | 15749 TypeArguments::Handle(zone, sig_fun.type_parameters()); |
15710 // Pass the closure context as well to InstantiateSignatureFrom(). | 15750 // TODO(regis): Pass the closure context to InstantiateSignatureFrom(). |
15711 // No bound error possible, since the instance exists. | 15751 sig_fun = sig_fun.InstantiateSignatureFrom( |
15712 sig_fun = sig_fun.InstantiateSignatureFrom(instantiator_type_arguments, | 15752 instantiator_type_arguments, function_type_arguments, Heap::kOld); |
15713 Heap::kOld); | |
15714 } | 15753 } |
15715 return sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld); | 15754 return sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld); |
15716 } | 15755 } |
15717 TypeArguments& type_arguments = TypeArguments::Handle(zone); | 15756 TypeArguments& type_arguments = TypeArguments::Handle(zone); |
15718 if (cls.NumTypeArguments() > 0) { | 15757 if (cls.NumTypeArguments() > 0) { |
15719 type_arguments = GetTypeArguments(); | 15758 type_arguments = GetTypeArguments(); |
15720 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); | 15759 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); |
15721 // The number of type arguments in the instance must be greater or equal to | 15760 // The number of type arguments in the instance must be greater or equal to |
15722 // the number of type arguments expected by the instance class. | 15761 // the number of type arguments expected by the instance class. |
15723 // A discrepancy is allowed for closures, which borrow the type argument | 15762 // A discrepancy is allowed for closures, which borrow the type argument |
15724 // vector of their instantiator, which may be of a subclass of the class | 15763 // vector of their instantiator, which may be of a subclass of the class |
15725 // defining the closure. Truncating the vector to the correct length on | 15764 // defining the closure. Truncating the vector to the correct length on |
15726 // instantiation is unnecessary. The vector may therefore be longer. | 15765 // instantiation is unnecessary. The vector may therefore be longer. |
15727 // Also, an optimization reuses the type argument vector of the instantiator | 15766 // Also, an optimization reuses the type argument vector of the instantiator |
15728 // of generic instances when its layout is compatible. | 15767 // of generic instances when its layout is compatible. |
15729 ASSERT(type_arguments.IsNull() || | 15768 ASSERT(type_arguments.IsNull() || |
15730 (type_arguments.Length() >= cls.NumTypeArguments())); | 15769 (type_arguments.Length() >= cls.NumTypeArguments())); |
15731 } | 15770 } |
15732 Class& other_class = Class::Handle(zone); | 15771 Class& other_class = Class::Handle(zone); |
15733 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); | 15772 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); |
15734 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); | 15773 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); |
15735 // Note that we may encounter a bound error in checked mode. | 15774 // Note that we may encounter a bound error in checked mode. |
15736 if (!other.IsInstantiated()) { | 15775 if (!other.IsInstantiated()) { |
15737 instantiated_other = other.InstantiateFrom(other_instantiator, bound_error, | 15776 instantiated_other = other.InstantiateFrom( |
15738 NULL, NULL, Heap::kOld); | 15777 other_instantiator_type_arguments, other_function_type_arguments, |
| 15778 bound_error, NULL, NULL, Heap::kOld); |
15739 if ((bound_error != NULL) && !bound_error->IsNull()) { | 15779 if ((bound_error != NULL) && !bound_error->IsNull()) { |
15740 ASSERT(Isolate::Current()->type_checks()); | 15780 ASSERT(Isolate::Current()->type_checks()); |
15741 return false; | 15781 return false; |
15742 } | 15782 } |
15743 if (instantiated_other.IsTypeRef()) { | 15783 if (instantiated_other.IsTypeRef()) { |
15744 instantiated_other = TypeRef::Cast(instantiated_other).type(); | 15784 instantiated_other = TypeRef::Cast(instantiated_other).type(); |
15745 } | 15785 } |
15746 if (instantiated_other.IsDynamicType()) { | 15786 if (instantiated_other.IsDynamicType()) { |
15747 return true; | 15787 return true; |
15748 } | 15788 } |
15749 } | 15789 } |
15750 other_type_arguments = instantiated_other.arguments(); | 15790 other_type_arguments = instantiated_other.arguments(); |
15751 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); | 15791 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); |
15752 if (other_is_dart_function || instantiated_other.IsFunctionType()) { | 15792 if (other_is_dart_function || instantiated_other.IsFunctionType()) { |
15753 // Check if this instance understands a call() method of a compatible type. | 15793 // Check if this instance understands a call() method of a compatible type. |
15754 Function& sig_fun = | 15794 Function& sig_fun = |
15755 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); | 15795 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); |
15756 if (!sig_fun.IsNull()) { | 15796 if (!sig_fun.IsNull()) { |
15757 if (other_is_dart_function) { | 15797 if (other_is_dart_function) { |
15758 return true; | 15798 return true; |
15759 } | 15799 } |
15760 if (!sig_fun.HasInstantiatedSignature()) { | 15800 if (!sig_fun.HasInstantiatedSignature()) { |
15761 // TODO(regis): If sig_fun is generic, pass its type parameters | 15801 const TypeArguments& function_type_arguments = |
15762 // as function instantiator, otherwise pass null. | 15802 TypeArguments::Handle(zone, sig_fun.type_parameters()); |
15763 // Pass the closure context as well to InstantiateSignatureFrom(). | 15803 // TODO(regis): Pass the closure context to InstantiateSignatureFrom(). |
15764 // No bound error possible, since the instance exists. | 15804 // No bound error possible, since the instance exists. |
15765 sig_fun = sig_fun.InstantiateSignatureFrom(type_arguments, Heap::kOld); | 15805 sig_fun = sig_fun.InstantiateSignatureFrom( |
| 15806 type_arguments, function_type_arguments, Heap::kOld); |
15766 } | 15807 } |
15767 const Function& other_signature = | 15808 const Function& other_signature = |
15768 Function::Handle(zone, Type::Cast(instantiated_other).signature()); | 15809 Function::Handle(zone, Type::Cast(instantiated_other).signature()); |
15769 if (sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld)) { | 15810 if (sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld)) { |
15770 return true; | 15811 return true; |
15771 } | 15812 } |
15772 } | 15813 } |
15773 } | 15814 } |
15774 if (!instantiated_other.IsType()) { | 15815 if (!instantiated_other.IsType()) { |
15775 return false; | 15816 return false; |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16110 | 16151 |
16111 bool AbstractType::IsRecursive() const { | 16152 bool AbstractType::IsRecursive() const { |
16112 // AbstractType is an abstract class. | 16153 // AbstractType is an abstract class. |
16113 UNREACHABLE(); | 16154 UNREACHABLE(); |
16114 return false; | 16155 return false; |
16115 } | 16156 } |
16116 | 16157 |
16117 | 16158 |
16118 RawAbstractType* AbstractType::InstantiateFrom( | 16159 RawAbstractType* AbstractType::InstantiateFrom( |
16119 const TypeArguments& instantiator_type_arguments, | 16160 const TypeArguments& instantiator_type_arguments, |
| 16161 const TypeArguments& function_type_arguments, |
16120 Error* bound_error, | 16162 Error* bound_error, |
16121 TrailPtr instantiation_trail, | 16163 TrailPtr instantiation_trail, |
16122 TrailPtr bound_trail, | 16164 TrailPtr bound_trail, |
16123 Heap::Space space) const { | 16165 Heap::Space space) const { |
16124 // AbstractType is an abstract class. | 16166 // AbstractType is an abstract class. |
16125 UNREACHABLE(); | 16167 UNREACHABLE(); |
16126 return NULL; | 16168 return NULL; |
16127 } | 16169 } |
16128 | 16170 |
16129 | 16171 |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16883 } | 16925 } |
16884 } | 16926 } |
16885 return (len == 0) || | 16927 return (len == 0) || |
16886 args.IsSubvectorInstantiated(num_type_args - len, len, genericity, | 16928 args.IsSubvectorInstantiated(num_type_args - len, len, genericity, |
16887 trail); | 16929 trail); |
16888 } | 16930 } |
16889 | 16931 |
16890 | 16932 |
16891 RawAbstractType* Type::InstantiateFrom( | 16933 RawAbstractType* Type::InstantiateFrom( |
16892 const TypeArguments& instantiator_type_arguments, | 16934 const TypeArguments& instantiator_type_arguments, |
| 16935 const TypeArguments& function_type_arguments, |
16893 Error* bound_error, | 16936 Error* bound_error, |
16894 TrailPtr instantiation_trail, | 16937 TrailPtr instantiation_trail, |
16895 TrailPtr bound_trail, | 16938 TrailPtr bound_trail, |
16896 Heap::Space space) const { | 16939 Heap::Space space) const { |
16897 Zone* zone = Thread::Current()->zone(); | 16940 Zone* zone = Thread::Current()->zone(); |
16898 ASSERT(IsFinalized() || IsBeingFinalized()); | 16941 ASSERT(IsFinalized() || IsBeingFinalized()); |
16899 ASSERT(!IsInstantiated()); | 16942 ASSERT(!IsInstantiated()); |
16900 // Return the uninstantiated type unchanged if malformed. No copy needed. | 16943 // Return the uninstantiated type unchanged if malformed. No copy needed. |
16901 if (IsMalformed()) { | 16944 if (IsMalformed()) { |
16902 return raw(); | 16945 return raw(); |
16903 } | 16946 } |
16904 // Note that the type class has to be resolved at this time, but not | 16947 // Note that the type class has to be resolved at this time, but not |
16905 // necessarily finalized yet. We may be checking bounds at compile time or | 16948 // necessarily finalized yet. We may be checking bounds at compile time or |
16906 // finalizing the type argument vector of a recursive type. | 16949 // finalizing the type argument vector of a recursive type. |
16907 const Class& cls = Class::Handle(zone, type_class()); | 16950 const Class& cls = Class::Handle(zone, type_class()); |
16908 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); | 16951 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); |
16909 Function& sig_fun = Function::Handle(zone, signature()); | 16952 Function& sig_fun = Function::Handle(zone, signature()); |
16910 if (!type_arguments.IsNull() && | 16953 if (!type_arguments.IsNull() && |
16911 (sig_fun.IsNull() || !type_arguments.IsInstantiated())) { | 16954 (sig_fun.IsNull() || !type_arguments.IsInstantiated())) { |
16912 // This type is uninstantiated because either its type arguments or its | 16955 // This type is uninstantiated because either its type arguments or its |
16913 // signature, or both are uninstantiated. | 16956 // signature, or both are uninstantiated. |
16914 // Note that the type arguments of a function type merely document the | 16957 // Note that the type arguments of a function type merely document the |
16915 // parameterization of a generic typedef. They are otherwise ignored. | 16958 // parameterization of a generic typedef. They are otherwise ignored. |
16916 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); | 16959 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); |
16917 type_arguments = | 16960 type_arguments = type_arguments.InstantiateFrom( |
16918 type_arguments.InstantiateFrom(instantiator_type_arguments, bound_error, | 16961 instantiator_type_arguments, function_type_arguments, bound_error, |
16919 instantiation_trail, bound_trail, space); | 16962 instantiation_trail, bound_trail, space); |
16920 } | 16963 } |
16921 // This uninstantiated type is not modified, as it can be instantiated | 16964 // This uninstantiated type is not modified, as it can be instantiated |
16922 // with different instantiators. Allocate a new instantiated version of it. | 16965 // with different instantiators. Allocate a new instantiated version of it. |
16923 const Type& instantiated_type = | 16966 const Type& instantiated_type = |
16924 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); | 16967 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); |
16925 // Preserve the bound error if any. | 16968 // Preserve the bound error if any. |
16926 if (IsMalbounded()) { | 16969 if (IsMalbounded()) { |
16927 const LanguageError& bound_error = LanguageError::Handle(zone, error()); | 16970 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
16928 instantiated_type.set_error(bound_error); | 16971 instantiated_type.set_error(bound_error); |
16929 } | 16972 } |
16930 // For a function type, possibly instantiate and set its signature. | 16973 // For a function type, possibly instantiate and set its signature. |
16931 if (!sig_fun.IsNull()) { | 16974 if (!sig_fun.IsNull()) { |
16932 // If we are finalizing a typedef, do not yet instantiate its signature, | 16975 // If we are finalizing a typedef, do not yet instantiate its signature, |
16933 // since it gets instantiated just before the type is marked as finalized. | 16976 // since it gets instantiated just before the type is marked as finalized. |
16934 // Other function types should never get instantiated while unfinalized, | 16977 // Other function types should never get instantiated while unfinalized, |
16935 // even while checking bounds of recursive types. | 16978 // even while checking bounds of recursive types. |
16936 if (IsFinalized()) { | 16979 if (IsFinalized()) { |
16937 // A generic typedef may actually declare an instantiated signature. | 16980 // A generic typedef may actually declare an instantiated signature. |
16938 if (!sig_fun.HasInstantiatedSignature()) { | 16981 if (!sig_fun.HasInstantiatedSignature()) { |
16939 sig_fun = sig_fun.InstantiateSignatureFrom(instantiator_type_arguments, | 16982 sig_fun = sig_fun.InstantiateSignatureFrom( |
16940 space); | 16983 instantiator_type_arguments, function_type_arguments, space); |
16941 } | 16984 } |
16942 } else { | 16985 } else { |
16943 // The Kernel frontend does not keep the information that a function type | 16986 // The Kernel frontend does not keep the information that a function type |
16944 // is a typedef, so we cannot assert that cls.IsTypedefClass(). | 16987 // is a typedef, so we cannot assert that cls.IsTypedefClass(). |
16945 } | 16988 } |
16946 instantiated_type.set_signature(sig_fun); | 16989 instantiated_type.set_signature(sig_fun); |
16947 } | 16990 } |
16948 if (IsFinalized()) { | 16991 if (IsFinalized()) { |
16949 instantiated_type.SetIsFinalized(); | 16992 instantiated_type.SetIsFinalized(); |
16950 } else { | 16993 } else { |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17588 } | 17631 } |
17589 if (TestAndAddBuddyToTrail(&trail, AbstractType::Cast(other))) { | 17632 if (TestAndAddBuddyToTrail(&trail, AbstractType::Cast(other))) { |
17590 return true; | 17633 return true; |
17591 } | 17634 } |
17592 return AbstractType::Handle(type()).IsEquivalent(other, trail); | 17635 return AbstractType::Handle(type()).IsEquivalent(other, trail); |
17593 } | 17636 } |
17594 | 17637 |
17595 | 17638 |
17596 RawTypeRef* TypeRef::InstantiateFrom( | 17639 RawTypeRef* TypeRef::InstantiateFrom( |
17597 const TypeArguments& instantiator_type_arguments, | 17640 const TypeArguments& instantiator_type_arguments, |
| 17641 const TypeArguments& function_type_arguments, |
17598 Error* bound_error, | 17642 Error* bound_error, |
17599 TrailPtr instantiation_trail, | 17643 TrailPtr instantiation_trail, |
17600 TrailPtr bound_trail, | 17644 TrailPtr bound_trail, |
17601 Heap::Space space) const { | 17645 Heap::Space space) const { |
17602 TypeRef& instantiated_type_ref = TypeRef::Handle(); | 17646 TypeRef& instantiated_type_ref = TypeRef::Handle(); |
17603 instantiated_type_ref ^= OnlyBuddyInTrail(instantiation_trail); | 17647 instantiated_type_ref ^= OnlyBuddyInTrail(instantiation_trail); |
17604 if (!instantiated_type_ref.IsNull()) { | 17648 if (!instantiated_type_ref.IsNull()) { |
17605 return instantiated_type_ref.raw(); | 17649 return instantiated_type_ref.raw(); |
17606 } | 17650 } |
17607 instantiated_type_ref = TypeRef::New(); | 17651 instantiated_type_ref = TypeRef::New(); |
17608 AddOnlyBuddyToTrail(&instantiation_trail, instantiated_type_ref); | 17652 AddOnlyBuddyToTrail(&instantiation_trail, instantiated_type_ref); |
17609 | 17653 |
17610 AbstractType& ref_type = AbstractType::Handle(type()); | 17654 AbstractType& ref_type = AbstractType::Handle(type()); |
17611 ASSERT(!ref_type.IsTypeRef()); | 17655 ASSERT(!ref_type.IsTypeRef()); |
17612 AbstractType& instantiated_ref_type = AbstractType::Handle(); | 17656 AbstractType& instantiated_ref_type = AbstractType::Handle(); |
17613 instantiated_ref_type = | 17657 instantiated_ref_type = ref_type.InstantiateFrom( |
17614 ref_type.InstantiateFrom(instantiator_type_arguments, bound_error, | 17658 instantiator_type_arguments, function_type_arguments, bound_error, |
17615 instantiation_trail, bound_trail, space); | 17659 instantiation_trail, bound_trail, space); |
17616 ASSERT(!instantiated_ref_type.IsTypeRef()); | 17660 ASSERT(!instantiated_ref_type.IsTypeRef()); |
17617 instantiated_type_ref.set_type(instantiated_ref_type); | 17661 instantiated_type_ref.set_type(instantiated_ref_type); |
17618 return instantiated_type_ref.raw(); | 17662 return instantiated_type_ref.raw(); |
17619 } | 17663 } |
17620 | 17664 |
17621 | 17665 |
17622 RawTypeRef* TypeRef::CloneUninstantiated(const Class& new_owner, | 17666 RawTypeRef* TypeRef::CloneUninstantiated(const Class& new_owner, |
17623 TrailPtr trail) const { | 17667 TrailPtr trail) const { |
17624 TypeRef& cloned_type_ref = TypeRef::Handle(); | 17668 TypeRef& cloned_type_ref = TypeRef::Handle(); |
17625 cloned_type_ref ^= OnlyBuddyInTrail(trail); | 17669 cloned_type_ref ^= OnlyBuddyInTrail(trail); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17827 } | 17871 } |
17828 | 17872 |
17829 | 17873 |
17830 void TypeParameter::set_bound(const AbstractType& value) const { | 17874 void TypeParameter::set_bound(const AbstractType& value) const { |
17831 StorePointer(&raw_ptr()->bound_, value.raw()); | 17875 StorePointer(&raw_ptr()->bound_, value.raw()); |
17832 } | 17876 } |
17833 | 17877 |
17834 | 17878 |
17835 RawAbstractType* TypeParameter::InstantiateFrom( | 17879 RawAbstractType* TypeParameter::InstantiateFrom( |
17836 const TypeArguments& instantiator_type_arguments, | 17880 const TypeArguments& instantiator_type_arguments, |
| 17881 const TypeArguments& function_type_arguments, |
17837 Error* bound_error, | 17882 Error* bound_error, |
17838 TrailPtr instantiation_trail, | 17883 TrailPtr instantiation_trail, |
17839 TrailPtr bound_trail, | 17884 TrailPtr bound_trail, |
17840 Heap::Space space) const { | 17885 Heap::Space space) const { |
17841 ASSERT(IsFinalized()); | 17886 ASSERT(IsFinalized()); |
| 17887 if (IsFunctionTypeParameter()) { |
| 17888 if (parent_level() == 0) { |
| 17889 if (function_type_arguments.IsNull()) { |
| 17890 return Type::DynamicType(); |
| 17891 } |
| 17892 return function_type_arguments.TypeAt(index()); |
| 17893 } |
| 17894 // We need to find the type argument vector of the parent function at |
| 17895 // parent_level() in the context. |
| 17896 UNIMPLEMENTED(); |
| 17897 return function_type_arguments.TypeAt(index()); |
| 17898 } |
| 17899 ASSERT(IsClassTypeParameter()); |
17842 if (instantiator_type_arguments.IsNull()) { | 17900 if (instantiator_type_arguments.IsNull()) { |
17843 return Type::DynamicType(); | 17901 return Type::DynamicType(); |
17844 } | 17902 } |
17845 const AbstractType& type_arg = | 17903 return instantiator_type_arguments.TypeAt(index()); |
17846 AbstractType::Handle(instantiator_type_arguments.TypeAt(index())); | |
17847 // There is no need to canonicalize the instantiated type parameter, since all | 17904 // There is no need to canonicalize the instantiated type parameter, since all |
17848 // type arguments are canonicalized at type finalization time. It would be too | 17905 // type arguments are canonicalized at type finalization time. It would be too |
17849 // early to canonicalize the returned type argument here, since instantiation | 17906 // early to canonicalize the returned type argument here, since instantiation |
17850 // not only happens at run time, but also during type finalization. | 17907 // not only happens at run time, but also during type finalization. |
17851 | 17908 |
17852 // If the instantiated type parameter type_arg is a BoundedType, it means that | 17909 // If the instantiated type parameter type_arg is a BoundedType, it means that |
17853 // it is still uninstantiated and that we are instantiating at finalization | 17910 // it is still uninstantiated and that we are instantiating at finalization |
17854 // time (i.e. compile time). | 17911 // time (i.e. compile time). |
17855 // Indeed, the instantiator (type arguments of an instance) is always | 17912 // Indeed, the instantiator (type arguments of an instance) is always |
17856 // instantiated at run time and any bounds were checked during allocation. | 17913 // instantiated at run time and any bounds were checked during allocation. |
17857 return type_arg.raw(); | |
17858 } | 17914 } |
17859 | 17915 |
17860 | 17916 |
17861 bool TypeParameter::CheckBound(const AbstractType& bounded_type, | 17917 bool TypeParameter::CheckBound(const AbstractType& bounded_type, |
17862 const AbstractType& upper_bound, | 17918 const AbstractType& upper_bound, |
17863 Error* bound_error, | 17919 Error* bound_error, |
17864 TrailPtr bound_trail, | 17920 TrailPtr bound_trail, |
17865 Heap::Space space) const { | 17921 Heap::Space space) const { |
17866 ASSERT((bound_error != NULL) && bound_error->IsNull()); | 17922 ASSERT((bound_error != NULL) && bound_error->IsNull()); |
17867 ASSERT(bounded_type.IsFinalized()); | 17923 ASSERT(bounded_type.IsFinalized()); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18158 void BoundedType::set_type_parameter(const TypeParameter& value) const { | 18214 void BoundedType::set_type_parameter(const TypeParameter& value) const { |
18159 // A null type parameter is set when marking a type malformed because of a | 18215 // A null type parameter is set when marking a type malformed because of a |
18160 // bound error at compile time. | 18216 // bound error at compile time. |
18161 ASSERT(value.IsNull() || value.IsFinalized()); | 18217 ASSERT(value.IsNull() || value.IsFinalized()); |
18162 StorePointer(&raw_ptr()->type_parameter_, value.raw()); | 18218 StorePointer(&raw_ptr()->type_parameter_, value.raw()); |
18163 } | 18219 } |
18164 | 18220 |
18165 | 18221 |
18166 RawAbstractType* BoundedType::InstantiateFrom( | 18222 RawAbstractType* BoundedType::InstantiateFrom( |
18167 const TypeArguments& instantiator_type_arguments, | 18223 const TypeArguments& instantiator_type_arguments, |
| 18224 const TypeArguments& function_type_arguments, |
18168 Error* bound_error, | 18225 Error* bound_error, |
18169 TrailPtr instantiation_trail, | 18226 TrailPtr instantiation_trail, |
18170 TrailPtr bound_trail, | 18227 TrailPtr bound_trail, |
18171 Heap::Space space) const { | 18228 Heap::Space space) const { |
18172 ASSERT(IsFinalized()); | 18229 ASSERT(IsFinalized()); |
18173 AbstractType& bounded_type = AbstractType::Handle(type()); | 18230 AbstractType& bounded_type = AbstractType::Handle(type()); |
18174 ASSERT(bounded_type.IsFinalized()); | 18231 ASSERT(bounded_type.IsFinalized()); |
18175 AbstractType& instantiated_bounded_type = | 18232 AbstractType& instantiated_bounded_type = |
18176 AbstractType::Handle(bounded_type.raw()); | 18233 AbstractType::Handle(bounded_type.raw()); |
18177 if (!bounded_type.IsInstantiated()) { | 18234 if (!bounded_type.IsInstantiated()) { |
18178 instantiated_bounded_type = | 18235 instantiated_bounded_type = bounded_type.InstantiateFrom( |
18179 bounded_type.InstantiateFrom(instantiator_type_arguments, bound_error, | 18236 instantiator_type_arguments, function_type_arguments, bound_error, |
18180 instantiation_trail, bound_trail, space); | 18237 instantiation_trail, bound_trail, space); |
18181 // In case types of instantiator_type_arguments are not finalized | 18238 // In case types of instantiator_type_arguments are not finalized |
18182 // (or instantiated), then the instantiated_bounded_type is not finalized | 18239 // (or instantiated), then the instantiated_bounded_type is not finalized |
18183 // (or instantiated) either. | 18240 // (or instantiated) either. |
18184 // Note that instantiator_type_arguments must have the final length, though. | 18241 // Note that instantiator_type_arguments must have the final length, though. |
18185 } | 18242 } |
18186 if ((Isolate::Current()->type_checks()) && (bound_error != NULL) && | 18243 if ((Isolate::Current()->type_checks()) && (bound_error != NULL) && |
18187 bound_error->IsNull()) { | 18244 bound_error->IsNull()) { |
18188 AbstractType& upper_bound = AbstractType::Handle(bound()); | 18245 AbstractType& upper_bound = AbstractType::Handle(bound()); |
18189 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType()); | 18246 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType()); |
18190 AbstractType& instantiated_upper_bound = | 18247 AbstractType& instantiated_upper_bound = |
18191 AbstractType::Handle(upper_bound.raw()); | 18248 AbstractType::Handle(upper_bound.raw()); |
18192 if (upper_bound.IsFinalized() && !upper_bound.IsInstantiated()) { | 18249 if (upper_bound.IsFinalized() && !upper_bound.IsInstantiated()) { |
18193 instantiated_upper_bound = | 18250 instantiated_upper_bound = upper_bound.InstantiateFrom( |
18194 upper_bound.InstantiateFrom(instantiator_type_arguments, bound_error, | 18251 instantiator_type_arguments, function_type_arguments, bound_error, |
18195 instantiation_trail, bound_trail, space); | 18252 instantiation_trail, bound_trail, space); |
18196 // The instantiated_upper_bound may not be finalized or instantiated. | 18253 // The instantiated_upper_bound may not be finalized or instantiated. |
18197 // See comment above. | 18254 // See comment above. |
18198 } | 18255 } |
18199 if (bound_error->IsNull()) { | 18256 if (bound_error->IsNull()) { |
18200 // Shortcut the F-bounded case where we have reached a fixpoint. | 18257 // Shortcut the F-bounded case where we have reached a fixpoint. |
18201 if (instantiated_bounded_type.Equals(bounded_type) && | 18258 if (instantiated_bounded_type.Equals(bounded_type) && |
18202 instantiated_upper_bound.Equals(upper_bound)) { | 18259 instantiated_upper_bound.Equals(upper_bound)) { |
18203 return bounded_type.raw(); | 18260 return bounded_type.raw(); |
18204 } | 18261 } |
18205 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); | 18262 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); |
(...skipping 4877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23083 return UserTag::null(); | 23140 return UserTag::null(); |
23084 } | 23141 } |
23085 | 23142 |
23086 | 23143 |
23087 const char* UserTag::ToCString() const { | 23144 const char* UserTag::ToCString() const { |
23088 const String& tag_label = String::Handle(label()); | 23145 const String& tag_label = String::Handle(label()); |
23089 return tag_label.ToCString(); | 23146 return tag_label.ToCString(); |
23090 } | 23147 } |
23091 | 23148 |
23092 } // namespace dart | 23149 } // namespace dart |
OLD | NEW |