Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
dart::CompileType Class Reference

#include <compile_type.h>

Inheritance diagram for dart::CompileType:
dart::ZoneAllocated

Public Member Functions

 CompileType (bool can_be_null, bool can_be_sentinel, intptr_t cid, const AbstractType *type)
 
 CompileType (const CompileType &other)
 
CompileTypeoperator= (const CompileType &other)
 
bool is_nullable () const
 
bool can_be_sentinel () const
 
const AbstractTypeToAbstractType ()
 
intptr_t ToCid ()
 
intptr_t ToNullableCid ()
 
bool HasDecidableNullability ()
 
bool IsNull ()
 
bool IsSubtypeOf (const AbstractType &other)
 
bool IsAssignableTo (const AbstractType &other)
 
bool IsInstanceOf (const AbstractType &other)
 
CompileType CopyNonNullable ()
 
CompileType CopyNonSentinel ()
 
void Union (CompileType *other)
 
bool IsEqualTo (CompileType *other)
 
bool IsNone () const
 
bool IsObject () const
 
bool IsInt ()
 
bool IsDouble ()
 
bool IsBool ()
 
bool IsNullableInt ()
 
bool IsNullableSmi ()
 
bool IsNullableDouble ()
 
bool IsNullableBool ()
 
bool CanBeSmi ()
 
bool CanBeFuture ()
 
bool Specialize (GrowableArray< intptr_t > *class_ids)
 
void PrintTo (BaseTextBuffer *f) const
 
void PrintTo (JSONWriter *writer) const
 
const char * ToCString () const
 
void set_owner (Definition *owner)
 
Definitionowner () const
 
void Write (FlowGraphSerializer *s) const
 
 CompileType (FlowGraphDeserializer *d)
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Static Public Member Functions

static CompileType FromAbstractType (const AbstractType &type, bool can_be_null, bool can_be_sentinel)
 
static CompileType FromCid (intptr_t cid)
 
static CompileType FromUnboxedRepresentation (Representation rep)
 
static CompileType FromRepresentation (Representation rep)
 
static CompileType None ()
 
static CompileType Dynamic ()
 
static CompileType DynamicOrSentinel ()
 
static CompileType Null ()
 
static CompileType Bool ()
 
static CompileType Int ()
 
static CompileType Int32 ()
 
static CompileType NullableInt ()
 
static CompileType Smi ()
 
static CompileType NullableSmi ()
 
static CompileType NullableMint ()
 
static CompileType Double ()
 
static CompileType NullableDouble ()
 
static CompileType String ()
 
static CompileType Object ()
 
static CompileTypeComputeRefinedType (CompileType *old_type, CompileType *new_type)
 

Static Public Attributes

static constexpr bool kCanBeNull = true
 
static constexpr bool kCannotBeNull = false
 
static constexpr bool kCanBeSentinel = true
 
static constexpr bool kCannotBeSentinel = false
 

Detailed Description

Definition at line 43 of file compile_type.h.

Constructor & Destructor Documentation

◆ CompileType() [1/3]

dart::CompileType::CompileType ( bool  can_be_null,
bool  can_be_sentinel,
intptr_t  cid,
const AbstractType type 
)
inline

Definition at line 51 of file compile_type.h.

55 : can_be_null_(can_be_null),
56 can_be_sentinel_(can_be_sentinel),
57 cid_(cid),
58 type_(type) {}
bool can_be_sentinel() const
const intptr_t cid

◆ CompileType() [2/3]

dart::CompileType::CompileType ( const CompileType other)
inline

Definition at line 60 of file compile_type.h.

61 : ZoneAllocated(),
62 can_be_null_(other.can_be_null_),
63 can_be_sentinel_(other.can_be_sentinel_),
64 cid_(other.cid_),
65 type_(other.type_) {}

◆ CompileType() [3/3]

dart::CompileType::CompileType ( FlowGraphDeserializer d)
explicit

Definition at line 527 of file il_serializer.cc.

528 : can_be_null_(d->Read<bool>()),
529 can_be_sentinel_(d->Read<bool>()),
530 cid_(d->Read<classid_t>()),
531 type_(nullptr) {
532 if (d->Read<bool>()) {
533 type_ = &d->Read<const AbstractType&>();
534 }
535}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
int32_t classid_t
Definition globals.h:524

