Flutter Engine
The Flutter Engine
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:313

◆ 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 12800 of file object.cc.

12803 {
12804 ASSERT(!value.IsNull()); // Should be handled by the caller.
12805 ASSERT(value.ptr() != Object::sentinel().ptr());
12806 ASSERT(value.ptr() != Object::transition_sentinel().ptr());
12807
12808 Thread* thread = Thread::Current();
12809 Zone* const zone = thread->zone();
12810 const TypeArguments& static_type_args =
12811 TypeArguments::Handle(zone, static_type.GetInstanceTypeArguments(thread));
12812
12813 TypeArguments& args = TypeArguments::Handle(zone);
12814
12815 ASSERT(static_type.IsFinalized());
12816 const Class& cls = Class::Handle(zone, value.clazz());
12817 GrowableArray<const Type*> path(10);
12818
12819 bool is_super_class = true;
12820 if (!cls.FindInstantiationOf(zone, static_type, &path,
12821 /*consider_only_super_classes=*/true)) {
12822 is_super_class = false;
12823 bool found_super_interface =
12824 cls.FindInstantiationOf(zone, static_type, &path);
12825 ASSERT(found_super_interface);
12826 }
12827
12828 // Trivial case: field has type G<T0, ..., Tn> and value has type
12829 // G<U0, ..., Un>. Check if type arguments match.
12830 if (path.is_empty()) {
12831 ASSERT(cls.ptr() == static_type.type_class());
12832 args = value.GetTypeArguments();
12833 // TODO(dartbug.com/34170) Evaluate if comparing relevant subvectors (that
12834 // disregards superclass own arguments) improves precision of the
12835 // tracking.
12836 if (args.ptr() == static_type_args.ptr()) {
12837 return TrivialTypeExactnessFor(cls);
12838 }
12839
12840 if (print_trace) {
12841 THR_Print(" expected %s got %s type arguments\n",
12842 SafeTypeArgumentsToCString(static_type_args),
12844 }
12846 }
12847
12848 // Value has type C<U0, ..., Un> and field has type G<T0, ..., Tn> and G != C.
12849 // Compute C<X0, ..., Xn> at G (Xi are free type arguments).
12850 // Path array contains a chain of immediate supertypes S0 <: S1 <: ... Sn,
12851 // such that S0 is an immediate supertype of C and Sn is G<...>.
12852 // Each Si might depend on type parameters of the previous supertype S{i-1}.
12853 // To compute C<X0, ..., Xn> at G we walk the chain backwards and
12854 // instantiate Si using type parameters of S{i-1} which gives us a type
12855 // depending on type parameters of S{i-2}.
12856 Type& type = Type::Handle(zone, path.Last()->ptr());
12857 for (intptr_t i = path.length() - 2; (i >= 0) && !type.IsInstantiated();
12858 i--) {
12859 args = path[i]->GetInstanceTypeArguments(thread, /*canonicalize=*/false);
12860 type ^= type.InstantiateFrom(args, TypeArguments::null_type_arguments(),
12862 }
12863
12864 if (type.IsInstantiated()) {
12865 // C<X0, ..., Xn> at G is fully instantiated and does not depend on
12866 // Xi. In this case just check if type arguments match.
12867 args = type.GetInstanceTypeArguments(thread, /*canonicalize=*/false);
12868 if (args.Equals(static_type_args)) {
12869 return is_super_class ? StaticTypeExactnessState::HasExactSuperClass()
12870 : StaticTypeExactnessState::HasExactSuperType();
12871 }
12872
12873 if (print_trace) {
12874 THR_Print(" expected %s got %s type arguments\n",
12875 SafeTypeArgumentsToCString(static_type_args),
12877 }
12878
12880 }
12881
12882 // The most complicated case: C<X0, ..., Xn> at G depends on
12883 // Xi values. To compare type arguments we would need to instantiate
12884 // it fully from value's type arguments and compare with <U0, ..., Un>.
12885 // However this would complicate fast path in the native code. To avoid this
12886 // complication we would optimize for the trivial case: we check if
12887 // C<X0, ..., Xn> at G is exactly G<X0, ..., Xn> which means we can simply
12888 // compare values type arguments (<T0, ..., Tn>) to fields type arguments
12889 // (<U0, ..., Un>) to establish if field type is exact.
12890 ASSERT(cls.IsGeneric());
12891 const intptr_t num_type_params = cls.NumTypeParameters();
12892 bool trivial_case =
12893 (num_type_params ==
12894 Class::Handle(zone, static_type.type_class()).NumTypeParameters()) &&
12895 (value.GetTypeArguments() == static_type_args.ptr());
12896 if (!trivial_case && FLAG_trace_field_guards) {
12897 THR_Print("Not a simple case: %" Pd " vs %" Pd
12898 " type parameters, %s vs %s type arguments\n",
12899 num_type_params,
12900 Class::Handle(zone, static_type.type_class()).NumTypeParameters(),
12902 TypeArguments::Handle(zone, value.GetTypeArguments())),
12903 SafeTypeArgumentsToCString(static_type_args));
12904 }
12905
12906 AbstractType& type_arg = AbstractType::Handle(zone);
12907 args = type.GetInstanceTypeArguments(thread, /*canonicalize=*/false);
12908 for (intptr_t i = 0; (i < num_type_params) && trivial_case; i++) {
12909 type_arg = args.TypeAt(i);
12910 if (!type_arg.IsTypeParameter() ||
12911 (TypeParameter::Cast(type_arg).index() != i)) {
12912 if (FLAG_trace_field_guards) {
12913 THR_Print(" => encountered %s at index % " Pd "\n",
12914 type_arg.ToCString(), i);
12915 }
12916 trivial_case = false;
12917 }
12918 }
12919
12920 return trivial_case ? TrivialTypeExactnessFor(cls)
12921 : StaticTypeExactnessState::NotExact();
12922}
GLenum type
@ kNew
Definition: heap.h:38
static Object & Handle()
Definition: object.h:407
static StaticTypeExactnessState NotExact()
static StaticTypeExactnessState HasExactSuperClass()
static Thread * Current()
Definition: thread.h:362
#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:12784
static const char * SafeTypeArgumentsToCString(const TypeArguments &args)
Definition: object.cc:12796
@ kAllFree
Definition: object.h:2940
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 12924 of file object.cc.

12924 {
12925 if (!IsTracking()) {
12926 return "not-tracking";
12927 } else if (!IsExactOrUninitialized()) {
12928 return "not-exact";
12929 } else if (IsTriviallyExact()) {
12930 return Thread::Current()->zone()->PrintToString(
12931 "trivially-exact(%hhu)", GetTypeArgumentsOffsetInWords());
12932 } else if (IsHasExactSuperType()) {
12933 return "has-exact-super-type";
12934 } else if (IsHasExactSuperClass()) {
12935 return "has-exact-super-class";
12936 } else {
12938 return "uninitialized-exactness";
12939 }
12940}
Zone * zone() const
Definition: thread_state.h:37
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: