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

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

Issue 2799373002: Pass a second type argument vector to all type instantiation calls in the VM. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/become.h" 10 #include "vm/become.h"
(...skipping 3880 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
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
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 8616 matching lines...) Expand 10 before | Expand all | Expand 10 after
15076 NoSafepointScope no_safepoint; 15106 NoSafepointScope no_safepoint;
15077 // Do not count the sentinel; 15107 // Do not count the sentinel;
15078 return (Smi::Value(cache()->ptr()->length_) / kTestEntryLength) - 1; 15108 return (Smi::Value(cache()->ptr()->length_) / kTestEntryLength) - 1;
15079 } 15109 }
15080 15110
15081 15111
15082 void SubtypeTestCache::AddCheck( 15112 void SubtypeTestCache::AddCheck(
15083 const Object& instance_class_id_or_function, 15113 const Object& instance_class_id_or_function,
15084 const TypeArguments& instance_type_arguments, 15114 const TypeArguments& instance_type_arguments,
15085 const TypeArguments& instantiator_type_arguments, 15115 const TypeArguments& instantiator_type_arguments,
15116 const TypeArguments& function_type_arguments,
15086 const Bool& test_result) const { 15117 const Bool& test_result) const {
15087 intptr_t old_num = NumberOfChecks(); 15118 intptr_t old_num = NumberOfChecks();
15088 Array& data = Array::Handle(cache()); 15119 Array& data = Array::Handle(cache());
15089 intptr_t new_len = data.Length() + kTestEntryLength; 15120 intptr_t new_len = data.Length() + kTestEntryLength;
15090 data = Array::Grow(data, new_len); 15121 data = Array::Grow(data, new_len);
15091 set_cache(data); 15122 set_cache(data);
15092 intptr_t data_pos = old_num * kTestEntryLength; 15123 intptr_t data_pos = old_num * kTestEntryLength;
15093 data.SetAt(data_pos + kInstanceClassIdOrFunction, 15124 data.SetAt(data_pos + kInstanceClassIdOrFunction,
15094 instance_class_id_or_function); 15125 instance_class_id_or_function);
15095 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments); 15126 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments);
15096 data.SetAt(data_pos + kInstantiatorTypeArguments, 15127 data.SetAt(data_pos + kInstantiatorTypeArguments,
15097 instantiator_type_arguments); 15128 instantiator_type_arguments);
15129 data.SetAt(data_pos + kFunctionTypeArguments, function_type_arguments);
15098 data.SetAt(data_pos + kTestResult, test_result); 15130 data.SetAt(data_pos + kTestResult, test_result);
15099 } 15131 }
15100 15132
15101 15133
15102 void SubtypeTestCache::GetCheck(intptr_t ix, 15134 void SubtypeTestCache::GetCheck(intptr_t ix,
15103 Object* instance_class_id_or_function, 15135 Object* instance_class_id_or_function,
15104 TypeArguments* instance_type_arguments, 15136 TypeArguments* instance_type_arguments,
15105 TypeArguments* instantiator_type_arguments, 15137 TypeArguments* instantiator_type_arguments,
15138 TypeArguments* function_type_arguments,
15106 Bool* test_result) const { 15139 Bool* test_result) const {
15107 Array& data = Array::Handle(cache()); 15140 Array& data = Array::Handle(cache());
15108 intptr_t data_pos = ix * kTestEntryLength; 15141 intptr_t data_pos = ix * kTestEntryLength;
15109 *instance_class_id_or_function = 15142 *instance_class_id_or_function =
15110 data.At(data_pos + kInstanceClassIdOrFunction); 15143 data.At(data_pos + kInstanceClassIdOrFunction);
15111 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); 15144 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments);
15112 *instantiator_type_arguments ^= 15145 *instantiator_type_arguments ^=
15113 data.At(data_pos + kInstantiatorTypeArguments); 15146 data.At(data_pos + kInstantiatorTypeArguments);
15147 *function_type_arguments ^= data.At(data_pos + kFunctionTypeArguments);
15114 *test_result ^= data.At(data_pos + kTestResult); 15148 *test_result ^= data.At(data_pos + kTestResult);
15115 } 15149 }
15116 15150
15117 15151
15118 const char* SubtypeTestCache::ToCString() const { 15152 const char* SubtypeTestCache::ToCString() const {
15119 return "SubtypeTestCache"; 15153 return "SubtypeTestCache";
15120 } 15154 }
15121 15155
15122 15156
15123 const char* Error::ToErrorCString() const { 15157 const char* Error::ToErrorCString() const {
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
15613 return Type::NullType(); 15647 return Type::NullType();
15614 } 15648 }
15615 const Class& cls = Class::Handle(clazz()); 15649 const Class& cls = Class::Handle(clazz());
15616 if (cls.IsClosureClass()) { 15650 if (cls.IsClosureClass()) {
15617 const Function& signature = 15651 const Function& signature =
15618 Function::Handle(Closure::Cast(*this).function()); 15652 Function::Handle(Closure::Cast(*this).function());
15619 Type& type = Type::Handle(signature.SignatureType()); 15653 Type& type = Type::Handle(signature.SignatureType());
15620 if (!type.IsInstantiated()) { 15654 if (!type.IsInstantiated()) {
15621 TypeArguments& instantiator_type_arguments = 15655 TypeArguments& instantiator_type_arguments =
15622 TypeArguments::Handle(Closure::Cast(*this).instantiator()); 15656 TypeArguments::Handle(Closure::Cast(*this).instantiator());
15623 // TODO(regis): Should we pass the context explicitly here (i.e. null) 15657 const TypeArguments& function_type_arguments =
15624 // once we support generic functions? 15658 TypeArguments::Handle(signature.type_parameters());
15625 type ^= type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, 15659 // TODO(regis): Pass the closure context to InstantiateSignatureFrom().
15626 NULL, space); 15660 // No bound error possible, since the instance exists.
15661 type ^= type.InstantiateFrom(instantiator_type_arguments,
15662 function_type_arguments, NULL, NULL, NULL,
15663 space);
15627 } 15664 }
15628 type ^= type.Canonicalize(); 15665 type ^= type.Canonicalize();
15629 return type.raw(); 15666 return type.raw();
15630 } 15667 }
15631 Type& type = Type::Handle(); 15668 Type& type = Type::Handle();
15632 if (!cls.IsGeneric()) { 15669 if (!cls.IsGeneric()) {
15633 type = cls.CanonicalType(); 15670 type = cls.CanonicalType();
15634 } 15671 }
15635 if (type.IsNull()) { 15672 if (type.IsNull()) {
15636 TypeArguments& type_arguments = TypeArguments::Handle(); 15673 TypeArguments& type_arguments = TypeArguments::Handle();
(...skipping 20 matching lines...) Expand all
15657 15694
15658 void Instance::SetTypeArguments(const TypeArguments& value) const { 15695 void Instance::SetTypeArguments(const TypeArguments& value) const {
15659 ASSERT(value.IsNull() || value.IsCanonical()); 15696 ASSERT(value.IsNull() || value.IsCanonical());
15660 const Class& cls = Class::Handle(clazz()); 15697 const Class& cls = Class::Handle(clazz());
15661 intptr_t field_offset = cls.type_arguments_field_offset(); 15698 intptr_t field_offset = cls.type_arguments_field_offset();
15662 ASSERT(field_offset != Class::kNoTypeArguments); 15699 ASSERT(field_offset != Class::kNoTypeArguments);
15663 SetFieldAtOffset(field_offset, value); 15700 SetFieldAtOffset(field_offset, value);
15664 } 15701 }
15665 15702
15666 15703
15667 bool Instance::IsInstanceOf(const AbstractType& other, 15704 bool Instance::IsInstanceOf(
15668 const TypeArguments& other_instantiator, 15705 const AbstractType& other,
15669 Error* bound_error) const { 15706 const TypeArguments& other_instantiator_type_arguments,
15707 const TypeArguments& other_function_type_arguments,
15708 Error* bound_error) const {
15670 ASSERT(other.IsFinalized()); 15709 ASSERT(other.IsFinalized());
15671 ASSERT(!other.IsDynamicType()); 15710 ASSERT(!other.IsDynamicType());
15672 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time. 15711 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time.
15673 ASSERT(!other.IsMalformed()); 15712 ASSERT(!other.IsMalformed());
15674 ASSERT(!other.IsMalbounded()); 15713 ASSERT(!other.IsMalbounded());
15675 if (other.IsVoidType()) { 15714 if (other.IsVoidType()) {
15676 return false; 15715 return false;
15677 } 15716 }
15678 Zone* zone = Thread::Current()->zone(); 15717 Zone* zone = Thread::Current()->zone();
15679 const Class& cls = Class::Handle(zone, clazz()); 15718 const Class& cls = Class::Handle(zone, clazz());
15680 if (cls.IsClosureClass()) { 15719 if (cls.IsClosureClass()) {
15681 if (other.IsObjectType() || other.IsDartFunctionType() || 15720 if (other.IsObjectType() || other.IsDartFunctionType() ||
15682 other.IsDartClosureType()) { 15721 other.IsDartClosureType()) {
15683 return true; 15722 return true;
15684 } 15723 }
15685 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); 15724 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw());
15686 // Note that we may encounter a bound error in checked mode. 15725 // Note that we may encounter a bound error in checked mode.
15687 if (!other.IsInstantiated()) { 15726 if (!other.IsInstantiated()) {
15688 instantiated_other = other.InstantiateFrom( 15727 instantiated_other = other.InstantiateFrom(
15689 other_instantiator, bound_error, NULL, NULL, Heap::kOld); 15728 other_instantiator_type_arguments, other_function_type_arguments,
15729 bound_error, NULL, NULL, Heap::kOld);
15690 if ((bound_error != NULL) && !bound_error->IsNull()) { 15730 if ((bound_error != NULL) && !bound_error->IsNull()) {
15691 ASSERT(Isolate::Current()->type_checks()); 15731 ASSERT(Isolate::Current()->type_checks());
15692 return false; 15732 return false;
15693 } 15733 }
15694 if (instantiated_other.IsTypeRef()) { 15734 if (instantiated_other.IsTypeRef()) {
15695 instantiated_other = TypeRef::Cast(instantiated_other).type(); 15735 instantiated_other = TypeRef::Cast(instantiated_other).type();
15696 } 15736 }
15697 if (instantiated_other.IsDynamicType() || 15737 if (instantiated_other.IsDynamicType() ||
15698 instantiated_other.IsObjectType() || 15738 instantiated_other.IsObjectType() ||
15699 instantiated_other.IsDartFunctionType()) { 15739 instantiated_other.IsDartFunctionType()) {
15700 return true; 15740 return true;
15701 } 15741 }
15702 } 15742 }
15703 if (!instantiated_other.IsFunctionType()) { 15743 if (!instantiated_other.IsFunctionType()) {
15704 return false; 15744 return false;
15705 } 15745 }
15706 Function& other_signature = 15746 Function& other_signature =
15707 Function::Handle(zone, Type::Cast(instantiated_other).signature()); 15747 Function::Handle(zone, Type::Cast(instantiated_other).signature());
15708 Function& sig_fun = Function::Handle(zone, Closure::Cast(*this).function()); 15748 Function& sig_fun = Function::Handle(zone, Closure::Cast(*this).function());
15709 if (!sig_fun.HasInstantiatedSignature()) { 15749 if (!sig_fun.HasInstantiatedSignature()) {
15710 const TypeArguments& instantiator_type_arguments = 15750 const TypeArguments& instantiator_type_arguments =
15711 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator()); 15751 TypeArguments::Handle(zone, Closure::Cast(*this).instantiator());
15712 // TODO(regis): If sig_fun is generic, pass its type parameters 15752 const TypeArguments& function_type_arguments =
15713 // as function instantiator, otherwise pass null. 15753 TypeArguments::Handle(zone, sig_fun.type_parameters());
15714 // Pass the closure context as well to InstantiateSignatureFrom(). 15754 // TODO(regis): Pass the closure context to InstantiateSignatureFrom().
15715 // No bound error possible, since the instance exists. 15755 sig_fun = sig_fun.InstantiateSignatureFrom(
15716 sig_fun = sig_fun.InstantiateSignatureFrom(instantiator_type_arguments, 15756 instantiator_type_arguments, function_type_arguments, Heap::kOld);
15717 Heap::kOld);
15718 } 15757 }
15719 return sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld); 15758 return sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld);
15720 } 15759 }
15721 TypeArguments& type_arguments = TypeArguments::Handle(zone); 15760 TypeArguments& type_arguments = TypeArguments::Handle(zone);
15722 if (cls.NumTypeArguments() > 0) { 15761 if (cls.NumTypeArguments() > 0) {
15723 type_arguments = GetTypeArguments(); 15762 type_arguments = GetTypeArguments();
15724 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); 15763 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical());
15725 // The number of type arguments in the instance must be greater or equal to 15764 // The number of type arguments in the instance must be greater or equal to
15726 // the number of type arguments expected by the instance class. 15765 // the number of type arguments expected by the instance class.
15727 // A discrepancy is allowed for closures, which borrow the type argument 15766 // A discrepancy is allowed for closures, which borrow the type argument
15728 // vector of their instantiator, which may be of a subclass of the class 15767 // vector of their instantiator, which may be of a subclass of the class
15729 // defining the closure. Truncating the vector to the correct length on 15768 // defining the closure. Truncating the vector to the correct length on
15730 // instantiation is unnecessary. The vector may therefore be longer. 15769 // instantiation is unnecessary. The vector may therefore be longer.
15731 // Also, an optimization reuses the type argument vector of the instantiator 15770 // Also, an optimization reuses the type argument vector of the instantiator
15732 // of generic instances when its layout is compatible. 15771 // of generic instances when its layout is compatible.
15733 ASSERT(type_arguments.IsNull() || 15772 ASSERT(type_arguments.IsNull() ||
15734 (type_arguments.Length() >= cls.NumTypeArguments())); 15773 (type_arguments.Length() >= cls.NumTypeArguments()));
15735 } 15774 }
15736 Class& other_class = Class::Handle(zone); 15775 Class& other_class = Class::Handle(zone);
15737 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); 15776 TypeArguments& other_type_arguments = TypeArguments::Handle(zone);
15738 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); 15777 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw());
15739 // Note that we may encounter a bound error in checked mode. 15778 // Note that we may encounter a bound error in checked mode.
15740 if (!other.IsInstantiated()) { 15779 if (!other.IsInstantiated()) {
15741 instantiated_other = other.InstantiateFrom(other_instantiator, bound_error, 15780 instantiated_other = other.InstantiateFrom(
15742 NULL, NULL, Heap::kOld); 15781 other_instantiator_type_arguments, other_function_type_arguments,
15782 bound_error, NULL, NULL, Heap::kOld);
15743 if ((bound_error != NULL) && !bound_error->IsNull()) { 15783 if ((bound_error != NULL) && !bound_error->IsNull()) {
15744 ASSERT(Isolate::Current()->type_checks()); 15784 ASSERT(Isolate::Current()->type_checks());
15745 return false; 15785 return false;
15746 } 15786 }
15747 if (instantiated_other.IsTypeRef()) { 15787 if (instantiated_other.IsTypeRef()) {
15748 instantiated_other = TypeRef::Cast(instantiated_other).type(); 15788 instantiated_other = TypeRef::Cast(instantiated_other).type();
15749 } 15789 }
15750 if (instantiated_other.IsDynamicType()) { 15790 if (instantiated_other.IsDynamicType()) {
15751 return true; 15791 return true;
15752 } 15792 }
15753 } 15793 }
15754 other_type_arguments = instantiated_other.arguments(); 15794 other_type_arguments = instantiated_other.arguments();
15755 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); 15795 const bool other_is_dart_function = instantiated_other.IsDartFunctionType();
15756 if (other_is_dart_function || instantiated_other.IsFunctionType()) { 15796 if (other_is_dart_function || instantiated_other.IsFunctionType()) {
15757 // Check if this instance understands a call() method of a compatible type. 15797 // Check if this instance understands a call() method of a compatible type.
15758 Function& sig_fun = 15798 Function& sig_fun =
15759 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); 15799 Function::Handle(zone, cls.LookupCallFunctionForTypeTest());
15760 if (!sig_fun.IsNull()) { 15800 if (!sig_fun.IsNull()) {
15761 if (other_is_dart_function) { 15801 if (other_is_dart_function) {
15762 return true; 15802 return true;
15763 } 15803 }
15764 if (!sig_fun.HasInstantiatedSignature()) { 15804 if (!sig_fun.HasInstantiatedSignature()) {
15765 // TODO(regis): If sig_fun is generic, pass its type parameters 15805 const TypeArguments& function_type_arguments =
15766 // as function instantiator, otherwise pass null. 15806 TypeArguments::Handle(zone, sig_fun.type_parameters());
15767 // Pass the closure context as well to InstantiateSignatureFrom(). 15807 // TODO(regis): Pass the closure context to InstantiateSignatureFrom().
15768 // No bound error possible, since the instance exists. 15808 // No bound error possible, since the instance exists.
15769 sig_fun = sig_fun.InstantiateSignatureFrom(type_arguments, Heap::kOld); 15809 sig_fun = sig_fun.InstantiateSignatureFrom(
15810 type_arguments, function_type_arguments, Heap::kOld);
15770 } 15811 }
15771 const Function& other_signature = 15812 const Function& other_signature =
15772 Function::Handle(zone, Type::Cast(instantiated_other).signature()); 15813 Function::Handle(zone, Type::Cast(instantiated_other).signature());
15773 if (sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld)) { 15814 if (sig_fun.IsSubtypeOf(other_signature, bound_error, Heap::kOld)) {
15774 return true; 15815 return true;
15775 } 15816 }
15776 } 15817 }
15777 } 15818 }
15778 if (!instantiated_other.IsType()) { 15819 if (!instantiated_other.IsType()) {
15779 return false; 15820 return false;
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
16114 16155
16115 bool AbstractType::IsRecursive() const { 16156 bool AbstractType::IsRecursive() const {
16116 // AbstractType is an abstract class. 16157 // AbstractType is an abstract class.
16117 UNREACHABLE(); 16158 UNREACHABLE();
16118 return false; 16159 return false;
16119 } 16160 }
16120 16161
16121 16162
16122 RawAbstractType* AbstractType::InstantiateFrom( 16163 RawAbstractType* AbstractType::InstantiateFrom(
16123 const TypeArguments& instantiator_type_arguments, 16164 const TypeArguments& instantiator_type_arguments,
16165 const TypeArguments& function_type_arguments,
16124 Error* bound_error, 16166 Error* bound_error,
16125 TrailPtr instantiation_trail, 16167 TrailPtr instantiation_trail,
16126 TrailPtr bound_trail, 16168 TrailPtr bound_trail,
16127 Heap::Space space) const { 16169 Heap::Space space) const {
16128 // AbstractType is an abstract class. 16170 // AbstractType is an abstract class.
16129 UNREACHABLE(); 16171 UNREACHABLE();
16130 return NULL; 16172 return NULL;
16131 } 16173 }
16132 16174
16133 16175
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
16881 len = cls.NumTypeParameters(); // Check the type parameters only. 16923 len = cls.NumTypeParameters(); // Check the type parameters only.
16882 } 16924 }
16883 return (len == 0) || 16925 return (len == 0) ||
16884 args.IsSubvectorInstantiated(num_type_args - len, len, genericity, 16926 args.IsSubvectorInstantiated(num_type_args - len, len, genericity,
16885 trail); 16927 trail);
16886 } 16928 }
16887 16929
16888 16930
16889 RawAbstractType* Type::InstantiateFrom( 16931 RawAbstractType* Type::InstantiateFrom(
16890 const TypeArguments& instantiator_type_arguments, 16932 const TypeArguments& instantiator_type_arguments,
16933 const TypeArguments& function_type_arguments,
16891 Error* bound_error, 16934 Error* bound_error,
16892 TrailPtr instantiation_trail, 16935 TrailPtr instantiation_trail,
16893 TrailPtr bound_trail, 16936 TrailPtr bound_trail,
16894 Heap::Space space) const { 16937 Heap::Space space) const {
16895 Zone* zone = Thread::Current()->zone(); 16938 Zone* zone = Thread::Current()->zone();
16896 ASSERT(IsFinalized() || IsBeingFinalized()); 16939 ASSERT(IsFinalized() || IsBeingFinalized());
16897 ASSERT(!IsInstantiated()); 16940 ASSERT(!IsInstantiated());
16898 // Return the uninstantiated type unchanged if malformed. No copy needed. 16941 // Return the uninstantiated type unchanged if malformed. No copy needed.
16899 if (IsMalformed()) { 16942 if (IsMalformed()) {
16900 return raw(); 16943 return raw();
16901 } 16944 }
16902 // Note that the type class has to be resolved at this time, but not 16945 // Note that the type class has to be resolved at this time, but not
16903 // necessarily finalized yet. We may be checking bounds at compile time or 16946 // necessarily finalized yet. We may be checking bounds at compile time or
16904 // finalizing the type argument vector of a recursive type. 16947 // finalizing the type argument vector of a recursive type.
16905 const Class& cls = Class::Handle(zone, type_class()); 16948 const Class& cls = Class::Handle(zone, type_class());
16906 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); 16949 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments());
16907 Function& sig_fun = Function::Handle(zone, signature()); 16950 Function& sig_fun = Function::Handle(zone, signature());
16908 if (!type_arguments.IsNull() && 16951 if (!type_arguments.IsNull() &&
16909 (sig_fun.IsNull() || !type_arguments.IsInstantiated())) { 16952 (sig_fun.IsNull() || !type_arguments.IsInstantiated())) {
16910 // This type is uninstantiated because either its type arguments or its 16953 // This type is uninstantiated because either its type arguments or its
16911 // signature, or both are uninstantiated. 16954 // signature, or both are uninstantiated.
16912 // Note that the type arguments of a function type merely document the 16955 // Note that the type arguments of a function type merely document the
16913 // parameterization of a generic typedef. They are otherwise ignored. 16956 // parameterization of a generic typedef. They are otherwise ignored.
16914 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); 16957 ASSERT(type_arguments.Length() == cls.NumTypeArguments());
16915 type_arguments = 16958 type_arguments = type_arguments.InstantiateFrom(
16916 type_arguments.InstantiateFrom(instantiator_type_arguments, bound_error, 16959 instantiator_type_arguments, function_type_arguments, bound_error,
16917 instantiation_trail, bound_trail, space); 16960 instantiation_trail, bound_trail, space);
16918 } 16961 }
16919 // This uninstantiated type is not modified, as it can be instantiated 16962 // This uninstantiated type is not modified, as it can be instantiated
16920 // with different instantiators. Allocate a new instantiated version of it. 16963 // with different instantiators. Allocate a new instantiated version of it.
16921 const Type& instantiated_type = 16964 const Type& instantiated_type =
16922 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); 16965 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space));
16923 // Preserve the bound error if any. 16966 // Preserve the bound error if any.
16924 if (IsMalbounded()) { 16967 if (IsMalbounded()) {
16925 const LanguageError& bound_error = LanguageError::Handle(zone, error()); 16968 const LanguageError& bound_error = LanguageError::Handle(zone, error());
16926 instantiated_type.set_error(bound_error); 16969 instantiated_type.set_error(bound_error);
16927 } 16970 }
16928 // If this type is a function type, instantiate its signature. 16971 // If this type is a function type, instantiate its signature.
16929 if (!sig_fun.IsNull()) { 16972 if (!sig_fun.IsNull()) {
16930 // If we are finalizing a typedef, do not yet instantiate its signature. 16973 // If we are finalizing a typedef, do not yet instantiate its signature.
16931 // Other function types should never be instantiated while unfinalized. 16974 // Other function types should never be instantiated while unfinalized.
16932 if (IsFinalized()) { 16975 if (IsFinalized()) {
16933 // A generic typedef may actually declare an instantiated signature. 16976 // A generic typedef may actually declare an instantiated signature.
16934 if (!sig_fun.HasInstantiatedSignature()) { 16977 if (!sig_fun.HasInstantiatedSignature()) {
16935 sig_fun = sig_fun.InstantiateSignatureFrom(instantiator_type_arguments, 16978 sig_fun = sig_fun.InstantiateSignatureFrom(
16936 space); 16979 instantiator_type_arguments, function_type_arguments, space);
16937 } 16980 }
16938 } else { 16981 } else {
16939 ASSERT(cls.IsTypedefClass()); 16982 ASSERT(cls.IsTypedefClass());
16940 } 16983 }
16941 instantiated_type.set_signature(sig_fun); 16984 instantiated_type.set_signature(sig_fun);
16942 } 16985 }
16943 if (IsFinalized()) { 16986 if (IsFinalized()) {
16944 instantiated_type.SetIsFinalized(); 16987 instantiated_type.SetIsFinalized();
16945 } else { 16988 } else {
16946 instantiated_type.SetIsResolved(); 16989 instantiated_type.SetIsResolved();
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
17583 } 17626 }
17584 if (TestAndAddBuddyToTrail(&trail, AbstractType::Cast(other))) { 17627 if (TestAndAddBuddyToTrail(&trail, AbstractType::Cast(other))) {
17585 return true; 17628 return true;
17586 } 17629 }
17587 return AbstractType::Handle(type()).IsEquivalent(other, trail); 17630 return AbstractType::Handle(type()).IsEquivalent(other, trail);
17588 } 17631 }
17589 17632
17590 17633
17591 RawTypeRef* TypeRef::InstantiateFrom( 17634 RawTypeRef* TypeRef::InstantiateFrom(
17592 const TypeArguments& instantiator_type_arguments, 17635 const TypeArguments& instantiator_type_arguments,
17636 const TypeArguments& function_type_arguments,
17593 Error* bound_error, 17637 Error* bound_error,
17594 TrailPtr instantiation_trail, 17638 TrailPtr instantiation_trail,
17595 TrailPtr bound_trail, 17639 TrailPtr bound_trail,
17596 Heap::Space space) const { 17640 Heap::Space space) const {
17597 TypeRef& instantiated_type_ref = TypeRef::Handle(); 17641 TypeRef& instantiated_type_ref = TypeRef::Handle();
17598 instantiated_type_ref ^= OnlyBuddyInTrail(instantiation_trail); 17642 instantiated_type_ref ^= OnlyBuddyInTrail(instantiation_trail);
17599 if (!instantiated_type_ref.IsNull()) { 17643 if (!instantiated_type_ref.IsNull()) {
17600 return instantiated_type_ref.raw(); 17644 return instantiated_type_ref.raw();
17601 } 17645 }
17602 instantiated_type_ref = TypeRef::New(); 17646 instantiated_type_ref = TypeRef::New();
17603 AddOnlyBuddyToTrail(&instantiation_trail, instantiated_type_ref); 17647 AddOnlyBuddyToTrail(&instantiation_trail, instantiated_type_ref);
17604 17648
17605 AbstractType& ref_type = AbstractType::Handle(type()); 17649 AbstractType& ref_type = AbstractType::Handle(type());
17606 ASSERT(!ref_type.IsTypeRef()); 17650 ASSERT(!ref_type.IsTypeRef());
17607 AbstractType& instantiated_ref_type = AbstractType::Handle(); 17651 AbstractType& instantiated_ref_type = AbstractType::Handle();
17608 instantiated_ref_type = 17652 instantiated_ref_type = ref_type.InstantiateFrom(
17609 ref_type.InstantiateFrom(instantiator_type_arguments, bound_error, 17653 instantiator_type_arguments, function_type_arguments, bound_error,
17610 instantiation_trail, bound_trail, space); 17654 instantiation_trail, bound_trail, space);
17611 ASSERT(!instantiated_ref_type.IsTypeRef()); 17655 ASSERT(!instantiated_ref_type.IsTypeRef());
17612 instantiated_type_ref.set_type(instantiated_ref_type); 17656 instantiated_type_ref.set_type(instantiated_ref_type);
17613 return instantiated_type_ref.raw(); 17657 return instantiated_type_ref.raw();
17614 } 17658 }
17615 17659
17616 17660
17617 RawTypeRef* TypeRef::CloneUninstantiated(const Class& new_owner, 17661 RawTypeRef* TypeRef::CloneUninstantiated(const Class& new_owner,
17618 TrailPtr trail) const { 17662 TrailPtr trail) const {
17619 TypeRef& cloned_type_ref = TypeRef::Handle(); 17663 TypeRef& cloned_type_ref = TypeRef::Handle();
17620 cloned_type_ref ^= OnlyBuddyInTrail(trail); 17664 cloned_type_ref ^= OnlyBuddyInTrail(trail);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
17822 } 17866 }
17823 17867
17824 17868
17825 void TypeParameter::set_bound(const AbstractType& value) const { 17869 void TypeParameter::set_bound(const AbstractType& value) const {
17826 StorePointer(&raw_ptr()->bound_, value.raw()); 17870 StorePointer(&raw_ptr()->bound_, value.raw());
17827 } 17871 }
17828 17872
17829 17873
17830 RawAbstractType* TypeParameter::InstantiateFrom( 17874 RawAbstractType* TypeParameter::InstantiateFrom(
17831 const TypeArguments& instantiator_type_arguments, 17875 const TypeArguments& instantiator_type_arguments,
17876 const TypeArguments& function_type_arguments,
17832 Error* bound_error, 17877 Error* bound_error,
17833 TrailPtr instantiation_trail, 17878 TrailPtr instantiation_trail,
17834 TrailPtr bound_trail, 17879 TrailPtr bound_trail,
17835 Heap::Space space) const { 17880 Heap::Space space) const {
17836 ASSERT(IsFinalized()); 17881 ASSERT(IsFinalized());
17882 if (IsFunctionTypeParameter()) {
17883 if (parent_level() == 0) {
17884 if (function_type_arguments.IsNull()) {
17885 return Type::DynamicType();
17886 }
17887 return function_type_arguments.TypeAt(index());
17888 }
17889 // We need to find the type argument vector of the parent function at
17890 // parent_level() in the context.
17891 UNIMPLEMENTED();
17892 return function_type_arguments.TypeAt(index());
17893 }
17894 ASSERT(IsClassTypeParameter());
17837 if (instantiator_type_arguments.IsNull()) { 17895 if (instantiator_type_arguments.IsNull()) {
17838 return Type::DynamicType(); 17896 return Type::DynamicType();
17839 } 17897 }
17840 const AbstractType& type_arg = 17898 return instantiator_type_arguments.TypeAt(index());
17841 AbstractType::Handle(instantiator_type_arguments.TypeAt(index()));
17842 // There is no need to canonicalize the instantiated type parameter, since all 17899 // There is no need to canonicalize the instantiated type parameter, since all
17843 // type arguments are canonicalized at type finalization time. It would be too 17900 // type arguments are canonicalized at type finalization time. It would be too
17844 // early to canonicalize the returned type argument here, since instantiation 17901 // early to canonicalize the returned type argument here, since instantiation
17845 // not only happens at run time, but also during type finalization. 17902 // not only happens at run time, but also during type finalization.
17846 17903
17847 // If the instantiated type parameter type_arg is a BoundedType, it means that 17904 // If the instantiated type parameter type_arg is a BoundedType, it means that
17848 // it is still uninstantiated and that we are instantiating at finalization 17905 // it is still uninstantiated and that we are instantiating at finalization
17849 // time (i.e. compile time). 17906 // time (i.e. compile time).
17850 // Indeed, the instantiator (type arguments of an instance) is always 17907 // Indeed, the instantiator (type arguments of an instance) is always
17851 // instantiated at run time and any bounds were checked during allocation. 17908 // instantiated at run time and any bounds were checked during allocation.
17852 return type_arg.raw();
17853 } 17909 }
17854 17910
17855 17911
17856 bool TypeParameter::CheckBound(const AbstractType& bounded_type, 17912 bool TypeParameter::CheckBound(const AbstractType& bounded_type,
17857 const AbstractType& upper_bound, 17913 const AbstractType& upper_bound,
17858 Error* bound_error, 17914 Error* bound_error,
17859 TrailPtr bound_trail, 17915 TrailPtr bound_trail,
17860 Heap::Space space) const { 17916 Heap::Space space) const {
17861 ASSERT((bound_error != NULL) && bound_error->IsNull()); 17917 ASSERT((bound_error != NULL) && bound_error->IsNull());
17862 ASSERT(bounded_type.IsFinalized()); 17918 ASSERT(bounded_type.IsFinalized());
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
18153 void BoundedType::set_type_parameter(const TypeParameter& value) const { 18209 void BoundedType::set_type_parameter(const TypeParameter& value) const {
18154 // A null type parameter is set when marking a type malformed because of a 18210 // A null type parameter is set when marking a type malformed because of a
18155 // bound error at compile time. 18211 // bound error at compile time.
18156 ASSERT(value.IsNull() || value.IsFinalized()); 18212 ASSERT(value.IsNull() || value.IsFinalized());
18157 StorePointer(&raw_ptr()->type_parameter_, value.raw()); 18213 StorePointer(&raw_ptr()->type_parameter_, value.raw());
18158 } 18214 }
18159 18215
18160 18216
18161 RawAbstractType* BoundedType::InstantiateFrom( 18217 RawAbstractType* BoundedType::InstantiateFrom(
18162 const TypeArguments& instantiator_type_arguments, 18218 const TypeArguments& instantiator_type_arguments,
18219 const TypeArguments& function_type_arguments,
18163 Error* bound_error, 18220 Error* bound_error,
18164 TrailPtr instantiation_trail, 18221 TrailPtr instantiation_trail,
18165 TrailPtr bound_trail, 18222 TrailPtr bound_trail,
18166 Heap::Space space) const { 18223 Heap::Space space) const {
18167 ASSERT(IsFinalized()); 18224 ASSERT(IsFinalized());
18168 AbstractType& bounded_type = AbstractType::Handle(type()); 18225 AbstractType& bounded_type = AbstractType::Handle(type());
18169 ASSERT(bounded_type.IsFinalized()); 18226 ASSERT(bounded_type.IsFinalized());
18170 AbstractType& instantiated_bounded_type = 18227 AbstractType& instantiated_bounded_type =
18171 AbstractType::Handle(bounded_type.raw()); 18228 AbstractType::Handle(bounded_type.raw());
18172 if (!bounded_type.IsInstantiated()) { 18229 if (!bounded_type.IsInstantiated()) {
18173 instantiated_bounded_type = 18230 instantiated_bounded_type = bounded_type.InstantiateFrom(
18174 bounded_type.InstantiateFrom(instantiator_type_arguments, bound_error, 18231 instantiator_type_arguments, function_type_arguments, bound_error,
18175 instantiation_trail, bound_trail, space); 18232 instantiation_trail, bound_trail, space);
18176 // In case types of instantiator_type_arguments are not finalized 18233 // In case types of instantiator_type_arguments are not finalized
18177 // (or instantiated), then the instantiated_bounded_type is not finalized 18234 // (or instantiated), then the instantiated_bounded_type is not finalized
18178 // (or instantiated) either. 18235 // (or instantiated) either.
18179 // Note that instantiator_type_arguments must have the final length, though. 18236 // Note that instantiator_type_arguments must have the final length, though.
18180 } 18237 }
18181 if ((Isolate::Current()->type_checks()) && (bound_error != NULL) && 18238 if ((Isolate::Current()->type_checks()) && (bound_error != NULL) &&
18182 bound_error->IsNull()) { 18239 bound_error->IsNull()) {
18183 AbstractType& upper_bound = AbstractType::Handle(bound()); 18240 AbstractType& upper_bound = AbstractType::Handle(bound());
18184 ASSERT(upper_bound.IsFinalized()); 18241 ASSERT(upper_bound.IsFinalized());
18185 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType()); 18242 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType());
18186 AbstractType& instantiated_upper_bound = 18243 AbstractType& instantiated_upper_bound =
18187 AbstractType::Handle(upper_bound.raw()); 18244 AbstractType::Handle(upper_bound.raw());
18188 if (!upper_bound.IsInstantiated()) { 18245 if (!upper_bound.IsInstantiated()) {
18189 instantiated_upper_bound = 18246 instantiated_upper_bound = upper_bound.InstantiateFrom(
18190 upper_bound.InstantiateFrom(instantiator_type_arguments, bound_error, 18247 instantiator_type_arguments, function_type_arguments, bound_error,
18191 instantiation_trail, bound_trail, space); 18248 instantiation_trail, bound_trail, space);
18192 // The instantiated_upper_bound may not be finalized or instantiated. 18249 // The instantiated_upper_bound may not be finalized or instantiated.
18193 // See comment above. 18250 // See comment above.
18194 } 18251 }
18195 if (bound_error->IsNull()) { 18252 if (bound_error->IsNull()) {
18196 // Shortcut the F-bounded case where we have reached a fixpoint. 18253 // Shortcut the F-bounded case where we have reached a fixpoint.
18197 if (instantiated_bounded_type.Equals(bounded_type) && 18254 if (instantiated_bounded_type.Equals(bounded_type) &&
18198 instantiated_upper_bound.Equals(upper_bound)) { 18255 instantiated_upper_bound.Equals(upper_bound)) {
18199 return bounded_type.raw(); 18256 return bounded_type.raw();
18200 } 18257 }
18201 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); 18258 const TypeParameter& type_param = TypeParameter::Handle(type_parameter());
(...skipping 4877 matching lines...) Expand 10 before | Expand all | Expand 10 after
23079 return UserTag::null(); 23136 return UserTag::null();
23080 } 23137 }
23081 23138
23082 23139
23083 const char* UserTag::ToCString() const { 23140 const char* UserTag::ToCString() const {
23084 const String& tag_label = String::Handle(label()); 23141 const String& tag_label = String::Handle(label());
23085 return tag_label.ToCString(); 23142 return tag_label.ToCString();
23086 } 23143 }
23087 23144
23088 } // namespace dart 23145 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698