Member Function Documentation

◆ Bool()

CompileType dart::CompileType::Bool ( )
static

Definition at line 729 of file type_propagator.cc.

729 {
732}
static constexpr bool kCannotBeSentinel
CompileType(bool can_be_null, bool can_be_sentinel, intptr_t cid, const AbstractType *type)
static constexpr bool kCannotBeNull
static Object & ZoneHandle()
Definition object.h:419
static TypePtr BoolType()
Definition object.cc:21882

◆ can_be_sentinel()

bool dart::CompileType::can_be_sentinel ( ) const
inline

Definition at line 80 of file compile_type.h.

80{ return can_be_sentinel_; }

◆ CanBeFuture()

bool dart::CompileType::CanBeFuture ( )

Definition at line 983 of file type_propagator.cc.

983 {
984 Thread* thread = Thread::Current();
985 Zone* zone = thread->zone();
986 if (cid_ != kIllegalCid && cid_ != kDynamicCid) {
987 if ((cid_ == kNullCid) || (cid_ == kNeverCid) ||
988 IsInternalOnlyClassId(cid_) || cid_ == kTypeArgumentsCid) {
989 return false;
990 }
991 const Class& cls =
992 Class::Handle(zone, thread->isolate_group()->class_table()->At(cid_));
993 return cls.is_future_subtype();
994 }
995
996 AbstractType& type = AbstractType::Handle(zone, ToAbstractType()->ptr());
997 if (type.IsTypeParameter()) {
998 type = TypeParameter::Cast(type).bound();
999 }
1000 if (type.IsTypeParameter()) {
1001 // Type parameter bounds can be cyclic, do not bother handling them here.
1002 return true;
1003 }
1004 const intptr_t type_class_id = type.type_class_id();
1005 if (type_class_id == kDynamicCid || type_class_id == kVoidCid ||
1006 type_class_id == kInstanceCid || type_class_id == kFutureOrCid) {
1007 return true;
1008 }
1009 if ((type_class_id == kIllegalCid) || (type_class_id == kNullCid) ||
1010 (type_class_id == kNeverCid)) {
1011 return false;
1012 }
1013 const auto& cls = Class::Handle(zone, type.type_class());
1014 return CHA::ClassCanBeFuture(cls);
1015}
static bool ClassCanBeFuture(const Class &cls)
Definition cha.cc:154
const AbstractType * ToAbstractType()
static Object & Handle()
Definition object.h:407
static Thread * Current()
Definition thread.h:361
@ kIllegalCid
Definition class_id.h:214
@ kNullCid
Definition class_id.h:252
@ kVoidCid
Definition class_id.h:254
@ kDynamicCid
Definition class_id.h:253
@ kNeverCid
Definition class_id.h:255
bool IsInternalOnlyClassId(intptr_t index)
Definition class_id.h:299

◆ CanBeSmi()

bool dart::CompileType::CanBeSmi ( )

Definition at line 975 of file type_propagator.cc.

975 {
976 // Fast path for known cid.
977 if (cid_ != kIllegalCid && cid_ != kDynamicCid) {
978 return cid_ == kSmiCid;
979 }
980 return CanPotentiallyBeSmi(*ToAbstractType(), /*recurse=*/true);
981}
static bool CanPotentiallyBeSmi(const AbstractType &type, bool recurse)

◆ ComputeRefinedType()

CompileType * dart::CompileType::ComputeRefinedType ( CompileType old_type,
CompileType new_type 
)
static

Definition at line 614 of file type_propagator.cc.

