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

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

Issue 2592263004: Fix resolution and canonicalization of typedefs and function types in (Closed)
Patch Set: work in progress Created 3 years, 12 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 5545 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
7265 } 7274 }
7266 7275
7267 7276
7268 void SignatureData::set_parent_function(const Function& value) const { 7277 void SignatureData::set_parent_function(const Function& value) const {
7269 StorePointer(&raw_ptr()->parent_function_, value.raw()); 7278 StorePointer(&raw_ptr()->parent_function_, value.raw());
7270 } 7279 }
7271 7280
7272 7281
7273 void SignatureData::set_signature_type(const Type& value) const { 7282 void SignatureData::set_signature_type(const Type& value) const {
7274 StorePointer(&raw_ptr()->signature_type_, value.raw()); 7283 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 } 7284 }
7291 7285
7292 7286
7293 RawSignatureData* SignatureData::New() { 7287 RawSignatureData* SignatureData::New() {
7294 ASSERT(Object::signature_data_class() != Class::null()); 7288 ASSERT(Object::signature_data_class() != Class::null());
7295 RawObject* raw = Object::Allocate(SignatureData::kClassId, 7289 RawObject* raw = Object::Allocate(SignatureData::kClassId,
7296 SignatureData::InstanceSize(), Heap::kOld); 7290 SignatureData::InstanceSize(), Heap::kOld);
7297 return reinterpret_cast<RawSignatureData*>(raw); 7291 return reinterpret_cast<RawSignatureData*>(raw);
7298 } 7292 }
7299 7293
(...skipping 9795 matching lines...) Expand 10 before | Expand all | Expand 10 after
17095 if (IsMalbounded()) { 17089 if (IsMalbounded()) {
17096 const LanguageError& bound_error = LanguageError::Handle(zone, error()); 17090 const LanguageError& bound_error = LanguageError::Handle(zone, error());
17097 clone.set_error(bound_error); 17091 clone.set_error(bound_error);
17098 } 17092 }
17099 // Clone the signature if this type represents a function type. 17093 // Clone the signature if this type represents a function type.
17100 Function& fun = Function::Handle(zone, signature()); 17094 Function& fun = Function::Handle(zone, signature());
17101 if (!fun.IsNull()) { 17095 if (!fun.IsNull()) {
17102 const Class& owner = Class::Handle(zone, fun.Owner()); 17096 const Class& owner = Class::Handle(zone, fun.Owner());
17103 Function& fun_clone = Function::Handle( 17097 Function& fun_clone = Function::Handle(
17104 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); 17098 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource));
17099 // TODO(regis): Handle cloning of a generic function type.
17105 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); 17100 AbstractType& type = AbstractType::Handle(zone, fun.result_type());
17106 type = type.CloneUnfinalized(); 17101 type = type.CloneUnfinalized();
17107 fun_clone.set_result_type(type); 17102 fun_clone.set_result_type(type);
17108 const intptr_t num_params = fun.NumParameters(); 17103 const intptr_t num_params = fun.NumParameters();
17109 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); 17104 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters());
17110 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), 17105 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(),
17111 fun.HasOptionalPositionalParameters()); 17106 fun.HasOptionalPositionalParameters());
17112 fun_clone.set_parameter_types( 17107 fun_clone.set_parameter_types(
17113 Array::Handle(Array::New(num_params, Heap::kOld))); 17108 Array::Handle(Array::New(num_params, Heap::kOld)));
17114 for (intptr_t i = 0; i < num_params; i++) { 17109 for (intptr_t i = 0; i < num_params; i++) {
17115 type = fun.ParameterTypeAt(i); 17110 type = fun.ParameterTypeAt(i);
17116 type = type.CloneUnfinalized(); 17111 type = type.CloneUnfinalized();
17117 fun_clone.SetParameterTypeAt(i, type); 17112 fun_clone.SetParameterTypeAt(i, type);
17118 } 17113 }
17119 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); 17114 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
17120 clone.set_signature(fun_clone); 17115 clone.set_signature(fun_clone);
17116 fun_clone.SetSignatureType(clone);
17121 } 17117 }
17122 clone.SetIsResolved(); 17118 clone.SetIsResolved();
17123 return clone.raw(); 17119 return clone.raw();
17124 } 17120 }
17125 17121
17126 17122
17127 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, 17123 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner,
17128 TrailPtr trail) const { 17124 TrailPtr trail) const {
17129 ASSERT(IsFinalized()); 17125 ASSERT(IsFinalized());
17130 ASSERT(IsCanonical()); 17126 ASSERT(IsCanonical());
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
17307 fun.HasOptionalPositionalParameters()); 17303 fun.HasOptionalPositionalParameters());
17308 sig_fun.set_parameter_types( 17304 sig_fun.set_parameter_types(
17309 Array::Handle(Array::New(num_params, Heap::kOld))); 17305 Array::Handle(Array::New(num_params, Heap::kOld)));
17310 for (intptr_t i = 0; i < num_params; i++) { 17306 for (intptr_t i = 0; i < num_params; i++) {
17311 type = fun.ParameterTypeAt(i); 17307 type = fun.ParameterTypeAt(i);
17312 type = type.Canonicalize(trail); 17308 type = type.Canonicalize(trail);
17313 sig_fun.SetParameterTypeAt(i, type); 17309 sig_fun.SetParameterTypeAt(i, type);
17314 } 17310 }
17315 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); 17311 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
17316 set_signature(sig_fun); 17312 set_signature(sig_fun);
17313 // Note that the signature type of the signature function may be
17314 // different than the type being canonicalized.
17315 // Consider F<int> being canonicalized, with F being a typedef and F<T>
17316 // being its signature type.
17317 } 17317 }
17318 } 17318 }
17319 17319
17320 // Check to see if the type got added to canonical list as part of the 17320 // Check to see if the type got added to canonical list as part of the
17321 // type arguments canonicalization. 17321 // type arguments canonicalization.
17322 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); 17322 SafepointMutexLocker ml(isolate->type_canonicalization_mutex());
17323 CanonicalTypeSet table(zone, object_store->canonical_types()); 17323 CanonicalTypeSet table(zone, object_store->canonical_types());
17324 type ^= table.GetOrNull(CanonicalTypeKey(*this)); 17324 type ^= table.GetOrNull(CanonicalTypeKey(*this));
17325 if (type.IsNull()) { 17325 if (type.IsNull()) {
17326 // Add this Type into the canonical list of types. 17326 // Add this Type into the canonical list of types.
(...skipping 5557 matching lines...) Expand 10 before | Expand all | Expand 10 after
22884 return UserTag::null(); 22884 return UserTag::null();
22885 } 22885 }
22886 22886
22887 22887
22888 const char* UserTag::ToCString() const { 22888 const char* UserTag::ToCString() const {
22889 const String& tag_label = String::Handle(label()); 22889 const String& tag_label = String::Handle(label());
22890 return tag_label.ToCString(); 22890 return tag_label.ToCString();
22891 } 22891 }
22892 22892
22893 } // namespace dart 22893 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698