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 5545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5556 } | 5556 } |
5557 return type.raw(); | 5557 return type.raw(); |
5558 } | 5558 } |
5559 | 5559 |
5560 | 5560 |
5561 void Function::SetSignatureType(const Type& value) const { | 5561 void Function::SetSignatureType(const Type& value) const { |
5562 const Object& obj = Object::Handle(raw_ptr()->data_); | 5562 const Object& obj = Object::Handle(raw_ptr()->data_); |
5563 ASSERT(!obj.IsNull()); | 5563 ASSERT(!obj.IsNull()); |
5564 if (IsSignatureFunction()) { | 5564 if (IsSignatureFunction()) { |
5565 SignatureData::Cast(obj).set_signature_type(value); | 5565 SignatureData::Cast(obj).set_signature_type(value); |
| 5566 ASSERT(!value.IsCanonical() || (value.signature() == this->raw())); |
5566 } else { | 5567 } else { |
5567 ASSERT(IsClosureFunction()); | 5568 ASSERT(IsClosureFunction()); |
5568 ClosureData::Cast(obj).set_signature_type(value); | 5569 ClosureData::Cast(obj).set_signature_type(value); |
5569 } | 5570 } |
5570 } | 5571 } |
5571 | 5572 |
5572 | 5573 |
5573 bool Function::IsRedirectingFactory() const { | 5574 bool Function::IsRedirectingFactory() const { |
5574 if (!IsFactory() || !is_redirecting()) { | 5575 if (!IsFactory() || !is_redirecting()) { |
5575 return false; | 5576 return false; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5715 } | 5716 } |
5716 | 5717 |
5717 | 5718 |
5718 void Function::set_name(const String& value) const { | 5719 void Function::set_name(const String& value) const { |
5719 ASSERT(value.IsSymbol()); | 5720 ASSERT(value.IsSymbol()); |
5720 StorePointer(&raw_ptr()->name_, value.raw()); | 5721 StorePointer(&raw_ptr()->name_, value.raw()); |
5721 } | 5722 } |
5722 | 5723 |
5723 | 5724 |
5724 void Function::set_owner(const Object& value) const { | 5725 void Function::set_owner(const Object& value) const { |
5725 ASSERT(!value.IsNull()); | 5726 ASSERT(!value.IsNull() || IsSignatureFunction()); |
5726 StorePointer(&raw_ptr()->owner_, value.raw()); | 5727 StorePointer(&raw_ptr()->owner_, value.raw()); |
5727 } | 5728 } |
5728 | 5729 |
5729 | 5730 |
5730 RawRegExp* Function::regexp() const { | 5731 RawRegExp* Function::regexp() const { |
5731 ASSERT(kind() == RawFunction::kIrregexpFunction); | 5732 ASSERT(kind() == RawFunction::kIrregexpFunction); |
5732 const Array& pair = Array::Cast(Object::Handle(raw_ptr()->data_)); | 5733 const Array& pair = Array::Cast(Object::Handle(raw_ptr()->data_)); |
5733 return RegExp::RawCast(pair.At(0)); | 5734 return RegExp::RawCast(pair.At(0)); |
5734 } | 5735 } |
5735 | 5736 |
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6919 type = ParameterTypeAt(i); | 6920 type = ParameterTypeAt(i); |
6920 if (!type.IsInstantiated()) { | 6921 if (!type.IsInstantiated()) { |
6921 return false; | 6922 return false; |
6922 } | 6923 } |
6923 } | 6924 } |
6924 return true; | 6925 return true; |
6925 } | 6926 } |
6926 | 6927 |
6927 | 6928 |
6928 RawClass* Function::Owner() const { | 6929 RawClass* Function::Owner() const { |
| 6930 if (raw_ptr()->owner_ == Object::null()) { |
| 6931 ASSERT(IsSignatureFunction()); |
| 6932 return Class::null(); |
| 6933 } |
6929 if (raw_ptr()->owner_->IsClass()) { | 6934 if (raw_ptr()->owner_->IsClass()) { |
6930 return Class::RawCast(raw_ptr()->owner_); | 6935 return Class::RawCast(raw_ptr()->owner_); |
6931 } | 6936 } |
6932 const Object& obj = Object::Handle(raw_ptr()->owner_); | 6937 const Object& obj = Object::Handle(raw_ptr()->owner_); |
6933 ASSERT(obj.IsPatchClass()); | 6938 ASSERT(obj.IsPatchClass()); |
6934 return PatchClass::Cast(obj).patched_class(); | 6939 return PatchClass::Cast(obj).patched_class(); |
6935 } | 6940 } |
6936 | 6941 |
6937 | 6942 |
6938 RawClass* Function::origin() const { | 6943 RawClass* Function::origin() const { |
| 6944 if (raw_ptr()->owner_ == Object::null()) { |
| 6945 ASSERT(IsSignatureFunction()); |
| 6946 return Class::null(); |
| 6947 } |
6939 if (raw_ptr()->owner_->IsClass()) { | 6948 if (raw_ptr()->owner_->IsClass()) { |
6940 return Class::RawCast(raw_ptr()->owner_); | 6949 return Class::RawCast(raw_ptr()->owner_); |
6941 } | 6950 } |
6942 const Object& obj = Object::Handle(raw_ptr()->owner_); | 6951 const Object& obj = Object::Handle(raw_ptr()->owner_); |
6943 ASSERT(obj.IsPatchClass()); | 6952 ASSERT(obj.IsPatchClass()); |
6944 return PatchClass::Cast(obj).origin_class(); | 6953 return PatchClass::Cast(obj).origin_class(); |
6945 } | 6954 } |
6946 | 6955 |
6947 | 6956 |
6948 RawScript* Function::script() const { | 6957 RawScript* Function::script() const { |
6949 // NOTE(turnidge): If you update this function, you probably want to | 6958 // NOTE(turnidge): If you update this function, you probably want to |
6950 // update Class::PatchFieldsAndFunctions() at the same time. | 6959 // update Class::PatchFieldsAndFunctions() at the same time. |
6951 if (token_pos() == TokenPosition::kMinSource) { | 6960 if (token_pos() == TokenPosition::kMinSource) { |
6952 // Testing for position 0 is an optimization that relies on temporary | 6961 // Testing for position 0 is an optimization that relies on temporary |
6953 // eval functions having token position 0. | 6962 // eval functions having token position 0. |
6954 const Script& script = Script::Handle(eval_script()); | 6963 const Script& script = Script::Handle(eval_script()); |
6955 if (!script.IsNull()) { | 6964 if (!script.IsNull()) { |
6956 return script.raw(); | 6965 return script.raw(); |
6957 } | 6966 } |
6958 } | 6967 } |
6959 if (IsClosureFunction()) { | 6968 if (IsClosureFunction()) { |
6960 return Function::Handle(parent_function()).script(); | 6969 return Function::Handle(parent_function()).script(); |
6961 } | 6970 } |
6962 const Object& obj = Object::Handle(raw_ptr()->owner_); | 6971 const Object& obj = Object::Handle(raw_ptr()->owner_); |
| 6972 if (obj.IsNull()) { |
| 6973 ASSERT(IsSignatureFunction()); |
| 6974 return Script::null(); |
| 6975 } |
6963 if (obj.IsClass()) { | 6976 if (obj.IsClass()) { |
6964 return Class::Cast(obj).script(); | 6977 return Class::Cast(obj).script(); |
6965 } | 6978 } |
6966 ASSERT(obj.IsPatchClass()); | 6979 ASSERT(obj.IsPatchClass()); |
6967 return PatchClass::Cast(obj).script(); | 6980 return PatchClass::Cast(obj).script(); |
6968 } | 6981 } |
6969 | 6982 |
6970 | 6983 |
6971 bool Function::HasOptimizedCode() const { | 6984 bool Function::HasOptimizedCode() const { |
6972 return HasCode() && Code::Handle(CurrentCode()).is_optimized(); | 6985 return HasCode() && Code::Handle(CurrentCode()).is_optimized(); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7265 } | 7278 } |
7266 | 7279 |
7267 | 7280 |
7268 void SignatureData::set_parent_function(const Function& value) const { | 7281 void SignatureData::set_parent_function(const Function& value) const { |
7269 StorePointer(&raw_ptr()->parent_function_, value.raw()); | 7282 StorePointer(&raw_ptr()->parent_function_, value.raw()); |
7270 } | 7283 } |
7271 | 7284 |
7272 | 7285 |
7273 void SignatureData::set_signature_type(const Type& value) const { | 7286 void SignatureData::set_signature_type(const Type& value) const { |
7274 StorePointer(&raw_ptr()->signature_type_, value.raw()); | 7287 StorePointer(&raw_ptr()->signature_type_, value.raw()); |
7275 // If the signature type is resolved, the parent function is not needed | |
7276 // anymore (type parameters may be declared by generic parent functions). | |
7277 // Keeping the parent function can unnecessarily pull more objects into a | |
7278 // snapshot. Also, the parent function is meaningless once the signature type | |
7279 // is canonicalized. | |
7280 | |
7281 // TODO(rmacnak): Keeping the parent function for unresolved signature types | |
7282 // is causing a tree shaking issue in AOT. Please, investigate. | |
7283 #if 0 | |
7284 if (value.IsResolved()) { | |
7285 set_parent_function(Function::Handle()); | |
7286 } | |
7287 #else | |
7288 set_parent_function(Function::Handle()); | |
7289 #endif | |
7290 } | 7288 } |
7291 | 7289 |
7292 | 7290 |
7293 RawSignatureData* SignatureData::New() { | 7291 RawSignatureData* SignatureData::New() { |
7294 ASSERT(Object::signature_data_class() != Class::null()); | 7292 ASSERT(Object::signature_data_class() != Class::null()); |
7295 RawObject* raw = Object::Allocate(SignatureData::kClassId, | 7293 RawObject* raw = Object::Allocate(SignatureData::kClassId, |
7296 SignatureData::InstanceSize(), Heap::kOld); | 7294 SignatureData::InstanceSize(), Heap::kOld); |
7297 return reinterpret_cast<RawSignatureData*>(raw); | 7295 return reinterpret_cast<RawSignatureData*>(raw); |
7298 } | 7296 } |
7299 | 7297 |
(...skipping 9795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17095 if (IsMalbounded()) { | 17093 if (IsMalbounded()) { |
17096 const LanguageError& bound_error = LanguageError::Handle(zone, error()); | 17094 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
17097 clone.set_error(bound_error); | 17095 clone.set_error(bound_error); |
17098 } | 17096 } |
17099 // Clone the signature if this type represents a function type. | 17097 // Clone the signature if this type represents a function type. |
17100 Function& fun = Function::Handle(zone, signature()); | 17098 Function& fun = Function::Handle(zone, signature()); |
17101 if (!fun.IsNull()) { | 17099 if (!fun.IsNull()) { |
17102 const Class& owner = Class::Handle(zone, fun.Owner()); | 17100 const Class& owner = Class::Handle(zone, fun.Owner()); |
17103 Function& fun_clone = Function::Handle( | 17101 Function& fun_clone = Function::Handle( |
17104 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); | 17102 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); |
| 17103 // TODO(regis): Handle cloning of a generic function type. |
17105 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); | 17104 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); |
17106 type = type.CloneUnfinalized(); | 17105 type = type.CloneUnfinalized(); |
17107 fun_clone.set_result_type(type); | 17106 fun_clone.set_result_type(type); |
17108 const intptr_t num_params = fun.NumParameters(); | 17107 const intptr_t num_params = fun.NumParameters(); |
17109 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); | 17108 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); |
17110 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), | 17109 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), |
17111 fun.HasOptionalPositionalParameters()); | 17110 fun.HasOptionalPositionalParameters()); |
17112 fun_clone.set_parameter_types( | 17111 fun_clone.set_parameter_types( |
17113 Array::Handle(Array::New(num_params, Heap::kOld))); | 17112 Array::Handle(Array::New(num_params, Heap::kOld))); |
17114 for (intptr_t i = 0; i < num_params; i++) { | 17113 for (intptr_t i = 0; i < num_params; i++) { |
17115 type = fun.ParameterTypeAt(i); | 17114 type = fun.ParameterTypeAt(i); |
17116 type = type.CloneUnfinalized(); | 17115 type = type.CloneUnfinalized(); |
17117 fun_clone.SetParameterTypeAt(i, type); | 17116 fun_clone.SetParameterTypeAt(i, type); |
17118 } | 17117 } |
17119 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); | 17118 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
17120 clone.set_signature(fun_clone); | 17119 clone.set_signature(fun_clone); |
| 17120 fun_clone.SetSignatureType(clone); |
17121 } | 17121 } |
17122 clone.SetIsResolved(); | 17122 clone.SetIsResolved(); |
17123 return clone.raw(); | 17123 return clone.raw(); |
17124 } | 17124 } |
17125 | 17125 |
17126 | 17126 |
17127 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, | 17127 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, |
17128 TrailPtr trail) const { | 17128 TrailPtr trail) const { |
17129 ASSERT(IsFinalized()); | 17129 ASSERT(IsFinalized()); |
17130 ASSERT(IsCanonical()); | 17130 ASSERT(IsCanonical()); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17307 fun.HasOptionalPositionalParameters()); | 17307 fun.HasOptionalPositionalParameters()); |
17308 sig_fun.set_parameter_types( | 17308 sig_fun.set_parameter_types( |
17309 Array::Handle(Array::New(num_params, Heap::kOld))); | 17309 Array::Handle(Array::New(num_params, Heap::kOld))); |
17310 for (intptr_t i = 0; i < num_params; i++) { | 17310 for (intptr_t i = 0; i < num_params; i++) { |
17311 type = fun.ParameterTypeAt(i); | 17311 type = fun.ParameterTypeAt(i); |
17312 type = type.Canonicalize(trail); | 17312 type = type.Canonicalize(trail); |
17313 sig_fun.SetParameterTypeAt(i, type); | 17313 sig_fun.SetParameterTypeAt(i, type); |
17314 } | 17314 } |
17315 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); | 17315 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
17316 set_signature(sig_fun); | 17316 set_signature(sig_fun); |
| 17317 // Note that the signature type of the signature function may be |
| 17318 // different than the type being canonicalized. |
| 17319 // Consider F<int> being canonicalized, with F being a typedef and F<T> |
| 17320 // being its signature type. |
17317 } | 17321 } |
17318 } | 17322 } |
17319 | 17323 |
17320 // Check to see if the type got added to canonical list as part of the | 17324 // Check to see if the type got added to canonical list as part of the |
17321 // type arguments canonicalization. | 17325 // type arguments canonicalization. |
17322 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); | 17326 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); |
17323 CanonicalTypeSet table(zone, object_store->canonical_types()); | 17327 CanonicalTypeSet table(zone, object_store->canonical_types()); |
17324 type ^= table.GetOrNull(CanonicalTypeKey(*this)); | 17328 type ^= table.GetOrNull(CanonicalTypeKey(*this)); |
17325 if (type.IsNull()) { | 17329 if (type.IsNull()) { |
17326 // Add this Type into the canonical list of types. | 17330 // Add this Type into the canonical list of types. |
(...skipping 5557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22884 return UserTag::null(); | 22888 return UserTag::null(); |
22885 } | 22889 } |
22886 | 22890 |
22887 | 22891 |
22888 const char* UserTag::ToCString() const { | 22892 const char* UserTag::ToCString() const { |
22889 const String& tag_label = String::Handle(label()); | 22893 const String& tag_label = String::Handle(label()); |
22890 return tag_label.ToCString(); | 22894 return tag_label.ToCString(); |
22891 } | 22895 } |
22892 | 22896 |
22893 } // namespace dart | 22897 } // namespace dart |
OLD | NEW |