615 {
616 ASSERT(new_type != nullptr);
617
618 // In general, prefer the newly inferred type over old type.
619 // It is possible that new and old types are unrelated or do not intersect
620 // at all (for example, in case of unreachable code).
621
622 // Discard None type as it is used to denote an unknown type.
623 if (old_type == nullptr || old_type->IsNone()) {
624 return new_type;
625 }
626 if (new_type->IsNone()) {
627 return old_type;
628 }
629
630 CompileType* preferred_type = nullptr;
631
632 // Prefer exact Cid if known.
633 const intptr_t new_type_cid = new_type->ToCid();
634 const intptr_t old_type_cid = old_type->ToCid();
635 if (new_type_cid != old_type_cid) {
636 if (new_type_cid != kDynamicCid) {
637 preferred_type = new_type;
638 } else if (old_type_cid != kDynamicCid) {
639 preferred_type = old_type;
640 }
641 }
642
643 if (preferred_type == nullptr) {
644 const AbstractType* old_abstract_type = old_type->ToAbstractType();
645 const AbstractType* new_abstract_type = new_type->ToAbstractType();
646
647 // Prefer 'int' if known.
648 if (old_type->IsNullableInt()) {
649 preferred_type = old_type;
650 } else if (new_type->IsNullableInt()) {
651 preferred_type = new_type;
652 } else if (old_abstract_type->IsSubtypeOf(*new_abstract_type, Heap::kOld)) {
653 // Prefer old type, as it is clearly more specific.
654 preferred_type = old_type;
655 } else {
656 // Prefer new type as it is more recent, even though it might be
657 // no better than the old type.
658 preferred_type = new_type;
659 }
660 }
661
662 // Refine non-nullability and whether it can be sentinel.
663 const bool can_be_null = old_type->is_nullable() && new_type->is_nullable();
664 const bool can_be_sentinel =
665 old_type->can_be_sentinel() && new_type->can_be_sentinel();
666
667 if ((preferred_type->is_nullable() && !can_be_null) ||
668 (preferred_type->can_be_sentinel() && !can_be_sentinel)) {
669 return new CompileType(can_be_null, can_be_sentinel, preferred_type->cid_,
670 preferred_type->type_);
671 } else {
672 ASSERT(preferred_type->is_nullable() == can_be_null);
673 ASSERT(preferred_type->can_be_sentinel() == can_be_sentinel);
674 return preferred_type;
675 }
676}
@ kOld
Definition heap.h:39
#define ASSERT(E)

◆ CopyNonNullable()

CompileType dart::CompileType::CopyNonNullable ( )
inline

Definition at line 113 of file compile_type.h.

113 {
114 if (IsNull()) {
115 // Represent a non-nullable null type (typically arising for
116 // unreachable values) as None.
117 return None();
118 }
119
120 return CompileType(kCannotBeNull, can_be_sentinel_, cid_, type_);
121 }
static CompileType None()

◆ CopyNonSentinel()

CompileType dart::CompileType::CopyNonSentinel ( )
inline

Definition at line 124 of file compile_type.h.

124 {
125 return CompileType(can_be_null_, kCannotBeSentinel, cid_, type_);
126 }

◆ Double()

CompileType dart::CompileType::Double ( )
static

Definition at line 757 of file type_propagator.cc.

757 {
758 return CompileType(kCannotBeNull, kCannotBeSentinel, kDoubleCid,
760}
static TypePtr Double()
Definition object.cc:21902

◆ Dynamic()

CompileType dart::CompileType::Dynamic ( )
static

Definition at line 714 of file type_propagator.cc.

714 {
716 &Object::dynamic_type());
717}
static constexpr bool kCanBeNull

◆ DynamicOrSentinel()

CompileType dart::CompileType::DynamicOrSentinel ( )
static

Definition at line 719 of file type_propagator.cc.

719 {
721 &Object::dynamic_type());
722}
static constexpr bool kCanBeSentinel

◆ FromAbstractType()

CompileType dart::CompileType::FromAbstractType ( const AbstractType type,
bool  can_be_null,
bool  can_be_sentinel 
)
static

Definition at line 678 of file type_propagator.cc.

680 {
681 return CompileType(can_be_null && !type.IsStrictlyNonNullable(),
683}

◆ FromCid()

CompileType dart::CompileType::FromCid ( intptr_t  cid)
static

Definition at line 685 of file type_propagator.cc.

685 {
687 if (cid == kDynamicCid) {
688 return CompileType::Dynamic();
689 }
690 return CompileType(cid == kNullCid, cid == kSentinelCid, cid, nullptr);
691}
static CompileType Dynamic()

◆ FromRepresentation()

CompileType dart::CompileType::FromRepresentation ( Representation  rep)
static

Definition at line 705 of file type_propagator.cc.

705 {
706 if (rep == kUntagged) return CompileType::Object();
708 return FromUnboxedRepresentation(rep);
709 }
710 ASSERT(rep != kNoRepresentation);
711 return CompileType::Dynamic();
712}
static CompileType Object()
static CompileType FromUnboxedRepresentation(Representation rep)
static constexpr bool IsUnboxed(Representation rep)
Definition locations.h:101

