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

#include <static_type_exactness_state.h>

Public Member Functions

bool IsTracking () const
 
bool IsUninitialized () const
 
bool IsHasExactSuperClass () const
 
bool IsHasExactSuperType () const
 
bool IsTriviallyExact () const
 
bool NeedsFieldGuard () const
 
bool IsExactOrUninitialized () const
 
bool IsExact () const
 
const char * ToCString () const
 
StaticTypeExactnessState CollapseSuperTypeExactness () const
 
int8_t Encode () const
 
int8_t GetTypeArgumentsOffsetInWords () const
 

Static Public Member Functions

static StaticTypeExactnessState TriviallyExact (intptr_t type_arguments_offset_in_bytes)
 
static bool CanRepresentAsTriviallyExact (intptr_t type_arguments_offset_in_bytes)
 
static StaticTypeExactnessState HasExactSuperType ()
 
static StaticTypeExactnessState HasExactSuperClass ()
 
static StaticTypeExactnessState NotExact ()
 
static StaticTypeExactnessState NotTracking ()
 
static StaticTypeExactnessState Uninitialized ()
 
static StaticTypeExactnessState Compute (const Type &static_type, const Instance &value, bool print_trace=false)
 
static StaticTypeExactnessState Decode (int8_t value)
 

Static Public Attributes

static constexpr int8_t kUninitialized = 0
 

Detailed Description

Definition at line 36 of file static_type_exactness_state.h.

Member Function Documentation

◆ CanRepresentAsTriviallyExact()

static bool dart::StaticTypeExactnessState::CanRepresentAsTriviallyExact ( intptr_t  type_arguments_offset_in_bytes)
inlinestatic

Definition at line 56 of file static_type_exactness_state.h.

57 {
58 return Utils::IsInt(8, type_arguments_offset_in_bytes);
59 }
static bool IsInt(intptr_t N, T value)
Definition utils.h:298

◆ CollapseSuperTypeExactness()

StaticTypeExactnessState dart::StaticTypeExactnessState::CollapseSuperTypeExactness ( ) const
inline

Definition at line 119 of file static_type_exactness_state.h.

119 {
120 return IsHasExactSuperClass() ? HasExactSuperType() : *this;
121 }
static StaticTypeExactnessState HasExactSuperType()

◆ Compute()

StaticTypeExactnessState dart::StaticTypeExactnessState::Compute ( const Type static_type,
const Instance value,
bool  print_trace = false 
)
static

Definition at line 12847 of file object.cc.

