| 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 4565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4576 // argument is still being finalized and is definitely recursive. The null | 4576 // argument is still being finalized and is definitely recursive. The null |
| 4577 // type argument will be replaced by a non-null type before the type is | 4577 // type argument will be replaced by a non-null type before the type is |
| 4578 // marked as finalized. | 4578 // marked as finalized. |
| 4579 if (type.IsNull() || type.IsRecursive()) { | 4579 if (type.IsNull() || type.IsRecursive()) { |
| 4580 return true; | 4580 return true; |
| 4581 } | 4581 } |
| 4582 } | 4582 } |
| 4583 return false; | 4583 return false; |
| 4584 } | 4584 } |
| 4585 | 4585 |
| 4586 void TypeArguments::SetScopeFunction(const Function& function) const { |
| 4587 if (IsNull()) return; |
| 4588 const intptr_t num_types = Length(); |
| 4589 AbstractType& type = AbstractType::Handle(); |
| 4590 for (intptr_t i = 0; i < num_types; i++) { |
| 4591 type = TypeAt(i); |
| 4592 if (!type.IsNull()) { |
| 4593 type.SetScopeFunction(function); |
| 4594 } |
| 4595 } |
| 4596 } |
| 4597 |
| 4586 bool TypeArguments::IsDynamicTypes(bool raw_instantiated, | 4598 bool TypeArguments::IsDynamicTypes(bool raw_instantiated, |
| 4587 intptr_t from_index, | 4599 intptr_t from_index, |
| 4588 intptr_t len) const { | 4600 intptr_t len) const { |
| 4589 ASSERT(Length() >= (from_index + len)); | 4601 ASSERT(Length() >= (from_index + len)); |
| 4590 AbstractType& type = AbstractType::Handle(); | 4602 AbstractType& type = AbstractType::Handle(); |
| 4591 Class& type_class = Class::Handle(); | 4603 Class& type_class = Class::Handle(); |
| 4592 for (intptr_t i = 0; i < len; i++) { | 4604 for (intptr_t i = 0; i < len; i++) { |
| 4593 type = TypeAt(from_index + i); | 4605 type = TypeAt(from_index + i); |
| 4594 if (type.IsNull()) { | 4606 if (type.IsNull()) { |
| 4595 return false; | 4607 return false; |
| (...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5472 const Object& obj = Object::Handle(raw_ptr()->data_); | 5484 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5473 ASSERT(!obj.IsNull()); | 5485 ASSERT(!obj.IsNull()); |
| 5474 if (IsSignatureFunction()) { | 5486 if (IsSignatureFunction()) { |
| 5475 return SignatureData::Cast(obj).signature_type(); | 5487 return SignatureData::Cast(obj).signature_type(); |
| 5476 } else { | 5488 } else { |
| 5477 ASSERT(IsClosureFunction()); | 5489 ASSERT(IsClosureFunction()); |
| 5478 return ClosureData::Cast(obj).signature_type(); | 5490 return ClosureData::Cast(obj).signature_type(); |
| 5479 } | 5491 } |
| 5480 } | 5492 } |
| 5481 | 5493 |
| 5482 RawFunction* Function::CanonicalSignatureFunction(TrailPtr trail) const { | |
| 5483 ASSERT(!IsSignatureFunction()); | |
| 5484 Zone* zone = Thread::Current()->zone(); | |
| 5485 Function& parent = Function::Handle(zone, parent_function()); | |
| 5486 if (!parent.IsNull() && !parent.IsSignatureFunction()) { | |
| 5487 // Make sure the parent function is also a signature function. | |
| 5488 parent = parent.CanonicalSignatureFunction(trail); | |
| 5489 } | |
| 5490 const Class& owner = Class::Handle(zone, Owner()); | |
| 5491 const Function& sig_fun = Function::Handle( | |
| 5492 zone, | |
| 5493 Function::NewSignatureFunction(owner, parent, TokenPosition::kNoSource)); | |
| 5494 // In case of a generic function, the function type parameters in the | |
| 5495 // signature will still refer to the original function. This should not | |
| 5496 // be a problem, since once finalized the indices will be identical. | |
| 5497 sig_fun.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); | |
| 5498 ASSERT(HasGenericParent() == sig_fun.HasGenericParent()); | |
| 5499 ASSERT(IsGeneric() == sig_fun.IsGeneric()); | |
| 5500 AbstractType& type = AbstractType::Handle(zone); | |
| 5501 type = result_type(); | |
| 5502 type = type.Canonicalize(trail); | |
| 5503 sig_fun.set_result_type(type); | |
| 5504 const intptr_t num_params = NumParameters(); | |
| 5505 sig_fun.set_num_fixed_parameters(num_fixed_parameters()); | |
| 5506 sig_fun.SetNumOptionalParameters(NumOptionalParameters(), | |
| 5507 HasOptionalPositionalParameters()); | |
| 5508 sig_fun.set_parameter_types( | |
| 5509 Array::Handle(Array::New(num_params, Heap::kOld))); | |
| 5510 for (intptr_t i = 0; i < num_params; i++) { | |
| 5511 type = ParameterTypeAt(i); | |
| 5512 type = type.Canonicalize(trail); | |
| 5513 sig_fun.SetParameterTypeAt(i, type); | |
| 5514 } | |
| 5515 sig_fun.set_parameter_names(Array::Handle(zone, parameter_names())); | |
| 5516 return sig_fun.raw(); | |
| 5517 } | |
| 5518 | |
| 5519 RawType* Function::SignatureType() const { | 5494 RawType* Function::SignatureType() const { |
| 5520 Type& type = Type::Handle(ExistingSignatureType()); | 5495 Type& type = Type::Handle(ExistingSignatureType()); |
| 5521 if (type.IsNull()) { | 5496 if (type.IsNull()) { |
| 5522 // The function type of this function is not yet cached and needs to be | 5497 // The function type of this function is not yet cached and needs to be |
| 5523 // constructed and cached here. | 5498 // constructed and cached here. |
| 5524 // A function type is type parameterized in the same way as the owner class | 5499 // A function type is type parameterized in the same way as the owner class |
| 5525 // of its non-static signature function. | 5500 // of its non-static signature function. |
| 5526 // It is not type parameterized if its signature function is static, or if | 5501 // It is not type parameterized if its signature function is static, or if |
| 5527 // none of its result type or formal parameter types are type parameterized. | 5502 // none of its result type or formal parameter types are type parameterized. |
| 5528 // Unless the function type is a generic typedef, the type arguments of the | 5503 // Unless the function type is a generic typedef, the type arguments of the |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5762 ASSERT(raw_ptr()->data_ == Object::null()); | 5737 ASSERT(raw_ptr()->data_ == Object::null()); |
| 5763 const Array& pair = Array::Handle(Array::New(2, Heap::kOld)); | 5738 const Array& pair = Array::Handle(Array::New(2, Heap::kOld)); |
| 5764 pair.SetAt(0, value); | 5739 pair.SetAt(0, value); |
| 5765 // pair[1] will be the implicit closure function if needed. | 5740 // pair[1] will be the implicit closure function if needed. |
| 5766 set_data(pair); | 5741 set_data(pair); |
| 5767 } | 5742 } |
| 5768 | 5743 |
| 5769 void Function::set_result_type(const AbstractType& value) const { | 5744 void Function::set_result_type(const AbstractType& value) const { |
| 5770 ASSERT(!value.IsNull()); | 5745 ASSERT(!value.IsNull()); |
| 5771 StorePointer(&raw_ptr()->result_type_, value.raw()); | 5746 StorePointer(&raw_ptr()->result_type_, value.raw()); |
| 5772 if (value.IsFunctionType()) { | |
| 5773 // The function result type may refer to this function's type parameters. | |
| 5774 // Change its parent function. | |
| 5775 const Function& result_signature_function = | |
| 5776 Function::Handle(Type::Cast(value).signature()); | |
| 5777 result_signature_function.set_parent_function(*this); | |
| 5778 } | |
| 5779 } | 5747 } |
| 5780 | 5748 |
| 5781 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const { | 5749 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const { |
| 5782 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); | 5750 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); |
| 5783 return AbstractType::RawCast(parameter_types.At(index)); | 5751 return AbstractType::RawCast(parameter_types.At(index)); |
| 5784 } | 5752 } |
| 5785 | 5753 |
| 5786 void Function::SetParameterTypeAt(intptr_t index, | 5754 void Function::SetParameterTypeAt(intptr_t index, |
| 5787 const AbstractType& value) const { | 5755 const AbstractType& value) const { |
| 5788 ASSERT(!value.IsNull()); | 5756 ASSERT(!value.IsNull()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5829 | 5797 |
| 5830 intptr_t Function::NumParentTypeParameters() const { | 5798 intptr_t Function::NumParentTypeParameters() const { |
| 5831 if (IsImplicitClosureFunction()) { | 5799 if (IsImplicitClosureFunction()) { |
| 5832 return 0; | 5800 return 0; |
| 5833 } | 5801 } |
| 5834 Thread* thread = Thread::Current(); | 5802 Thread* thread = Thread::Current(); |
| 5835 Function& parent = Function::Handle(parent_function()); | 5803 Function& parent = Function::Handle(parent_function()); |
| 5836 intptr_t num_parent_type_params = 0; | 5804 intptr_t num_parent_type_params = 0; |
| 5837 while (!parent.IsNull()) { | 5805 while (!parent.IsNull()) { |
| 5838 num_parent_type_params += parent.NumTypeParameters(thread); | 5806 num_parent_type_params += parent.NumTypeParameters(thread); |
| 5807 if (parent.IsImplicitClosureFunction()) break; |
| 5839 parent ^= parent.parent_function(); | 5808 parent ^= parent.parent_function(); |
| 5840 } | 5809 } |
| 5841 return num_parent_type_params; | 5810 return num_parent_type_params; |
| 5842 } | 5811 } |
| 5843 | 5812 |
| 5813 void Function::PrintSignatureTypes() const { |
| 5814 Function& sig_fun = Function::Handle(raw()); |
| 5815 Type& sig_type = Type::Handle(); |
| 5816 while (!sig_fun.IsNull()) { |
| 5817 sig_type = sig_fun.SignatureType(); |
| 5818 THR_Print("%s%s\n", |
| 5819 sig_fun.IsImplicitClosureFunction() ? "implicit closure: " : "", |
| 5820 sig_type.ToCString()); |
| 5821 sig_fun ^= sig_fun.parent_function(); |
| 5822 } |
| 5823 } |
| 5824 |
| 5844 RawTypeParameter* Function::LookupTypeParameter( | 5825 RawTypeParameter* Function::LookupTypeParameter( |
| 5845 const String& type_name, | 5826 const String& type_name, |
| 5846 intptr_t* function_level) const { | 5827 intptr_t* function_level) const { |
| 5847 ASSERT(!type_name.IsNull()); | 5828 ASSERT(!type_name.IsNull()); |
| 5848 Thread* thread = Thread::Current(); | 5829 Thread* thread = Thread::Current(); |
| 5849 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 5830 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
| 5850 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); | 5831 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); |
| 5851 REUSABLE_STRING_HANDLESCOPE(thread); | 5832 REUSABLE_STRING_HANDLESCOPE(thread); |
| 5852 REUSABLE_FUNCTION_HANDLESCOPE(thread); | 5833 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
| 5853 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 5834 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6290 // function is compiled. | 6271 // function is compiled. |
| 6291 return true; | 6272 return true; |
| 6292 } | 6273 } |
| 6293 | 6274 |
| 6294 RawFunction* Function::InstantiateSignatureFrom( | 6275 RawFunction* Function::InstantiateSignatureFrom( |
| 6295 const TypeArguments& instantiator_type_arguments, | 6276 const TypeArguments& instantiator_type_arguments, |
| 6296 const TypeArguments& function_type_arguments, | 6277 const TypeArguments& function_type_arguments, |
| 6297 Heap::Space space) const { | 6278 Heap::Space space) const { |
| 6298 Zone* zone = Thread::Current()->zone(); | 6279 Zone* zone = Thread::Current()->zone(); |
| 6299 const Object& owner = Object::Handle(zone, RawOwner()); | 6280 const Object& owner = Object::Handle(zone, RawOwner()); |
| 6281 // Note that parent pointers in newly instantiated signatures still points to |
| 6282 // the original uninstantiated parent signatures. That is not a problem. |
| 6300 const Function& parent = Function::Handle(zone, parent_function()); | 6283 const Function& parent = Function::Handle(zone, parent_function()); |
| 6301 ASSERT(!HasInstantiatedSignature()); | 6284 ASSERT(!HasInstantiatedSignature()); |
| 6302 Function& sig = Function::Handle( | 6285 Function& sig = Function::Handle( |
| 6303 zone, Function::NewSignatureFunction(owner, parent, | 6286 zone, Function::NewSignatureFunction(owner, parent, |
| 6304 TokenPosition::kNoSource, space)); | 6287 TokenPosition::kNoSource, space)); |
| 6305 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); | 6288 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); |
| 6306 AbstractType& type = AbstractType::Handle(zone, result_type()); | 6289 AbstractType& type = AbstractType::Handle(zone, result_type()); |
| 6307 if (!type.IsInstantiated()) { | 6290 if (!type.IsInstantiated()) { |
| 6308 type = | 6291 type = |
| 6309 type.InstantiateFrom(instantiator_type_arguments, | 6292 type.InstantiateFrom(instantiator_type_arguments, |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6964 const AbstractType& res_type = AbstractType::Handle(zone, result_type()); | 6947 const AbstractType& res_type = AbstractType::Handle(zone, result_type()); |
| 6965 name = res_type.BuildName(name_visibility); | 6948 name = res_type.BuildName(name_visibility); |
| 6966 pieces.Add(name); | 6949 pieces.Add(name); |
| 6967 return Symbols::FromConcatAll(thread, pieces); | 6950 return Symbols::FromConcatAll(thread, pieces); |
| 6968 } | 6951 } |
| 6969 | 6952 |
| 6970 bool Function::HasInstantiatedSignature(Genericity genericity, | 6953 bool Function::HasInstantiatedSignature(Genericity genericity, |
| 6971 intptr_t num_free_fun_type_params, | 6954 intptr_t num_free_fun_type_params, |
| 6972 TrailPtr trail) const { | 6955 TrailPtr trail) const { |
| 6973 if (genericity != kCurrentClass) { | 6956 if (genericity != kCurrentClass) { |
| 6974 // We only consider the function type parameters declared by the parents of | 6957 // A generic typedef may declare a non-generic function type and get |
| 6975 // this signature function. | 6958 // instantiated with unrelated function type parameters. In that case, its |
| 6976 const int num_parent_type_params = NumParentTypeParameters(); | 6959 // signature is still uninstantiated, because these type parameters are |
| 6977 if (num_parent_type_params < num_free_fun_type_params) { | 6960 // free (they are not declared by the typedef). |
| 6978 num_free_fun_type_params = num_parent_type_params; | 6961 // For that reason, we only adjust num_free_fun_type_params if this |
| 6962 // signature is generic or has a generic parent. |
| 6963 if (IsGeneric() || HasGenericParent()) { |
| 6964 // We only consider the function type parameters declared by the parents |
| 6965 // of this signature function as free. |
| 6966 const int num_parent_type_params = NumParentTypeParameters(); |
| 6967 if (num_parent_type_params < num_free_fun_type_params) { |
| 6968 num_free_fun_type_params = num_parent_type_params; |
| 6969 } |
| 6979 } | 6970 } |
| 6971 // TODO(regis): Should we check the owners of the function type parameters |
| 6972 // in addition to their indexes to decide if they are free or not? |
| 6980 } | 6973 } |
| 6981 AbstractType& type = AbstractType::Handle(result_type()); | 6974 AbstractType& type = AbstractType::Handle(result_type()); |
| 6982 if (!type.IsInstantiated(genericity, num_free_fun_type_params, trail)) { | 6975 if (!type.IsInstantiated(genericity, num_free_fun_type_params, trail)) { |
| 6983 return false; | 6976 return false; |
| 6984 } | 6977 } |
| 6985 const intptr_t num_parameters = NumParameters(); | 6978 const intptr_t num_parameters = NumParameters(); |
| 6986 for (intptr_t i = 0; i < num_parameters; i++) { | 6979 for (intptr_t i = 0; i < num_parameters; i++) { |
| 6987 type = ParameterTypeAt(i); | 6980 type = ParameterTypeAt(i); |
| 6988 if (!type.IsInstantiated(genericity, num_free_fun_type_params, trail)) { | 6981 if (!type.IsInstantiated(genericity, num_free_fun_type_params, trail)) { |
| 6989 return false; | 6982 return false; |
| (...skipping 8528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15518 UNREACHABLE(); | 15511 UNREACHABLE(); |
| 15519 return false; | 15512 return false; |
| 15520 } | 15513 } |
| 15521 | 15514 |
| 15522 bool AbstractType::IsRecursive() const { | 15515 bool AbstractType::IsRecursive() const { |
| 15523 // AbstractType is an abstract class. | 15516 // AbstractType is an abstract class. |
| 15524 UNREACHABLE(); | 15517 UNREACHABLE(); |
| 15525 return false; | 15518 return false; |
| 15526 } | 15519 } |
| 15527 | 15520 |
| 15521 void AbstractType::SetScopeFunction(const Function& function) const { |
| 15522 // AbstractType is an abstract class. |
| 15523 UNREACHABLE(); |
| 15524 } |
| 15525 |
| 15528 RawAbstractType* AbstractType::InstantiateFrom( | 15526 RawAbstractType* AbstractType::InstantiateFrom( |
| 15529 const TypeArguments& instantiator_type_arguments, | 15527 const TypeArguments& instantiator_type_arguments, |
| 15530 const TypeArguments& function_type_arguments, | 15528 const TypeArguments& function_type_arguments, |
| 15531 Error* bound_error, | 15529 Error* bound_error, |
| 15532 TrailPtr instantiation_trail, | 15530 TrailPtr instantiation_trail, |
| 15533 TrailPtr bound_trail, | 15531 TrailPtr bound_trail, |
| 15534 Heap::Space space) const { | 15532 Heap::Space space) const { |
| 15535 // AbstractType is an abstract class. | 15533 // AbstractType is an abstract class. |
| 15536 UNREACHABLE(); | 15534 UNREACHABLE(); |
| 15537 return NULL; | 15535 return NULL; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15919 // For example, with class A<K, V extends K>, new A<T, T> called from within | 15917 // For example, with class A<K, V extends K>, new A<T, T> called from within |
| 15920 // a class B<T> will never require a run time bound check, even if T is | 15918 // a class B<T> will never require a run time bound check, even if T is |
| 15921 // uninstantiated at compile time. | 15919 // uninstantiated at compile time. |
| 15922 if (IsTypeParameter()) { | 15920 if (IsTypeParameter()) { |
| 15923 const TypeParameter& type_param = TypeParameter::Cast(*this); | 15921 const TypeParameter& type_param = TypeParameter::Cast(*this); |
| 15924 if (other.IsTypeParameter()) { | 15922 if (other.IsTypeParameter()) { |
| 15925 const TypeParameter& other_type_param = TypeParameter::Cast(other); | 15923 const TypeParameter& other_type_param = TypeParameter::Cast(other); |
| 15926 if (type_param.Equals(other_type_param)) { | 15924 if (type_param.Equals(other_type_param)) { |
| 15927 return true; | 15925 return true; |
| 15928 } | 15926 } |
| 15929 // TODO(regis): Should we update TypeParameter::IsEquivalent() instead? | |
| 15930 if (type_param.IsFunctionTypeParameter() && | 15927 if (type_param.IsFunctionTypeParameter() && |
| 15931 other_type_param.IsFunctionTypeParameter() && | 15928 other_type_param.IsFunctionTypeParameter() && |
| 15932 type_param.IsFinalized() && other_type_param.IsFinalized()) { | 15929 type_param.IsFinalized() && other_type_param.IsFinalized()) { |
| 15933 // To be compatible, the function type parameters should be declared at | 15930 // To be compatible, the function type parameters should be declared at |
| 15934 // the same position in the generic function. Their index therefore | 15931 // the same position in the generic function. Their index therefore |
| 15935 // needs adjustement before comparison. | 15932 // needs adjustement before comparison. |
| 15936 // Example: 'foo<F>(bar<B>(B b)) { }' and 'baz<Z>(Z z) { }', baz can be | 15933 // Example: 'foo<F>(bar<B>(B b)) { }' and 'baz<Z>(Z z) { }', baz can be |
| 15937 // assigned to bar, although B has index 1 and Z index 0. | 15934 // assigned to bar, although B has index 1 and Z index 0. |
| 15938 const Function& sig_fun = | 15935 const Function& sig_fun = |
| 15939 Function::Handle(zone, type_param.parameterized_function()); | 15936 Function::Handle(zone, type_param.parameterized_function()); |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16502 return false; | 16499 return false; |
| 16503 } | 16500 } |
| 16504 } | 16501 } |
| 16505 return true; | 16502 return true; |
| 16506 } | 16503 } |
| 16507 | 16504 |
| 16508 bool Type::IsRecursive() const { | 16505 bool Type::IsRecursive() const { |
| 16509 return TypeArguments::Handle(arguments()).IsRecursive(); | 16506 return TypeArguments::Handle(arguments()).IsRecursive(); |
| 16510 } | 16507 } |
| 16511 | 16508 |
| 16509 void Type::SetScopeFunction(const Function& function) const { |
| 16510 TypeArguments::Handle(arguments()).SetScopeFunction(function); |
| 16511 if (IsFunctionType()) { |
| 16512 const Function& sig_fun = Function::Handle(signature()); |
| 16513 sig_fun.set_parent_function(function); |
| 16514 // No need to traverse result type and parameter types (and bounds, in case |
| 16515 // sig_fun is generic), since they have sig_fun as scope function. |
| 16516 } |
| 16517 } |
| 16518 |
| 16512 RawAbstractType* Type::CloneUnfinalized() const { | 16519 RawAbstractType* Type::CloneUnfinalized() const { |
| 16513 ASSERT(IsResolved()); | 16520 ASSERT(IsResolved()); |
| 16514 if (IsFinalized()) { | 16521 if (IsFinalized()) { |
| 16515 return raw(); | 16522 return raw(); |
| 16516 } | 16523 } |
| 16517 ASSERT(!IsMalformed()); // Malformed types are finalized. | 16524 ASSERT(!IsMalformed()); // Malformed types are finalized. |
| 16518 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. | 16525 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. |
| 16519 Zone* zone = Thread::Current()->zone(); | 16526 Zone* zone = Thread::Current()->zone(); |
| 16520 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | 16527 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
| 16521 const TypeArguments& type_args_clone = | 16528 const TypeArguments& type_args_clone = |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16740 if (IsCanonical()) { | 16747 if (IsCanonical()) { |
| 16741 // Canonicalizing type_args canonicalized this type as a side effect. | 16748 // Canonicalizing type_args canonicalized this type as a side effect. |
| 16742 ASSERT(IsRecursive()); | 16749 ASSERT(IsRecursive()); |
| 16743 // Cycles via typedefs are detected and disallowed, but a function type | 16750 // Cycles via typedefs are detected and disallowed, but a function type |
| 16744 // can be recursive due to a cycle in its type arguments. | 16751 // can be recursive due to a cycle in its type arguments. |
| 16745 return this->raw(); | 16752 return this->raw(); |
| 16746 } | 16753 } |
| 16747 set_arguments(type_args); | 16754 set_arguments(type_args); |
| 16748 ASSERT(type_args.IsNull() || type_args.IsOld()); | 16755 ASSERT(type_args.IsNull() || type_args.IsOld()); |
| 16749 | 16756 |
| 16750 // In case of a function type, replace the actual function by a signature | 16757 // In case of a function type, the signature has already been canonicalized |
| 16751 // function. | 16758 // when finalizing the type and passing kCanonicalize as finalization. |
| 16752 if (IsFunctionType()) { | 16759 // Therefore, we do not canonicalize the signature here, which would have no |
| 16753 Function& sig_fun = Function::Handle(zone, signature()); | 16760 // effect on selecting the canonical type anyway, because the function |
| 16754 if (!sig_fun.IsSignatureFunction()) { | 16761 // object is not replaced when canonicalizing the signature. |
| 16755 sig_fun = sig_fun.CanonicalSignatureFunction(trail); | |
| 16756 set_signature(sig_fun); | |
| 16757 // Note that the signature type of the signature function may be | |
| 16758 // different than the type being canonicalized. | |
| 16759 // Consider F<int> being canonicalized, with F being a typedef and F<T> | |
| 16760 // being its signature type. | |
| 16761 } | |
| 16762 } | |
| 16763 | 16762 |
| 16764 // Check to see if the type got added to canonical list as part of the | 16763 // Check to see if the type got added to canonical list as part of the |
| 16765 // type arguments canonicalization. | 16764 // type arguments canonicalization. |
| 16766 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); | 16765 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); |
| 16767 CanonicalTypeSet table(zone, object_store->canonical_types()); | 16766 CanonicalTypeSet table(zone, object_store->canonical_types()); |
| 16768 type ^= table.GetOrNull(CanonicalTypeKey(*this)); | 16767 type ^= table.GetOrNull(CanonicalTypeKey(*this)); |
| 16769 if (type.IsNull()) { | 16768 if (type.IsNull()) { |
| 16770 // Add this Type into the canonical list of types. | 16769 // Add this Type into the canonical list of types. |
| 16771 if (this->IsNew()) { | 16770 if (this->IsNew()) { |
| 16772 type ^= Object::Clone(*this, Heap::kOld); | 16771 type ^= Object::Clone(*this, Heap::kOld); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16986 if (!other.IsAbstractType()) { | 16985 if (!other.IsAbstractType()) { |
| 16987 return false; | 16986 return false; |
| 16988 } | 16987 } |
| 16989 if (TestAndAddBuddyToTrail(&trail, AbstractType::Cast(other))) { | 16988 if (TestAndAddBuddyToTrail(&trail, AbstractType::Cast(other))) { |
| 16990 return true; | 16989 return true; |
| 16991 } | 16990 } |
| 16992 const AbstractType& ref_type = AbstractType::Handle(type()); | 16991 const AbstractType& ref_type = AbstractType::Handle(type()); |
| 16993 return !ref_type.IsNull() && ref_type.IsEquivalent(other, trail); | 16992 return !ref_type.IsNull() && ref_type.IsEquivalent(other, trail); |
| 16994 } | 16993 } |
| 16995 | 16994 |
| 16995 void TypeRef::SetScopeFunction(const Function& function) const { |
| 16996 // TypeRefs are created during finalization, when scope functions have |
| 16997 // already been adjusted. |
| 16998 UNREACHABLE(); |
| 16999 } |
| 17000 |
| 16996 RawTypeRef* TypeRef::InstantiateFrom( | 17001 RawTypeRef* TypeRef::InstantiateFrom( |
| 16997 const TypeArguments& instantiator_type_arguments, | 17002 const TypeArguments& instantiator_type_arguments, |
| 16998 const TypeArguments& function_type_arguments, | 17003 const TypeArguments& function_type_arguments, |
| 16999 Error* bound_error, | 17004 Error* bound_error, |
| 17000 TrailPtr instantiation_trail, | 17005 TrailPtr instantiation_trail, |
| 17001 TrailPtr bound_trail, | 17006 TrailPtr bound_trail, |
| 17002 Heap::Space space) const { | 17007 Heap::Space space) const { |
| 17003 TypeRef& instantiated_type_ref = TypeRef::Handle(); | 17008 TypeRef& instantiated_type_ref = TypeRef::Handle(); |
| 17004 instantiated_type_ref ^= OnlyBuddyInTrail(instantiation_trail); | 17009 instantiated_type_ref ^= OnlyBuddyInTrail(instantiation_trail); |
| 17005 if (!instantiated_type_ref.IsNull()) { | 17010 if (!instantiated_type_ref.IsNull()) { |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17509 const AbstractType& this_bound = AbstractType::Handle(bound()); | 17514 const AbstractType& this_bound = AbstractType::Handle(bound()); |
| 17510 const AbstractType& other_bound = AbstractType::Handle(other_bounded.bound()); | 17515 const AbstractType& other_bound = AbstractType::Handle(other_bounded.bound()); |
| 17511 return this_bound.IsFinalized() && other_bound.IsFinalized() && | 17516 return this_bound.IsFinalized() && other_bound.IsFinalized() && |
| 17512 this_bound.Equals(other_bound); // Different graph, do not pass trail. | 17517 this_bound.Equals(other_bound); // Different graph, do not pass trail. |
| 17513 } | 17518 } |
| 17514 | 17519 |
| 17515 bool BoundedType::IsRecursive() const { | 17520 bool BoundedType::IsRecursive() const { |
| 17516 return AbstractType::Handle(type()).IsRecursive(); | 17521 return AbstractType::Handle(type()).IsRecursive(); |
| 17517 } | 17522 } |
| 17518 | 17523 |
| 17524 void BoundedType::SetScopeFunction(const Function& function) const { |
| 17525 AbstractType::Handle(type()).SetScopeFunction(function); |
| 17526 AbstractType::Handle(bound()).SetScopeFunction(function); |
| 17527 } |
| 17528 |
| 17519 void BoundedType::set_type(const AbstractType& value) const { | 17529 void BoundedType::set_type(const AbstractType& value) const { |
| 17520 ASSERT(value.IsFinalized() || value.IsBeingFinalized() || | 17530 ASSERT(value.IsFinalized() || value.IsBeingFinalized() || |
| 17521 value.IsTypeParameter()); | 17531 value.IsTypeParameter()); |
| 17522 ASSERT(!value.IsMalformed()); | 17532 ASSERT(!value.IsMalformed()); |
| 17523 StorePointer(&raw_ptr()->type_, value.raw()); | 17533 StorePointer(&raw_ptr()->type_, value.raw()); |
| 17524 } | 17534 } |
| 17525 | 17535 |
| 17526 void BoundedType::set_bound(const AbstractType& value) const { | 17536 void BoundedType::set_bound(const AbstractType& value) const { |
| 17527 // The bound may still be unfinalized because of legal cycles. | 17537 // The bound may still be unfinalized because of legal cycles. |
| 17528 // It must be finalized before it is checked at run time, though. | 17538 // It must be finalized before it is checked at run time, though. |
| (...skipping 4708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22237 } | 22247 } |
| 22238 return UserTag::null(); | 22248 return UserTag::null(); |
| 22239 } | 22249 } |
| 22240 | 22250 |
| 22241 const char* UserTag::ToCString() const { | 22251 const char* UserTag::ToCString() const { |
| 22242 const String& tag_label = String::Handle(label()); | 22252 const String& tag_label = String::Handle(label()); |
| 22243 return tag_label.ToCString(); | 22253 return tag_label.ToCString(); |
| 22244 } | 22254 } |
| 22245 | 22255 |
| 22246 } // namespace dart | 22256 } // namespace dart |
| OLD | NEW |