◆ FromUnboxedRepresentation()

CompileType dart::CompileType::FromUnboxedRepresentation ( Representation  rep)
static

Definition at line 693 of file type_propagator.cc.

693 {
694 ASSERT(rep != kTagged);
695 ASSERT(rep != kUntagged);
697 if (!Boxing::RequiresAllocation(rep)) {
698 return CompileType::Smi();
699 }
700 return CompileType::Int();
701 }
703}
static CompileType FromCid(intptr_t cid)
static CompileType Int()
static CompileType Smi()
static bool RequiresAllocation(Representation rep)
Definition il.cc:468
static intptr_t BoxCid(Representation rep)
Definition il.cc:491
static constexpr bool IsUnboxedInteger(Representation rep)
Definition locations.h:92

◆ HasDecidableNullability()

bool dart::CompileType::HasDecidableNullability ( )

Definition at line 840 of file type_propagator.cc.

840 {
841 return !can_be_null_ || IsNull();
842}

◆ Int()

CompileType dart::CompileType::Int ( )
static

Definition at line 734 of file type_propagator.cc.

734 {
737}
static CompileType FromAbstractType(const AbstractType &type, bool can_be_null, bool can_be_sentinel)
static TypePtr IntType()
Definition object.cc:21886

◆ Int32()

CompileType dart::CompileType::Int32 ( )
static

Definition at line 739 of file type_propagator.cc.

739 {
740#if defined(HAS_SMI_63_BITS)
741 return FromCid(kSmiCid);
742#else
743 return Int();
744#endif
745}

◆ is_nullable()

bool dart::CompileType::is_nullable ( ) const
inline

Definition at line 76 of file compile_type.h.

76{ return can_be_null_; }

◆ IsAssignableTo()

bool dart::CompileType::IsAssignableTo ( const AbstractType other)

Definition at line 882 of file type_propagator.cc.

882 {
883 if (other.IsTopTypeForSubtyping()) {
884 return true;
885 }
886 // If we allow comparisons against an uninstantiated type, then we can
887 // end up incorrectly optimizing away AssertAssignables where the incoming
888 // value and outgoing value have CompileTypes that would return true to the
889 // subtype check below, but at runtime are instantiated with different type
890 // argument vectors such that the relation does not hold for the runtime
891 // instantiated values.
892 //
893 // We might consider using an approximation of the uninstantiated type,
894 // like the instantiation to bounds, and compare to that. However, in
895 // vm/dart/regress_b_230945329_test.dart we have a case where the compared
896 // uninstantiated type is the same as the one in the CompileType. Thus, no
897 // approach will be able to distinguish the two types, and so we fail the
898 // comparison in all cases.
899 if (IsNone() || !other.IsInstantiated()) {
900 return false;
901 }
902 if (is_nullable() && !Instance::NullIsAssignableTo(other)) {
903 return false;
904 }
905 return ToAbstractType()->IsSubtypeOf(other, Heap::kOld);
906}
bool IsSubtypeOf(const AbstractType &other, Heap::Space space, FunctionTypeMapping *function_type_equivalence=nullptr) const
Definition object.cc:21611
bool IsNone() const
bool is_nullable() const
static bool NullIsAssignableTo(const AbstractType &other)
Definition object.cc:20715

◆ IsBool()

bool dart::CompileType::IsBool ( )
inline

Definition at line 233 of file compile_type.h.

233{ return !is_nullable() && IsNullableBool(); }

◆ IsDouble()

bool dart::CompileType::IsDouble ( )
inline

Definition at line 230 of file compile_type.h.

230{ return !is_nullable() && IsNullableDouble(); }

◆ IsEqualTo()

bool dart::CompileType::IsEqualTo ( CompileType other)
inline

Definition at line 214 of file compile_type.h.

214 {
215 return (can_be_null_ == other->can_be_null_) &&
216 (can_be_sentinel_ == other->can_be_sentinel_) &&
217 (ToNullableCid() == other->ToNullableCid()) &&
218 (compiler::IsEqualType(*ToAbstractType(), *other->ToAbstractType()));
219 }
bool IsEqualType(const AbstractType &a, const AbstractType &b)

