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

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

Issue 2606993002: Second try: Fix resolution and canonicalization of typedefs and function types (Closed)
Patch Set: Created 3 years, 11 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 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
6941 type = ParameterTypeAt(i); 6942 type = ParameterTypeAt(i);
6942 if (!type.IsInstantiated()) { 6943 if (!type.IsInstantiated()) {
6943 return false; 6944 return false;
6944 } 6945 }
6945 } 6946 }
6946 return true; 6947 return true;
6947 } 6948 }
6948 6949
6949 6950
6950 RawClass* Function::Owner() const { 6951 RawClass* Function::Owner() const {
6952 if (raw_ptr()->owner_ == Object::null()) {
6953 ASSERT(IsSignatureFunction());
6954 return Class::null();
6955 }
6951 if (raw_ptr()->owner_->IsClass()) { 6956 if (raw_ptr()->owner_->IsClass()) {
6952 return Class::RawCast(raw_ptr()->owner_); 6957 return Class::RawCast(raw_ptr()->owner_);
6953 } 6958 }
6954 const Object& obj = Object::Handle(raw_ptr()->owner_); 6959 const Object& obj = Object::Handle(raw_ptr()->owner_);
6955 ASSERT(obj.IsPatchClass()); 6960 ASSERT(obj.IsPatchClass());
6956 return PatchClass::Cast(obj).patched_class(); 6961 return PatchClass::Cast(obj).patched_class();
6957 } 6962 }
6958 6963
6959 6964
6960 RawClass* Function::origin() const { 6965 RawClass* Function::origin() const {
6966 if (raw_ptr()->owner_ == Object::null()) {
6967 ASSERT(IsSignatureFunction());
6968 return Class::null();
6969 }
6961 if (raw_ptr()->owner_->IsClass()) { 6970 if (raw_ptr()->owner_->IsClass()) {
6962 return Class::RawCast(raw_ptr()->owner_); 6971 return Class::RawCast(raw_ptr()->owner_);
6963 } 6972 }
6964 const Object& obj = Object::Handle(raw_ptr()->owner_); 6973 const Object& obj = Object::Handle(raw_ptr()->owner_);
6965 ASSERT(obj.IsPatchClass()); 6974 ASSERT(obj.IsPatchClass());
6966 return PatchClass::Cast(obj).origin_class(); 6975 return PatchClass::Cast(obj).origin_class();
6967 } 6976 }
6968 6977
6969 6978
6970 RawScript* Function::script() const { 6979 RawScript* Function::script() const {
6971 // NOTE(turnidge): If you update this function, you probably want to 6980 // NOTE(turnidge): If you update this function, you probably want to
6972 // update Class::PatchFieldsAndFunctions() at the same time. 6981 // update Class::PatchFieldsAndFunctions() at the same time.
6973 if (token_pos() == TokenPosition::kMinSource) { 6982 if (token_pos() == TokenPosition::kMinSource) {
6974 // Testing for position 0 is an optimization that relies on temporary 6983 // Testing for position 0 is an optimization that relies on temporary
6975 // eval functions having token position 0. 6984 // eval functions having token position 0.
6976 const Script& script = Script::Handle(eval_script()); 6985 const Script& script = Script::Handle(eval_script());
6977 if (!script.IsNull()) { 6986 if (!script.IsNull()) {
6978 return script.raw(); 6987 return script.raw();
6979 } 6988 }
6980 } 6989 }
6981 if (IsClosureFunction()) { 6990 if (IsClosureFunction()) {
6982 return Function::Handle(parent_function()).script(); 6991 return Function::Handle(parent_function()).script();
6983 } 6992 }
6984 const Object& obj = Object::Handle(raw_ptr()->owner_); 6993 const Object& obj = Object::Handle(raw_ptr()->owner_);
6994 if (obj.IsNull()) {
6995 ASSERT(IsSignatureFunction());
6996 return Script::null();
6997 }
6985 if (obj.IsClass()) { 6998 if (obj.IsClass()) {
6986 return Class::Cast(obj).script(); 6999 return Class::Cast(obj).script();
6987 } 7000 }
6988 ASSERT(obj.IsPatchClass()); 7001 ASSERT(obj.IsPatchClass());
6989 return PatchClass::Cast(obj).script(); 7002 return PatchClass::Cast(obj).script();
6990 } 7003 }
6991 7004
6992 7005
6993 bool Function::HasOptimizedCode() const { 7006 bool Function::HasOptimizedCode() const {
6994 return HasCode() && Code::Handle(CurrentCode()).is_optimized(); 7007 return HasCode() && Code::Handle(CurrentCode()).is_optimized();
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
7292 } 7305 }
7293 7306
7294 7307
7295 void SignatureData::set_parent_function(const Function& value) const { 7308 void SignatureData::set_parent_function(const Function& value) const {
7296 StorePointer(&raw_ptr()->parent_function_, value.raw()); 7309 StorePointer(&raw_ptr()->parent_function_, value.raw());
7297 } 7310 }
7298 7311
7299 7312
7300 void SignatureData::set_signature_type(const Type& value) const { 7313 void SignatureData::set_signature_type(const Type& value) const {
7301 StorePointer(&raw_ptr()->signature_type_, value.raw()); 7314 StorePointer(&raw_ptr()->signature_type_, value.raw());
7302 // If the signature type is resolved, the parent function is not needed
7303 // anymore (type parameters may be declared by generic parent functions).
7304 // Keeping the parent function can unnecessarily pull more objects into a
7305 // snapshot. Also, the parent function is meaningless once the signature type
7306 // is canonicalized.
7307
7308 // TODO(rmacnak): Keeping the parent function for unresolved signature types
7309 // is causing a tree shaking issue in AOT. Please, investigate.
7310 #if 0
7311 if (value.IsResolved()) {
7312 set_parent_function(Function::Handle());
7313 }
7314 #else
7315 set_parent_function(Function::Handle());
7316 #endif
7317 } 7315 }
7318 7316
7319 7317
7320 RawSignatureData* SignatureData::New() { 7318 RawSignatureData* SignatureData::New() {
7321 ASSERT(Object::signature_data_class() != Class::null()); 7319 ASSERT(Object::signature_data_class() != Class::null());
7322 RawObject* raw = Object::Allocate(SignatureData::kClassId, 7320 RawObject* raw = Object::Allocate(SignatureData::kClassId,
7323 SignatureData::InstanceSize(), Heap::kOld); 7321 SignatureData::InstanceSize(), Heap::kOld);
7324 return reinterpret_cast<RawSignatureData*>(raw); 7322 return reinterpret_cast<RawSignatureData*>(raw);
7325 } 7323 }
7326 7324
(...skipping 9795 matching lines...) Expand 10 before | Expand all | Expand 10 after
17122 if (IsMalbounded()) { 17120 if (IsMalbounded()) {
17123 const LanguageError& bound_error = LanguageError::Handle(zone, error()); 17121 const LanguageError& bound_error = LanguageError::Handle(zone, error());
17124 clone.set_error(bound_error); 17122 clone.set_error(bound_error);
17125 } 17123 }
17126 // Clone the signature if this type represents a function type. 17124 // Clone the signature if this type represents a function type.
17127 Function& fun = Function::Handle(zone, signature()); 17125 Function& fun = Function::Handle(zone, signature());
17128 if (!fun.IsNull()) { 17126 if (!fun.IsNull()) {
17129 const Class& owner = Class::Handle(zone, fun.Owner()); 17127 const Class& owner = Class::Handle(zone, fun.Owner());
17130 Function& fun_clone = Function::Handle( 17128 Function& fun_clone = Function::Handle(
17131 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); 17129 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource));
17130 // TODO(regis): Handle cloning of a generic function type.
17132 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); 17131 AbstractType& type = AbstractType::Handle(zone, fun.result_type());
17133 type = type.CloneUnfinalized(); 17132 type = type.CloneUnfinalized();
17134 fun_clone.set_result_type(type); 17133 fun_clone.set_result_type(type);
17135 const intptr_t num_params = fun.NumParameters(); 17134 const intptr_t num_params = fun.NumParameters();
17136 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); 17135 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters());
17137 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), 17136 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(),
17138 fun.HasOptionalPositionalParameters()); 17137 fun.HasOptionalPositionalParameters());
17139 fun_clone.set_parameter_types( 17138 fun_clone.set_parameter_types(
17140 Array::Handle(Array::New(num_params, Heap::kOld))); 17139 Array::Handle(Array::New(num_params, Heap::kOld)));
17141 for (intptr_t i = 0; i < num_params; i++) { 17140 for (intptr_t i = 0; i < num_params; i++) {
17142 type = fun.ParameterTypeAt(i); 17141 type = fun.ParameterTypeAt(i);
17143 type = type.CloneUnfinalized(); 17142 type = type.CloneUnfinalized();
17144 fun_clone.SetParameterTypeAt(i, type); 17143 fun_clone.SetParameterTypeAt(i, type);
17145 } 17144 }
17146 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); 17145 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
17147 clone.set_signature(fun_clone); 17146 clone.set_signature(fun_clone);
17147 fun_clone.SetSignatureType(clone);
17148 } 17148 }
17149 clone.SetIsResolved(); 17149 clone.SetIsResolved();
17150 return clone.raw(); 17150 return clone.raw();
17151 } 17151 }
17152 17152
17153 17153
17154 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, 17154 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner,
17155 TrailPtr trail) const { 17155 TrailPtr trail) const {
17156 ASSERT(IsFinalized()); 17156 ASSERT(IsFinalized());
17157 ASSERT(IsCanonical()); 17157 ASSERT(IsCanonical());
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
17334 fun.HasOptionalPositionalParameters()); 17334 fun.HasOptionalPositionalParameters());
17335 sig_fun.set_parameter_types( 17335 sig_fun.set_parameter_types(
17336 Array::Handle(Array::New(num_params, Heap::kOld))); 17336 Array::Handle(Array::New(num_params, Heap::kOld)));
17337 for (intptr_t i = 0; i < num_params; i++) { 17337 for (intptr_t i = 0; i < num_params; i++) {
17338 type = fun.ParameterTypeAt(i); 17338 type = fun.ParameterTypeAt(i);
17339 type = type.Canonicalize(trail); 17339 type = type.Canonicalize(trail);
17340 sig_fun.SetParameterTypeAt(i, type); 17340 sig_fun.SetParameterTypeAt(i, type);
17341 } 17341 }
17342 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); 17342 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
17343 set_signature(sig_fun); 17343 set_signature(sig_fun);
17344 // Note that the signature type of the signature function may be
17345 // different than the type being canonicalized.
17346 // Consider F<int> being canonicalized, with F being a typedef and F<T>
17347 // being its signature type.
17344 } 17348 }
17345 } 17349 }
17346 17350
17347 // Check to see if the type got added to canonical list as part of the 17351 // Check to see if the type got added to canonical list as part of the
17348 // type arguments canonicalization. 17352 // type arguments canonicalization.
17349 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); 17353 SafepointMutexLocker ml(isolate->type_canonicalization_mutex());
17350 CanonicalTypeSet table(zone, object_store->canonical_types()); 17354 CanonicalTypeSet table(zone, object_store->canonical_types());
17351 type ^= table.GetOrNull(CanonicalTypeKey(*this)); 17355 type ^= table.GetOrNull(CanonicalTypeKey(*this));
17352 if (type.IsNull()) { 17356 if (type.IsNull()) {
17353 // Add this Type into the canonical list of types. 17357 // Add this Type into the canonical list of types.
(...skipping 5557 matching lines...) Expand 10 before | Expand all | Expand 10 after
22911 return UserTag::null(); 22915 return UserTag::null();
22912 } 22916 }
22913 22917
22914 22918
22915 const char* UserTag::ToCString() const { 22919 const char* UserTag::ToCString() const {
22916 const String& tag_label = String::Handle(label()); 22920 const String& tag_label = String::Handle(label());
22917 return tag_label.ToCString(); 22921 return tag_label.ToCString();
22918 } 22922 }
22919 22923
22920 } // namespace dart 22924 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698