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

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

Issue 2761933002: Add Genericity enum in VM to distinguish how a type is uninstantiated. (Closed)
Patch Set: sync Created 3 years, 9 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4782 matching lines...) Expand 10 before | Expand all | Expand 10 after
4793 if (!type.IsResolved()) { 4793 if (!type.IsResolved()) {
4794 return false; 4794 return false;
4795 } 4795 }
4796 } 4796 }
4797 return true; 4797 return true;
4798 } 4798 }
4799 4799
4800 4800
4801 bool TypeArguments::IsSubvectorInstantiated(intptr_t from_index, 4801 bool TypeArguments::IsSubvectorInstantiated(intptr_t from_index,
4802 intptr_t len, 4802 intptr_t len,
4803 Genericity genericity,
4803 TrailPtr trail) const { 4804 TrailPtr trail) const {
4804 ASSERT(!IsNull()); 4805 ASSERT(!IsNull());
4805 AbstractType& type = AbstractType::Handle(); 4806 AbstractType& type = AbstractType::Handle();
4806 for (intptr_t i = 0; i < len; i++) { 4807 for (intptr_t i = 0; i < len; i++) {
4807 type = TypeAt(from_index + i); 4808 type = TypeAt(from_index + i);
4808 // If the type argument is null, the type parameterized with this type 4809 // If the type argument is null, the type parameterized with this type
4809 // argument is still being finalized. Skip this null type argument. 4810 // argument is still being finalized. Skip this null type argument.
4810 if (!type.IsNull() && !type.IsInstantiated(trail)) { 4811 if (!type.IsNull() && !type.IsInstantiated(genericity, trail)) {
4811 return false; 4812 return false;
4812 } 4813 }
4813 } 4814 }
4814 return true; 4815 return true;
4815 } 4816 }
4816 4817
4817 4818
4818 bool TypeArguments::IsUninstantiatedIdentity() const { 4819 bool TypeArguments::IsUninstantiatedIdentity() const {
4819 ASSERT(!IsInstantiated()); 4820 ASSERT(!IsInstantiated());
4820 AbstractType& type = AbstractType::Handle(); 4821 AbstractType& type = AbstractType::Handle();
4821 const intptr_t num_types = Length(); 4822 const intptr_t num_types = Length();
4822 for (intptr_t i = 0; i < num_types; i++) { 4823 for (intptr_t i = 0; i < num_types; i++) {
4823 type = TypeAt(i); 4824 type = TypeAt(i);
4824 if (!type.IsTypeParameter()) { 4825 if (!type.IsTypeParameter()) {
4825 return false; 4826 return false;
4826 } 4827 }
4827 const TypeParameter& type_param = TypeParameter::Cast(type); 4828 const TypeParameter& type_param = TypeParameter::Cast(type);
4828 ASSERT(type_param.IsFinalized()); 4829 ASSERT(type_param.IsFinalized());
4829 if ((type_param.index() != i)) { 4830 if ((type_param.index() != i) || type_param.IsFunctionTypeParameter()) {
4830 return false; 4831 return false;
4831 } 4832 }
4832 // If this type parameter specifies an upper bound, then the type argument 4833 // If this type parameter specifies an upper bound, then the type argument
4833 // vector does not really represent the identity vector. It cannot be 4834 // vector does not really represent the identity vector. It cannot be
4834 // substituted by the instantiator's type argument vector without checking 4835 // substituted by the instantiator's type argument vector without checking
4835 // the upper bound. 4836 // the upper bound.
4836 const AbstractType& bound = AbstractType::Handle(type_param.bound()); 4837 const AbstractType& bound = AbstractType::Handle(type_param.bound());
4837 ASSERT(bound.IsResolved()); 4838 ASSERT(bound.IsResolved());
4838 if (!bound.IsObjectType() && !bound.IsDynamicType()) { 4839 if (!bound.IsObjectType() && !bound.IsDynamicType()) {
4839 return false; 4840 return false;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4878 // arguments of this type argument vector must refer to the corresponding type 4879 // arguments of this type argument vector must refer to the corresponding type
4879 // parameters of the instantiator class. 4880 // parameters of the instantiator class.
4880 AbstractType& type_arg = AbstractType::Handle(); 4881 AbstractType& type_arg = AbstractType::Handle();
4881 for (intptr_t i = first_type_param_offset; i < num_type_args; i++) { 4882 for (intptr_t i = first_type_param_offset; i < num_type_args; i++) {
4882 type_arg = TypeAt(i); 4883 type_arg = TypeAt(i);
4883 if (!type_arg.IsTypeParameter()) { 4884 if (!type_arg.IsTypeParameter()) {
4884 return false; 4885 return false;
4885 } 4886 }
4886 const TypeParameter& type_param = TypeParameter::Cast(type_arg); 4887 const TypeParameter& type_param = TypeParameter::Cast(type_arg);
4887 ASSERT(type_param.IsFinalized()); 4888 ASSERT(type_param.IsFinalized());
4888 if ((type_param.index() != i)) { 4889 if ((type_param.index() != i) || type_param.IsFunctionTypeParameter()) {
4889 return false; 4890 return false;
4890 } 4891 }
4891 } 4892 }
4892 // As a second requirement, the type arguments corresponding to the super type 4893 // As a second requirement, the type arguments corresponding to the super type
4893 // must be identical. Overlapping ones have already been checked starting at 4894 // must be identical. Overlapping ones have already been checked starting at
4894 // first_type_param_offset. 4895 // first_type_param_offset.
4895 if (first_type_param_offset == 0) { 4896 if (first_type_param_offset == 0) {
4896 return true; 4897 return true;
4897 } 4898 }
4898 AbstractType& super_type = 4899 AbstractType& super_type =
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
5543 ASSERT(!obj.IsNull()); 5544 ASSERT(!obj.IsNull());
5544 if (IsClosureFunction()) { 5545 if (IsClosureFunction()) {
5545 ClosureData::Cast(obj).set_parent_function(value); 5546 ClosureData::Cast(obj).set_parent_function(value);
5546 } else { 5547 } else {
5547 ASSERT(IsSignatureFunction()); 5548 ASSERT(IsSignatureFunction());
5548 SignatureData::Cast(obj).set_parent_function(value); 5549 SignatureData::Cast(obj).set_parent_function(value);
5549 } 5550 }
5550 } 5551 }
5551 5552
5552 5553
5554 bool Function::HasGenericParent() const {
5555 Function& parent = Function::Handle(parent_function());
5556 while (!parent.IsNull()) {
5557 if (parent.IsGeneric()) {
5558 return true;
5559 }
5560 parent = parent.parent_function();
5561 }
5562 return false;
5563 }
5564
5565
5553 RawFunction* Function::implicit_closure_function() const { 5566 RawFunction* Function::implicit_closure_function() const {
5554 if (IsClosureFunction() || IsSignatureFunction() || IsFactory()) { 5567 if (IsClosureFunction() || IsSignatureFunction() || IsFactory()) {
5555 return Function::null(); 5568 return Function::null();
5556 } 5569 }
5557 const Object& obj = Object::Handle(raw_ptr()->data_); 5570 const Object& obj = Object::Handle(raw_ptr()->data_);
5558 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction() || obj.IsArray()); 5571 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction() || obj.IsArray());
5559 if (obj.IsNull() || obj.IsScript()) { 5572 if (obj.IsNull() || obj.IsScript()) {
5560 return Function::null(); 5573 return Function::null();
5561 } 5574 }
5562 if (obj.IsFunction()) { 5575 if (obj.IsFunction()) {
(...skipping 10479 matching lines...) Expand 10 before | Expand all | Expand 10 after
16042 UNREACHABLE(); 16055 UNREACHABLE();
16043 } 16056 }
16044 16057
16045 TokenPosition AbstractType::token_pos() const { 16058 TokenPosition AbstractType::token_pos() const {
16046 // AbstractType is an abstract class. 16059 // AbstractType is an abstract class.
16047 UNREACHABLE(); 16060 UNREACHABLE();
16048 return TokenPosition::kNoSource; 16061 return TokenPosition::kNoSource;
16049 } 16062 }
16050 16063
16051 16064
16052 bool AbstractType::IsInstantiated(TrailPtr trail) const { 16065 bool AbstractType::IsInstantiated(Genericity genericity, TrailPtr trail) const {
16053 // AbstractType is an abstract class. 16066 // AbstractType is an abstract class.
16054 UNREACHABLE(); 16067 UNREACHABLE();
16055 return false; 16068 return false;
16056 } 16069 }
16057 16070
16058 16071
16059 bool AbstractType::IsFinalized() const { 16072 bool AbstractType::IsFinalized() const {
16060 // AbstractType is an abstract class. 16073 // AbstractType is an abstract class.
16061 UNREACHABLE(); 16074 UNREACHABLE();
16062 return false; 16075 return false;
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
16848 ASSERT(!unresolved_class.IsNull()); 16861 ASSERT(!unresolved_class.IsNull());
16849 return unresolved_class.raw(); 16862 return unresolved_class.raw();
16850 #else 16863 #else
16851 ASSERT(!Object::Handle(raw_ptr()->type_class_id_).IsNull()); 16864 ASSERT(!Object::Handle(raw_ptr()->type_class_id_).IsNull());
16852 ASSERT(Object::Handle(raw_ptr()->type_class_id_).IsUnresolvedClass()); 16865 ASSERT(Object::Handle(raw_ptr()->type_class_id_).IsUnresolvedClass());
16853 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_id_); 16866 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_id_);
16854 #endif 16867 #endif
16855 } 16868 }
16856 16869
16857 16870
16858 bool Type::IsInstantiated(TrailPtr trail) const { 16871 bool Type::IsInstantiated(Genericity genericity, TrailPtr trail) const {
16859 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { 16872 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) {
16860 return true; 16873 return true;
16861 } 16874 }
16862 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) { 16875 if ((genericity == kAny) &&
16876 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated)) {
16863 return false; 16877 return false;
16864 } 16878 }
16865 if (arguments() == TypeArguments::null()) { 16879 if (arguments() == TypeArguments::null()) {
16866 return true; 16880 return true;
16867 } 16881 }
16868 const TypeArguments& args = TypeArguments::Handle(arguments()); 16882 const TypeArguments& args = TypeArguments::Handle(arguments());
16869 intptr_t num_type_args = args.Length(); 16883 intptr_t num_type_args = args.Length();
16870 intptr_t len = num_type_args; // Check the full vector of type args. 16884 intptr_t len = num_type_args; // Check the full vector of type args.
16871 ASSERT(num_type_args > 0); 16885 ASSERT(num_type_args > 0);
16872 // This type is not instantiated if it refers to type parameters. 16886 // This type is not instantiated if it refers to type parameters.
16873 // Although this type may still be unresolved, the type parameters it may 16887 // Although this type may still be unresolved, the type parameters it may
16874 // refer to are resolved by definition. We can therefore return the correct 16888 // refer to are resolved by definition. We can therefore return the correct
16875 // result even for an unresolved type. We just need to look at all type 16889 // result even for an unresolved type. We just need to look at all type
16876 // arguments and not just at the type parameters. 16890 // arguments and not just at the type parameters.
16877 if (HasResolvedTypeClass()) { 16891 if (HasResolvedTypeClass()) {
16878 const Class& cls = Class::Handle(type_class()); 16892 const Class& cls = Class::Handle(type_class());
16879 len = cls.NumTypeParameters(); // Check the type parameters only. 16893 len = cls.NumTypeParameters(); // Check the type parameters only.
16880 } 16894 }
16881 return (len == 0) || 16895 return (len == 0) ||
16882 args.IsSubvectorInstantiated(num_type_args - len, len, trail); 16896 args.IsSubvectorInstantiated(num_type_args - len, len, genericity,
16897 trail);
16883 } 16898 }
16884 16899
16885 16900
16886 RawAbstractType* Type::InstantiateFrom( 16901 RawAbstractType* Type::InstantiateFrom(
16887 const TypeArguments& instantiator_type_arguments, 16902 const TypeArguments& instantiator_type_arguments,
16888 Error* bound_error, 16903 Error* bound_error,
16889 TrailPtr instantiation_trail, 16904 TrailPtr instantiation_trail,
16890 TrailPtr bound_trail, 16905 TrailPtr bound_trail,
16891 Heap::Space space) const { 16906 Heap::Space space) const {
16892 Zone* zone = Thread::Current()->zone(); 16907 Zone* zone = Thread::Current()->zone();
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
17560 const intptr_t hash = Hash(); 17575 const intptr_t hash = Hash();
17561 return OS::SCreate(zone, "Type: (@%p H%" Px ") class '%s', args:[%s]", 17576 return OS::SCreate(zone, "Type: (@%p H%" Px ") class '%s', args:[%s]",
17562 raw(), hash, class_name, args_cstr); 17577 raw(), hash, class_name, args_cstr);
17563 } else { 17578 } else {
17564 return OS::SCreate(zone, "%sType: class '%s', args:[%s]", unresolved, 17579 return OS::SCreate(zone, "%sType: class '%s', args:[%s]", unresolved,
17565 class_name, args_cstr); 17580 class_name, args_cstr);
17566 } 17581 }
17567 } 17582 }
17568 17583
17569 17584
17570 bool TypeRef::IsInstantiated(TrailPtr trail) const { 17585 bool TypeRef::IsInstantiated(Genericity genericity, TrailPtr trail) const {
17571 if (TestAndAddToTrail(&trail)) { 17586 if (TestAndAddToTrail(&trail)) {
17572 return true; 17587 return true;
17573 } 17588 }
17574 return AbstractType::Handle(type()).IsInstantiated(trail); 17589 return AbstractType::Handle(type()).IsInstantiated(genericity, trail);
17575 } 17590 }
17576 17591
17577 17592
17578 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const { 17593 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const {
17579 if (raw() == other.raw()) { 17594 if (raw() == other.raw()) {
17580 return true; 17595 return true;
17581 } 17596 }
17582 if (!other.IsAbstractType()) { 17597 if (!other.IsAbstractType()) {
17583 return false; 17598 return false;
17584 } 17599 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
17725 } 17740 }
17726 } 17741 }
17727 17742
17728 17743
17729 void TypeParameter::SetIsFinalized() const { 17744 void TypeParameter::SetIsFinalized() const {
17730 ASSERT(!IsFinalized()); 17745 ASSERT(!IsFinalized());
17731 set_type_state(RawTypeParameter::kFinalizedUninstantiated); 17746 set_type_state(RawTypeParameter::kFinalizedUninstantiated);
17732 } 17747 }
17733 17748
17734 17749
17750 bool TypeParameter::IsInstantiated(Genericity genericity,
17751 TrailPtr trail) const {
17752 switch (genericity) {
17753 case kAny:
17754 return false;
17755 case kClass:
17756 return IsFunctionTypeParameter();
17757 case kFunctions:
17758 return IsClassTypeParameter();
17759 case kCurrentFunction:
17760 return IsClassTypeParameter() || (parent_level() > 0);
17761 case kParentFunctions:
17762 return IsClassTypeParameter() || (parent_level() == 0);
17763 default:
17764 UNREACHABLE();
17765 }
17766 return false;
17767 }
17768
17769
17735 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const { 17770 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const {
17736 if (raw() == other.raw()) { 17771 if (raw() == other.raw()) {
17737 return true; 17772 return true;
17738 } 17773 }
17739 if (other.IsTypeRef()) { 17774 if (other.IsTypeRef()) {
17740 // Unfold right hand type. Divergence is controlled by left hand type. 17775 // Unfold right hand type. Divergence is controlled by left hand type.
17741 const AbstractType& other_ref_type = 17776 const AbstractType& other_ref_type =
17742 AbstractType::Handle(TypeRef::Cast(other).type()); 17777 AbstractType::Handle(TypeRef::Cast(other).type());
17743 ASSERT(!other_ref_type.IsTypeRef()); 17778 ASSERT(!other_ref_type.IsTypeRef());
17744 return IsEquivalent(other_ref_type, trail); 17779 return IsEquivalent(other_ref_type, trail);
(...skipping 5306 matching lines...) Expand 10 before | Expand all | Expand 10 after
23051 return UserTag::null(); 23086 return UserTag::null();
23052 } 23087 }
23053 23088
23054 23089
23055 const char* UserTag::ToCString() const { 23090 const char* UserTag::ToCString() const {
23056 const String& tag_label = String::Handle(label()); 23091 const String& tag_label = String::Handle(label());
23057 return tag_label.ToCString(); 23092 return tag_label.ToCString();
23058 } 23093 }
23059 23094
23060 } // namespace dart 23095 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698