◆ IsInstanceOf()

bool dart::CompileType::IsInstanceOf ( const AbstractType other)

Definition at line 908 of file type_propagator.cc.

908 {
909 if (other.IsTopTypeForInstanceOf()) {
910 return true;
911 }
912 if (IsNone() || !other.IsInstantiated()) {
913 return false;
914 }
915 if (is_nullable() && !other.IsNullable()) {
916 return false;
917 }
918 return ToAbstractType()->IsSubtypeOf(other, Heap::kOld);
919}

◆ IsInt()

bool dart::CompileType::IsInt ( )
inline

Definition at line 227 of file compile_type.h.

227{ return !is_nullable() && IsNullableInt(); }

◆ IsNone()

bool dart::CompileType::IsNone ( ) const
inline

Definition at line 221 of file compile_type.h.

221{ return (cid_ == kIllegalCid) && (type_ == nullptr); }

◆ IsNull()

bool dart::CompileType::IsNull ( )

Definition at line 844 of file type_propagator.cc.

844 {
845 return (ToCid() == kNullCid);
846}

◆ IsNullableBool()

bool dart::CompileType::IsNullableBool ( )
inline

Definition at line 269 of file compile_type.h.

269 {
270 if (cid_ == kBoolCid) {
271 return true;
272 }
273 if ((cid_ == kIllegalCid) || (cid_ == kDynamicCid)) {
274 return type_ != nullptr && compiler::IsBoolType(*type_);
275 }
276 return false;
277 }
bool IsBoolType(const AbstractType &type)

◆ IsNullableDouble()

bool dart::CompileType::IsNullableDouble ( )
inline

Definition at line 258 of file compile_type.h.

258 {
259 if (cid_ == kDoubleCid) {
260 return true;
261 }
262 if ((cid_ == kIllegalCid) || (cid_ == kDynamicCid)) {
263 return type_ != nullptr && compiler::IsDoubleType(*type_);
264 }
265 return false;
266 }
bool IsDoubleType(const AbstractType &type)

◆ IsNullableInt()

bool dart::CompileType::IsNullableInt ( )
inline

Definition at line 236 of file compile_type.h.

236 {
237 if (cid_ == kSmiCid || cid_ == kMintCid) {
238 return true;
239 }
240 if (cid_ == kIllegalCid || cid_ == kDynamicCid) {
241 return type_ != nullptr && compiler::IsSubtypeOfInt(*type_);
242 }
243 return false;
244 }
bool IsSubtypeOfInt(const AbstractType &type)

◆ IsNullableSmi()

bool dart::CompileType::IsNullableSmi ( )
inline

Definition at line 247 of file compile_type.h.

247 {
248 if (cid_ == kSmiCid) {
249 return true;
250 }
251 if (cid_ == kIllegalCid || cid_ == kDynamicCid) {
252 return type_ != nullptr && compiler::IsSmiType(*type_);
253 }
254 return false;
255 }
bool IsSmiType(const AbstractType &type)

◆ IsObject()

bool dart::CompileType::IsObject ( ) const

Definition at line 777 of file type_propagator.cc.

777 {
778 if (is_nullable()) return false;
779 if (cid_ != kIllegalCid && cid_ != kDynamicCid) return false;
780 return type_ != nullptr && type_->IsObjectType();
781}
bool IsObjectType() const
Definition object.h:9181

◆ IsSubtypeOf()

bool dart::CompileType::IsSubtypeOf ( const AbstractType other)

Definition at line 870 of file type_propagator.cc.

870 {
871 if (other.IsTopTypeForSubtyping()) {
872 return true;
873 }
874
875 if (IsNone()) {
876 return false;
877 }
878
879 return ToAbstractType()->IsSubtypeOf(other, Heap::kOld);
880}

◆ None()

static CompileType dart::CompileType::None ( )
inlinestatic

Definition at line 155 of file compile_type.h.

155 {
157 }

◆ Null()

CompileType dart::CompileType::Null ( )
static

Definition at line 724 of file type_propagator.cc.

724 {
727}
static TypePtr NullType()
Definition object.cc:21862

◆ NullableDouble()

CompileType dart::CompileType::NullableDouble ( )
static

Definition at line 762 of file type_propagator.cc.