12850 {
12851 ASSERT(!value.IsNull()); // Should be handled by the caller.
12852 ASSERT(value.ptr() != Object::sentinel().ptr());
12853 ASSERT(value.ptr() != Object::transition_sentinel().ptr());
12854
12855 Thread* thread = Thread::Current();
12856 Zone* const zone = thread->zone();
12857 const TypeArguments& static_type_args =
12858 TypeArguments::Handle(zone, static_type.GetInstanceTypeArguments(thread));
12859
12860 TypeArguments& args = TypeArguments::Handle(zone);
12861
12862 ASSERT(static_type.IsFinalized());
12863 const Class& cls = Class::Handle(zone, value.clazz());
12864 GrowableArray<const Type*> path(10);
12865
12866 bool is_super_class = true;
12867 if (!cls.FindInstantiationOf(zone, static_type, &path,
12868 /*consider_only_super_classes=*/true)) {
12869 is_super_class = false;
12870 bool found_super_interface =
12871 cls.FindInstantiationOf(zone, static_type, &path);
12872 ASSERT(found_super_interface);
12873 }
12874
12875 // Trivial case: field has type G<T0, ..., Tn> and value has type
12876 // G<U0, ..., Un>. Check if type arguments match.
12877 if (path.is_empty()) {
12878 ASSERT(cls.ptr() == static_type.type_class());
12879 args = value.GetTypeArguments();
12880 // TODO(dartbug.com/34170) Evaluate if comparing relevant subvectors (that
12881 // disregards superclass own arguments) improves precision of the
12882 // tracking.
12883 if (args.ptr() == static_type_args.ptr()) {
12884 return TrivialTypeExactnessFor(cls);
12885 }
12886
12887 if (print_trace) {
12888 THR_Print(" expected %s got %s type arguments\n",
12889 SafeTypeArgumentsToCString(static_type_args),
12891 }
12893 }
12894
12895 // Value has type C<U0, ..., Un> and field has type G<T0, ..., Tn> and G != C.
12896 // Compute C<X0, ..., Xn> at G (Xi are free type arguments).
12897 // Path array contains a chain of immediate supertypes S0 <: S1 <: ... Sn,
12898 // such that S0 is an immediate supertype of C and Sn is G<...>.
12899 // Each Si might depend on type parameters of the previous supertype S{i-1}.
12900 // To compute C<X0, ..., Xn> at G we walk the chain backwards and
12901 // instantiate Si using type parameters of S{i-1} which gives us a type
12902 // depending on type parameters of S{i-2}.
12903 Type& type = Type::Handle(zone, path.Last()->ptr());
12904 for (intptr_t i = path.length() - 2; (i >= 0) && !type.IsInstantiated();
12905 i--) {
12906 args = path[i]->GetInstanceTypeArguments(thread, /*canonicalize=*/false);
12907 type ^= type.InstantiateFrom(args, TypeArguments::null_type_arguments(),
12909 }
12910
12911 if (type.IsInstantiated()) {
12912 // C<X0, ..., Xn> at G is fully instantiated and does not depend on
12913 // Xi. In this case just check if type arguments match.
12914 args = type.GetInstanceTypeArguments(thread, /*canonicalize=*/false);
12915 if (args.Equals(static_type_args)) {
12916 return is_super_class ? StaticTypeExactnessState::HasExactSuperClass()
12917 : StaticTypeExactnessState::HasExactSuperType();
12918 }
12919
12920 if (print_trace) {
12921 THR_Print(" expected %s got %s type arguments\n",
12922 SafeTypeArgumentsToCString(static_type_args),
12924 }
12925
12927 }
12928
12929 // The most complicated case: C<X0, ..., Xn> at G depends on
12930 // Xi values. To compare type arguments we would need to instantiate
12931 // it fully from value's type arguments and compare with <U0, ..., Un>.
12932 // However this would complicate fast path in the native code. To avoid this
12933 // complication we would optimize for the trivial case: we check if
12934 // C<X0, ..., Xn> at G is exactly G<X0, ..., Xn> which means we can simply
12935 // compare values type arguments (<T0, ..., Tn>) to fields type arguments
12936 // (<U0, ..., Un>) to establish if field type is exact.
12937 ASSERT(cls.IsGeneric());
12938 const intptr_t num_type_params = cls.NumTypeParameters();
12939 bool trivial_case =
12940 (num_type_params ==
12941 Class::Handle(zone, static_type.type_class()).NumTypeParameters()) &&
12942 (value.GetTypeArguments() == static_type_args.ptr());
12943 if (!trivial_case && FLAG_trace_field_guards) {
12944 THR_Print("Not a simple case: %" Pd " vs %" Pd
12945 " type parameters, %s vs %s type arguments\n",
12946 num_type_params,
12947 Class::Handle(zone, static_type.type_class()).NumTypeParameters(),
12949 TypeArguments::Handle(zone, value.GetTypeArguments())),
12950 SafeTypeArgumentsToCString(static_type_args));
12951 }
12952
12953 AbstractType& type_arg = AbstractType::Handle(zone);
12954 args = type.GetInstanceTypeArguments(thread, /*canonicalize=*/false);
12955 for (intptr_t i = 0; (i < num_type_params) && trivial_case; i++) {
12956 type_arg = args.TypeAt(i);
12957 if (!type_arg.IsTypeParameter() ||
12958 (TypeParameter::Cast(type_arg).index() != i)) {
12959 if (FLAG_trace_field_guards) {
12960 THR_Print(" => encountered %s at index % " Pd "\n",
12961 type_arg.ToCString(), i);
12962 }
12963 trivial_case = false;
12964 }
12965 }
12966
12967 return trivial_case ? TrivialTypeExactnessFor(cls)
12968 : StaticTypeExactnessState::NotExact();
12969}
@ kNew
Definition heap.h:38
static Object & Handle()
Definition object.h:407
static StaticTypeExactnessState NotExact()
static StaticTypeExactnessState HasExactSuperClass()
static Thread * Current()
Definition thread.h:361
#define THR_Print(format,...)
Definition log.h:20
#define ASSERT(E)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint8_t value
static StaticTypeExactnessState TrivialTypeExactnessFor(const Class &cls)
Definition object.cc:12831
@ kAllFree
Definition object.h:2920
static const char * SafeTypeArgumentsToCString(const TypeArguments &args)
Definition object.cc:12843
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
#define Pd
Definition globals.h:408

◆ Decode()

static StaticTypeExactnessState dart::StaticTypeExactnessState::Decode ( int8_t  value)
inlinestatic

Definition at line 123 of file static_type_exactness_state.h.

123 {
124 return StaticTypeExactnessState(value);
125 }

◆ Encode()

int8_t dart::StaticTypeExactnessState::Encode ( ) const
inline

Definition at line 127 of file static_type_exactness_state.h.

127{ return value_; }

◆ GetTypeArgumentsOffsetInWords()

int8_t dart::StaticTypeExactnessState::GetTypeArgumentsOffsetInWords ( ) const
inline

Definition at line 128 of file static_type_exactness_state.h.

128 {
130 return value_;
131 }

◆ HasExactSuperClass()

static StaticTypeExactnessState dart::StaticTypeExactnessState::HasExactSuperClass ( )
inlinestatic

Definition at line 77 of file static_type_exactness_state.h.

77 {
78 return StaticTypeExactnessState(kHasExactSuperClass);
79 }

◆ HasExactSuperType()

static StaticTypeExactnessState dart::StaticTypeExactnessState::HasExactSuperType ( )
inlinestatic

Definition at line 73 of file static_type_exactness_state.h.

73 {
74 return StaticTypeExactnessState(kHasExactSuperType);
75 }

◆ IsExact()

bool dart::StaticTypeExactnessState::IsExact ( ) const
inline

Definition at line 112 of file static_type_exactness_state.h.

◆ IsExactOrUninitialized()

bool dart::StaticTypeExactnessState::IsExactOrUninitialized ( ) const
inline

Definition at line 111 of file static_type_exactness_state.h.

111{ return value_ > kNotExact; }

◆ IsHasExactSuperClass()

bool dart::StaticTypeExactnessState::IsHasExactSuperClass ( ) const
inline

Definition at line 107 of file static_type_exactness_state.h.

107{ return value_ == kHasExactSuperClass; }

◆ IsHasExactSuperType()

bool dart::StaticTypeExactnessState::IsHasExactSuperType ( ) const
inline

Definition at line 108 of file static_type_exactness_state.h.

108{ return value_ == kHasExactSuperType; }

◆ IsTracking()

bool dart::StaticTypeExactnessState::IsTracking ( ) const
inline

Definition at line 105 of file static_type_exactness_state.h.

105{ return value_ != kNotTracking; }

◆ IsTriviallyExact()

bool dart::StaticTypeExactnessState::IsTriviallyExact ( ) const
inline

Definition at line 109 of file static_type_exactness_state.h.

109{ return value_ > kUninitialized; }

◆ IsUninitialized()

bool dart::StaticTypeExactnessState::IsUninitialized ( ) const
inline

Definition at line 106 of file static_type_exactness_state.h.

106{ return value_ == kUninitialized; }

◆ NeedsFieldGuard()

bool dart::StaticTypeExactnessState::NeedsFieldGuard ( ) const
inline

Definition at line 110 of file static_type_exactness_state.h.

110{ return value_ >= kUninitialized; }

◆ NotExact()

static StaticTypeExactnessState dart::StaticTypeExactnessState::NotExact ( )
inlinestatic

Definition at line 88 of file static_type_exactness_state.h.

88 {
89 return StaticTypeExactnessState(kNotExact);
90 }

◆ NotTracking()

static StaticTypeExactnessState dart::StaticTypeExactnessState::NotTracking ( )
inlinestatic

Definition at line 93 of file static_type_exactness_state.h.

93 {
94 return StaticTypeExactnessState(kNotTracking);
95 }

◆ ToCString()

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

Definition at line 12971 of file object.cc.

12971 {
12972 if (!IsTracking()) {
12973 return "not-tracking";
12974 } else if (!IsExactOrUninitialized()) {
12975 return "not-exact";
12976 } else if (IsTriviallyExact()) {
12977 return Thread::Current()->zone()->PrintToString(
12978 "trivially-exact(%hhu)", GetTypeArgumentsOffsetInWords());
12979 } else if (IsHasExactSuperType()) {
12980 return "has-exact-super-type";
12981 } else if (IsHasExactSuperClass()) {
12982 return "has-exact-super-class";
12983 } else {
12985 return "uninitialized-exactness";
12986 }
12987}
Zone * zone() const
char * PrintToString(const char *format,...) PRINTF_ATTRIBUTE(2
Definition zone.cc:313

◆ TriviallyExact()

static StaticTypeExactnessState dart::StaticTypeExactnessState::TriviallyExact ( intptr_t  type_arguments_offset_in_bytes)
inlinestatic

Definition at line 49 of file static_type_exactness_state.h.

50 {
51 ASSERT((type_arguments_offset_in_bytes > 0) &&
52 Utils::IsInt(8, type_arguments_offset_in_bytes));
53 return StaticTypeExactnessState(type_arguments_offset_in_bytes);
54 }

◆ Uninitialized()

static StaticTypeExactnessState dart::StaticTypeExactnessState::Uninitialized ( )
inlinestatic

Definition at line 97 of file static_type_exactness_state.h.

97 {
98 return StaticTypeExactnessState(kUninitialized);
99 }

Member Data Documentation

◆ kUninitialized

constexpr int8_t dart::StaticTypeExactnessState::kUninitialized = 0
staticconstexpr

Definition at line 133 of file static_type_exactness_state.h.


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