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

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

Issue 2718513002: Void is not required to be `null` anymore. (Closed)
Patch Set: Fix more places in the VM. 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
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 3769 matching lines...) Expand 10 before | Expand all | Expand 10 after
3780 Heap::Space space) { 3780 Heap::Space space) {
3781 // Use the thsi object as if it was the receiver of this method, but instead 3781 // Use the thsi object as if it was the receiver of this method, but instead
3782 // of recursing reset it to the super class and loop. 3782 // of recursing reset it to the super class and loop.
3783 Zone* zone = Thread::Current()->zone(); 3783 Zone* zone = Thread::Current()->zone();
3784 Class& thsi = Class::Handle(zone, cls.raw()); 3784 Class& thsi = Class::Handle(zone, cls.raw());
3785 while (true) { 3785 while (true) {
3786 ASSERT(!thsi.IsVoidClass()); 3786 ASSERT(!thsi.IsVoidClass());
3787 // Check for DynamicType. 3787 // Check for DynamicType.
3788 // Each occurrence of DynamicType in type T is interpreted as the dynamic 3788 // Each occurrence of DynamicType in type T is interpreted as the dynamic
3789 // type, a supertype of all types. 3789 // type, a supertype of all types.
3790 if (other.IsDynamicClass()) { 3790 if (other.IsDynamicClass()) {
regis 2017/03/22 16:29:32 || other.IsVoidClass() // and update the comment
3791 return true; 3791 return true;
3792 } 3792 }
3793 // Check for NullType, which, as of Dart 1.5, is a subtype of (and is more 3793 // Check for NullType, which, as of Dart 1.5, is a subtype of (and is more
3794 // specific than) any type. Note that the null instance is not handled here. 3794 // specific than) any type. Note that the null instance is not handled here.
3795 if (thsi.IsNullClass()) { 3795 if (thsi.IsNullClass()) {
3796 return true; 3796 return true;
3797 } 3797 }
3798 // In the case of a subtype test, each occurrence of DynamicType in type S 3798 // In the case of a subtype test, each occurrence of DynamicType in type S
3799 // is interpreted as the bottom type, a subtype of all types. 3799 // is interpreted as the bottom type, a subtype of all types.
3800 // However, DynamicType is not more specific than any type. 3800 // However, DynamicType is not more specific than any type.
regis 2017/03/22 16:29:32 If dynamic is not more specific than void, then ig
3801 if (thsi.IsDynamicClass()) { 3801 if (thsi.IsDynamicClass()) {
3802 return test_kind == Class::kIsSubtypeOf; 3802 return test_kind == Class::kIsSubtypeOf;
3803 } 3803 }
3804 // Check for ObjectType. Any type that is not NullType or DynamicType 3804 // Check for ObjectType. Any type that is not NullType or DynamicType
3805 // (already checked above), is more specific than ObjectType. 3805 // (already checked above), is more specific than ObjectType.
3806 if (other.IsObjectClass()) { 3806 if (other.IsObjectClass()) {
regis 2017/03/22 16:29:32 if you did not handle void above, check here.
3807 return true; 3807 return true;
3808 } 3808 }
3809 // Check for reflexivity. 3809 // Check for reflexivity.
3810 if (thsi.raw() == other.raw()) { 3810 if (thsi.raw() == other.raw()) {
3811 const intptr_t num_type_params = thsi.NumTypeParameters(); 3811 const intptr_t num_type_params = thsi.NumTypeParameters();
3812 if (num_type_params == 0) { 3812 if (num_type_params == 0) {
3813 return true; 3813 return true;
3814 } 3814 }
3815 const intptr_t num_type_args = thsi.NumTypeArguments(); 3815 const intptr_t num_type_args = thsi.NumTypeArguments();
3816 const intptr_t from_index = num_type_args - num_type_params; 3816 const intptr_t from_index = num_type_args - num_type_params;
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 ASSERT(type_param.IsFinalized()); 4812 ASSERT(type_param.IsFinalized());
4813 if ((type_param.index() != i)) { 4813 if ((type_param.index() != i)) {
4814 return false; 4814 return false;
4815 } 4815 }
4816 // If this type parameter specifies an upper bound, then the type argument 4816 // If this type parameter specifies an upper bound, then the type argument
4817 // vector does not really represent the identity vector. It cannot be 4817 // vector does not really represent the identity vector. It cannot be
4818 // substituted by the instantiator's type argument vector without checking 4818 // substituted by the instantiator's type argument vector without checking
4819 // the upper bound. 4819 // the upper bound.
4820 const AbstractType& bound = AbstractType::Handle(type_param.bound()); 4820 const AbstractType& bound = AbstractType::Handle(type_param.bound());
4821 ASSERT(bound.IsResolved()); 4821 ASSERT(bound.IsResolved());
4822 if (!bound.IsObjectType() && !bound.IsDynamicType()) { 4822 if (!bound.IsObjectType() && !bound.IsDynamicType()) {
regis 2017/03/22 16:29:32 Is void allowed as an upper bound? If so, && !boun
4823 return false; 4823 return false;
4824 } 4824 }
4825 } 4825 }
4826 return true; 4826 return true;
4827 // Note that it is not necessary to verify at runtime that the instantiator 4827 // Note that it is not necessary to verify at runtime that the instantiator
4828 // type vector is long enough, since this uninstantiated vector contains as 4828 // type vector is long enough, since this uninstantiated vector contains as
4829 // many different type parameters as it is long. 4829 // many different type parameters as it is long.
4830 } 4830 }
4831 4831
4832 4832
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
4917 AbstractType& type = AbstractType::Handle(); 4917 AbstractType& type = AbstractType::Handle();
4918 const intptr_t num_types = Length(); 4918 const intptr_t num_types = Length();
4919 for (intptr_t i = 0; i < num_types; i++) { 4919 for (intptr_t i = 0; i < num_types; i++) {
4920 type = TypeAt(i); 4920 type = TypeAt(i);
4921 if (type.IsBoundedType()) { 4921 if (type.IsBoundedType()) {
4922 return true; 4922 return true;
4923 } 4923 }
4924 if (type.IsTypeParameter()) { 4924 if (type.IsTypeParameter()) {
4925 const AbstractType& bound = 4925 const AbstractType& bound =
4926 AbstractType::Handle(TypeParameter::Cast(type).bound()); 4926 AbstractType::Handle(TypeParameter::Cast(type).bound());
4927 if (!bound.IsObjectType() && !bound.IsDynamicType()) { 4927 if (!bound.IsObjectType() && !bound.IsDynamicType()) {
regis 2017/03/22 16:29:32 ditto
4928 return true; 4928 return true;
4929 } 4929 }
4930 continue; 4930 continue;
4931 } 4931 }
4932 const TypeArguments& type_args = 4932 const TypeArguments& type_args =
4933 TypeArguments::Handle(Type::Cast(type).arguments()); 4933 TypeArguments::Handle(Type::Cast(type).arguments());
4934 if (!type_args.IsNull() && type_args.IsBounded()) { 4934 if (!type_args.IsNull() && type_args.IsBounded()) {
4935 return true; 4935 return true;
4936 } 4936 }
4937 } 4937 }
(...skipping 10697 matching lines...) Expand 10 before | Expand all | Expand 10 after
15635 15635
15636 bool Instance::IsInstanceOf(const AbstractType& other, 15636 bool Instance::IsInstanceOf(const AbstractType& other,
15637 const TypeArguments& other_instantiator, 15637 const TypeArguments& other_instantiator,
15638 Error* bound_error) const { 15638 Error* bound_error) const {
15639 ASSERT(other.IsFinalized()); 15639 ASSERT(other.IsFinalized());
15640 ASSERT(!other.IsDynamicType()); 15640 ASSERT(!other.IsDynamicType());
15641 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time. 15641 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time.
15642 ASSERT(!other.IsMalformed()); 15642 ASSERT(!other.IsMalformed());
15643 ASSERT(!other.IsMalbounded()); 15643 ASSERT(!other.IsMalbounded());
15644 if (other.IsVoidType()) { 15644 if (other.IsVoidType()) {
15645 return false; 15645 return true;
15646 } 15646 }
15647 Zone* zone = Thread::Current()->zone(); 15647 Zone* zone = Thread::Current()->zone();
15648 const Class& cls = Class::Handle(zone, clazz()); 15648 const Class& cls = Class::Handle(zone, clazz());
15649 if (cls.IsClosureClass()) { 15649 if (cls.IsClosureClass()) {
15650 if (other.IsObjectType() || other.IsDartFunctionType() || 15650 if (other.IsObjectType() || other.IsDartFunctionType() ||
15651 other.IsDartClosureType()) { 15651 other.IsDartClosureType()) {
15652 return true; 15652 return true;
15653 } 15653 }
15654 Function& other_signature = Function::Handle(zone); 15654 Function& other_signature = Function::Handle(zone);
15655 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); 15655 TypeArguments& other_type_arguments = TypeArguments::Handle(zone);
15656 // Note that we may encounter a bound error in checked mode. 15656 // Note that we may encounter a bound error in checked mode.
15657 if (!other.IsInstantiated()) { 15657 if (!other.IsInstantiated()) {
15658 AbstractType& instantiated_other = AbstractType::Handle( 15658 AbstractType& instantiated_other = AbstractType::Handle(
15659 zone, other.InstantiateFrom(other_instantiator, bound_error, NULL, 15659 zone, other.InstantiateFrom(other_instantiator, bound_error, NULL,
15660 NULL, Heap::kOld)); 15660 NULL, Heap::kOld));
15661 if ((bound_error != NULL) && !bound_error->IsNull()) { 15661 if ((bound_error != NULL) && !bound_error->IsNull()) {
15662 ASSERT(Isolate::Current()->type_checks()); 15662 ASSERT(Isolate::Current()->type_checks());
15663 return false; 15663 return false;
15664 } 15664 }
15665 if (instantiated_other.IsTypeRef()) { 15665 if (instantiated_other.IsTypeRef()) {
15666 instantiated_other = TypeRef::Cast(instantiated_other).type(); 15666 instantiated_other = TypeRef::Cast(instantiated_other).type();
15667 } 15667 }
15668 if (instantiated_other.IsDynamicType() || 15668 if (instantiated_other.IsDynamicType() ||
15669 instantiated_other.IsObjectType() || 15669 instantiated_other.IsObjectType() ||
15670 instantiated_other.IsDartFunctionType()) { 15670 instantiated_other.IsDartFunctionType()) {
regis 2017/03/22 16:29:32 This may not yet be necessary, but it will as soon
15671 return true; 15671 return true;
15672 } 15672 }
15673 if (!instantiated_other.IsFunctionType()) { 15673 if (!instantiated_other.IsFunctionType()) {
15674 return false; 15674 return false;
15675 } 15675 }
15676 other_signature = Type::Cast(instantiated_other).signature(); 15676 other_signature = Type::Cast(instantiated_other).signature();
15677 other_type_arguments = instantiated_other.arguments(); 15677 other_type_arguments = instantiated_other.arguments();
15678 } else { 15678 } else {
15679 if (!other.IsFunctionType()) { 15679 if (!other.IsFunctionType()) {
15680 return false; 15680 return false;
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
16456 if (other.IsMalbounded()) { 16456 if (other.IsMalbounded()) {
16457 ASSERT(Isolate::Current()->type_checks()); 16457 ASSERT(Isolate::Current()->type_checks());
16458 if ((bound_error != NULL) && bound_error->IsNull()) { 16458 if ((bound_error != NULL) && bound_error->IsNull()) {
16459 *bound_error = other.error(); 16459 *bound_error = other.error();
16460 } 16460 }
16461 return false; 16461 return false;
16462 } 16462 }
16463 // Any type is a subtype of (and is more specific than) Object and dynamic. 16463 // Any type is a subtype of (and is more specific than) Object and dynamic.
16464 // As of Dart 1.5, the Null type is a subtype of (and is more specific than) 16464 // As of Dart 1.5, the Null type is a subtype of (and is more specific than)
16465 // any type. 16465 // any type.
16466 if (other.IsObjectType() || other.IsDynamicType() || IsNullType()) { 16466 if (other.IsObjectType() || other.IsDynamicType() || IsNullType()) {
regis 2017/03/22 16:29:32 || other.IsVoidType()
16467 return true; 16467 return true;
16468 } 16468 }
16469 Zone* zone = Thread::Current()->zone(); 16469 Zone* zone = Thread::Current()->zone();
16470 if (IsBoundedType() || other.IsBoundedType()) { 16470 if (IsBoundedType() || other.IsBoundedType()) {
16471 if (Equals(other)) { 16471 if (Equals(other)) {
16472 return true; 16472 return true;
16473 } 16473 }
16474 // Redundant check if other type is equal to the upper bound of this type. 16474 // Redundant check if other type is equal to the upper bound of this type.
16475 if (IsBoundedType() && 16475 if (IsBoundedType() &&
16476 AbstractType::Handle(BoundedType::Cast(*this).bound()).Equals(other)) { 16476 AbstractType::Handle(BoundedType::Cast(*this).bound()).Equals(other)) {
(...skipping 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after
18109 instantiation_trail, bound_trail, space); 18109 instantiation_trail, bound_trail, space);
18110 // In case types of instantiator_type_arguments are not finalized 18110 // In case types of instantiator_type_arguments are not finalized
18111 // (or instantiated), then the instantiated_bounded_type is not finalized 18111 // (or instantiated), then the instantiated_bounded_type is not finalized
18112 // (or instantiated) either. 18112 // (or instantiated) either.
18113 // Note that instantiator_type_arguments must have the final length, though. 18113 // Note that instantiator_type_arguments must have the final length, though.
18114 } 18114 }
18115 if ((Isolate::Current()->type_checks()) && (bound_error != NULL) && 18115 if ((Isolate::Current()->type_checks()) && (bound_error != NULL) &&
18116 bound_error->IsNull()) { 18116 bound_error->IsNull()) {
18117 AbstractType& upper_bound = AbstractType::Handle(bound()); 18117 AbstractType& upper_bound = AbstractType::Handle(bound());
18118 ASSERT(upper_bound.IsFinalized()); 18118 ASSERT(upper_bound.IsFinalized());
18119 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType()); 18119 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType());
regis 2017/03/22 16:29:32 && !upper_bound.IsVoidType()
18120 AbstractType& instantiated_upper_bound = 18120 AbstractType& instantiated_upper_bound =
18121 AbstractType::Handle(upper_bound.raw()); 18121 AbstractType::Handle(upper_bound.raw());
18122 if (!upper_bound.IsInstantiated()) { 18122 if (!upper_bound.IsInstantiated()) {
18123 instantiated_upper_bound = 18123 instantiated_upper_bound =
18124 upper_bound.InstantiateFrom(instantiator_type_arguments, bound_error, 18124 upper_bound.InstantiateFrom(instantiator_type_arguments, bound_error,
18125 instantiation_trail, bound_trail, space); 18125 instantiation_trail, bound_trail, space);
18126 // The instantiated_upper_bound may not be finalized or instantiated. 18126 // The instantiated_upper_bound may not be finalized or instantiated.
18127 // See comment above. 18127 // See comment above.
18128 } 18128 }
18129 if (bound_error->IsNull()) { 18129 if (bound_error->IsNull()) {
(...skipping 4797 matching lines...) Expand 10 before | Expand all | Expand 10 after
22927 return UserTag::null(); 22927 return UserTag::null();
22928 } 22928 }
22929 22929
22930 22930
22931 const char* UserTag::ToCString() const { 22931 const char* UserTag::ToCString() const {
22932 const String& tag_label = String::Handle(label()); 22932 const String& tag_label = String::Handle(label());
22933 return tag_label.ToCString(); 22933 return tag_label.ToCString();
22934 } 22934 }
22935 22935
22936 } // namespace dart 22936 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698