762 {
765}
static TypePtr NullableDouble()
Definition object.cc:21906

◆ NullableInt()

CompileType dart::CompileType::NullableInt ( )
static

Definition at line 747 of file type_propagator.cc.

747 {
750}
static TypePtr NullableIntType()
Definition object.cc:21890

◆ NullableMint()

static CompileType dart::CompileType::NullableMint ( )
inlinestatic

Definition at line 188 of file compile_type.h.

188 {
189 return CompileType(kCanBeNull, kCannotBeSentinel, kMintCid, nullptr);
190 }

◆ NullableSmi()

static CompileType dart::CompileType::NullableSmi ( )
inlinestatic

Definition at line 183 of file compile_type.h.

183 {
184 return CompileType(kCanBeNull, kCannotBeSentinel, kSmiCid, nullptr);
185 }

◆ Object()

CompileType dart::CompileType::Object ( )
static

Definition at line 772 of file type_propagator.cc.

772 {
775}
static TypePtr ObjectType()
Definition object.cc:21878

◆ operator=()

CompileType & dart::CompileType::operator= ( const CompileType other)
inline

Definition at line 67 of file compile_type.h.

67 {
68 // This intentionally does not change the owner of this type.
69 can_be_null_ = other.can_be_null_;
70 can_be_sentinel_ = other.can_be_sentinel_;
71 cid_ = other.cid_;
72 type_ = other.type_;
73 return *this;
74 }

◆ owner()

Definition * dart::CompileType::owner ( ) const
inline

Definition at line 304 of file compile_type.h.

304{ return owner_; }

◆ PrintTo() [1/2]

void dart::CompileType::PrintTo ( BaseTextBuffer f) const

Definition at line 1042 of file type_propagator.cc.

1042 {
1043 const char* type_name = "?";
1044 if (IsNone()) {
1045 f->AddString("T{}");
1046 return;
1047 } else if ((cid_ != kIllegalCid) && (cid_ != kDynamicCid)) {
1048 const Class& cls =
1049 Class::Handle(IsolateGroup::Current()->class_table()->At(cid_));
1050 type_name = cls.ScrubbedNameCString();
1051 } else if (type_ != nullptr) {
1052 type_name = type_->IsDynamicType() ? "*" : type_->ScrubbedNameCString();
1053 } else if (!is_nullable()) {
1054 type_name = "!null";
1055 }
1056
1057 f->Printf("T{%s%s%s}", type_name, can_be_null_ ? "?" : "",
1058 can_be_sentinel_ ? "~" : "");
1059}
const char * ScrubbedNameCString() const
Definition object.cc:21407
bool IsDynamicType() const
Definition object.h:9166
static IsolateGroup * Current()
Definition isolate.h:534

◆ PrintTo() [2/2]

void dart::CompileType::PrintTo ( JSONWriter writer) const

Definition at line 1018 of file type_propagator.cc.

1018 {
1019 if (IsNone()) {
1020 return;
1021 }
1022
1023 if (cid_ != kIllegalCid && cid_ != kDynamicCid) {
1024 const Class& cls =
1025 Class::Handle(IsolateGroup::Current()->class_table()->At(cid_));
1026 writer->PrintPropertyStr("c", String::Handle(cls.ScrubbedName()));
1027 }
1028
1029 if (type_ != nullptr && !type_->IsDynamicType()) {
1030 writer->PrintPropertyStr("t", String::Handle(type_->ScrubbedName()));
1031 }
1032
1033 if (can_be_null_) {
1034 writer->PrintPropertyBool("n", true);
1035 }
1036
1037 if (can_be_sentinel_) {
1038 writer->PrintPropertyBool("s", true);
1039 }
1040}
StringPtr ScrubbedName() const
Definition object.cc:21403

◆ set_owner()

void dart::CompileType::set_owner ( Definition owner)
inline

Definition at line 303 of file compile_type.h.

303{ owner_ = owner; }
Definition * owner() const

◆ Smi()

CompileType dart::CompileType::Smi ( )
static

Definition at line 752 of file type_propagator.cc.

752 {
755}
static TypePtr SmiType()
Definition object.cc:21894

◆ Specialize()

bool dart::CompileType::Specialize ( GrowableArray< intptr_t > *  class_ids)

Definition at line 921 of file type_propagator.cc.

921 {
923 if (cid_ != kDynamicCid) {
924 class_ids->Add(cid_);
925 return true;
926 }
927 if (type_ != nullptr && type_->type_class_id() != kIllegalCid) {
928 const Class& type_class = Class::Handle(type_->type_class());
929 if (!CHA::ConcreteSubclasses(type_class, class_ids)) return false;
930 if (can_be_null_) {
931 class_ids->Add(kNullCid);
932 }
933 if (can_be_sentinel_) {
934 class_ids->Add(kSentinelCid);
935 }
936 }
937 return false;
938}
virtual classid_t type_class_id() const
Definition object.cc:21074
virtual ClassPtr type_class() const
Definition object.cc:21083
void Add(const T &value)
static bool ConcreteSubclasses(const Class &cls, GrowableArray< intptr_t > *class_ids)
Definition cha.cc:90

◆ String()

CompileType dart::CompileType::String ( )
static

Definition at line 767 of file type_propagator.cc.

767 {
770}
static TypePtr StringType()
Definition object.cc:21930

◆ ToAbstractType()

const AbstractType * dart::CompileType::ToAbstractType ( )

Definition at line 848 of file type_propagator.cc.

848 {
849 if (type_ == nullptr) {
850 // Type propagation has not run. Return dynamic-type.
851 if (cid_ == kIllegalCid) {
852 return &Object::dynamic_type();
853 }
854
855 // VM-internal objects don't have a compile-type. Return dynamic-type
856 // in this case.
857 if (IsInternalOnlyClassId(cid_) || cid_ == kTypeArgumentsCid) {
858 type_ = &Object::dynamic_type();
859 return type_;
860 }
861
862 auto IG = IsolateGroup::Current();
863 const Class& type_class = Class::Handle(IG->class_table()->At(cid_));
864 type_ = &AbstractType::ZoneHandle(type_class.RareType());
865 }
866
867 return type_;
868}
#define IG

◆ ToCid()

intptr_t dart::CompileType::ToCid ( )

Definition at line 783 of file type_propagator.cc.

783 {
784 if (cid_ == kIllegalCid) {
785 // Make sure to initialize cid_ for Null type to consistently return
786 // kNullCid.
787 if ((type_ != nullptr) && type_->IsNullType()) {
788 cid_ = kNullCid;
789 }
790 // Same for sentinel.
791 if ((type_ != nullptr) && type_->IsSentinelType()) {
792 cid_ = kSentinelCid;
793 }
794 }
795
796 if ((cid_ == kDynamicCid) || (can_be_null_ && (cid_ != kNullCid)) ||
797 (can_be_sentinel_ && (cid_ != kSentinelCid))) {
798 return kDynamicCid;
799 }
800
801 return ToNullableCid();
802}
bool IsNullType() const
Definition object.cc:21428
bool IsSentinelType() const
Definition object.cc:21436

◆ ToCString()

const char * dart::CompileType::ToCString ( ) const

Definition at line 1061 of file type_propagator.cc.

1061 {
1062 char buffer[1024];
1063 BufferFormatter f(buffer, sizeof(buffer));
1064 PrintTo(&f);
1066}
void PrintTo(BaseTextBuffer *f) const
Zone * zone() const
char * MakeCopyOfString(const char *str)
Definition zone.cc:270
static const uint8_t buffer[]

◆ ToNullableCid()

intptr_t dart::CompileType::ToNullableCid ( )

Definition at line 804 of file type_propagator.cc.

804 {
805 if (cid_ == kIllegalCid) {
806 if (type_ == nullptr) {
807 // Type propagation is turned off or has not yet run.
808 return kDynamicCid;
809 } else if (type_->IsVoidType()) {
810 cid_ = kDynamicCid;
811 } else if (type_->IsNullType()) {
812 cid_ = kNullCid;
813 } else if (type_->IsSentinelType()) {
814 cid_ = kSentinelCid;
815 } else if (type_->IsFunctionType() || type_->IsDartFunctionType()) {
816 cid_ = kClosureCid;
817 } else if (type_->IsRecordType() || type_->IsDartRecordType()) {
818 cid_ = kRecordCid;
819 } else if (type_->type_class_id() != kIllegalCid) {
820 const Class& type_class = Class::Handle(type_->type_class());
821 intptr_t implementation_cid = kIllegalCid;
823 &implementation_cid)) {
824 cid_ = implementation_cid;
825 } else {
826 cid_ = kDynamicCid;
827 }
828 } else {
829 cid_ = kDynamicCid;
830 }
831 }
832
833 if (can_be_sentinel_ && (cid_ != kSentinelCid)) {
834 return kDynamicCid;
835 }
836
837 return cid_;
838}
bool IsDartFunctionType() const
Definition object.cc:21512
bool IsDartRecordType() const
Definition object.cc:21521
bool IsVoidType() const
Definition object.h:9169
static bool HasSingleConcreteImplementation(const Class &interface, intptr_t *implementation_cid)
Definition cha.cc:127

◆ Union()

void dart::CompileType::Union ( CompileType other)

Definition at line 557 of file type_propagator.cc.

557 {
558 if (other->IsNone()) {
559 return;
560 }
561
562 if (IsNone()) {
563 *this = *other;
564 return;
565 }
566
567 can_be_null_ = can_be_null_ || other->can_be_null_;
568 can_be_sentinel_ = can_be_sentinel_ || other->can_be_sentinel_;
569
570 ToNullableCid(); // Ensure cid_ is set.
571 if ((cid_ == kNullCid) || (cid_ == kSentinelCid)) {
572 cid_ = other->cid_;
573 type_ = other->type_;
574 return;
575 }
576
577 other->ToNullableCid(); // Ensure other->cid_ is set.
578 if ((other->cid_ == kNullCid) || (other->cid_ == kSentinelCid)) {
579 return;
580 }
581
582 const AbstractType* abstract_type = ToAbstractType();
583 if (cid_ != other->cid_) {
584 cid_ = kDynamicCid;
585 }
586
587 const AbstractType* other_abstract_type = other->ToAbstractType();
588 if (abstract_type->IsSubtypeOf(*other_abstract_type, Heap::kOld)) {
589 type_ = other_abstract_type;
590 return;
591 } else if (other_abstract_type->IsSubtypeOf(*abstract_type, Heap::kOld)) {
592 return; // Nothing to do.
593 }
594
595 // Climb up the hierarchy to find a suitable supertype. Note that interface
596 // types are not considered, making the union potentially non-commutative
597 if (abstract_type->IsInstantiated() && !abstract_type->IsDynamicType() &&
598 !abstract_type->IsFunctionType() && !abstract_type->IsRecordType()) {
599 Class& cls = Class::Handle(abstract_type->type_class());
600 for (; !cls.IsNull() && !cls.IsGeneric(); cls = cls.SuperClass()) {
601 type_ = &AbstractType::ZoneHandle(cls.RareType());
602 if (other_abstract_type->IsSubtypeOf(*type_, Heap::kOld)) {
603 // Found suitable supertype: keep type_ only.
604 cid_ = kDynamicCid;
605 return;
606 }
607 }
608 }
609
610 // Can't unify.
611 type_ = &Object::dynamic_type();
612}

◆ Write()

void dart::CompileType::Write ( FlowGraphSerializer s) const

Definition at line 515 of file il_serializer.cc.

515 {
516 s->Write<bool>(can_be_null_);
517 s->Write<bool>(can_be_sentinel_);
518 s->Write<classid_t>(cid_);
519 if (type_ == nullptr) {
520 s->Write<bool>(false);
521 } else {
522 s->Write<bool>(true);
523 s->Write<const AbstractType&>(*type_);
524 }
525}
struct MyStruct s

Member Data Documentation

◆ kCanBeNull

constexpr bool dart::CompileType::kCanBeNull = true
staticconstexpr

Definition at line 45 of file compile_type.h.

◆ kCanBeSentinel

constexpr bool dart::CompileType::kCanBeSentinel = true
staticconstexpr

Definition at line 48 of file compile_type.h.

◆ kCannotBeNull

constexpr bool dart::CompileType::kCannotBeNull = false
staticconstexpr

Definition at line 46 of file compile_type.h.

◆ kCannotBeSentinel

constexpr bool dart::CompileType::kCannotBeSentinel = false
staticconstexpr

Definition at line 49 of file compile_type.h.


The documentation for this class was generated from the following files: