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

#include <il.h>

Inheritance diagram for dart::HierarchyInfo:
dart::ThreadStackResource dart::StackResource

Public Member Functions

 HierarchyInfo (Thread *thread)
 
 ~HierarchyInfo ()
 
const CidRangeVectorSubtypeRangesForClass (const Class &klass, bool include_abstract, bool exclude_null)
 
bool InstanceOfHasClassRange (const AbstractType &type, intptr_t *lower_limit, intptr_t *upper_limit)
 
bool CanUseSubtypeRangeCheckFor (const AbstractType &type)
 
bool CanUseGenericSubtypeRangeCheckFor (const AbstractType &type)
 
bool CanUseRecordSubtypeRangeCheckFor (const AbstractType &type)
 
- Public Member Functions inherited from dart::ThreadStackResource
 ThreadStackResource (Thread *T)
 
 ~ThreadStackResource ()
 
Threadthread () const
 
Isolateisolate () const
 
IsolateGroupisolate_group () const
 
- Public Member Functions inherited from dart::StackResource
 StackResource (ThreadState *thread)
 
virtual ~StackResource ()
 
ThreadStatethread () const
 

Static Public Attributes

static constexpr intptr_t kNoCompatibleTAVOffset = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from dart::StackResource
static void Unwind (ThreadState *thread)
 
static void UnwindAbove (ThreadState *thread, StackResource *new_top)
 

Detailed Description

Definition at line 267 of file il.h.

Constructor & Destructor Documentation

◆ HierarchyInfo()

dart::HierarchyInfo::HierarchyInfo ( Thread thread)
inlineexplicit

Definition at line 269 of file il.h.

271 cid_subtype_ranges_nullable_(),
272 cid_subtype_ranges_abstract_nullable_(),
273 cid_subtype_ranges_nonnullable_(),
274 cid_subtype_ranges_abstract_nonnullable_() {
276 }
void set_hierarchy_info(HierarchyInfo *value)
Definition thread.h:593

◆ ~HierarchyInfo()

dart::HierarchyInfo::~HierarchyInfo ( )
inline

Definition at line 278 of file il.h.

278{ thread()->set_hierarchy_info(nullptr); }

Member Function Documentation

◆ CanUseGenericSubtypeRangeCheckFor()

bool dart::HierarchyInfo::CanUseGenericSubtypeRangeCheckFor ( const AbstractType type)

Definition at line 344 of file il.cc.

345 {
346 ASSERT(type.IsFinalized());
347
348 if (!type.IsType() || type.IsDartFunctionType()) {
349 return false;
350 }
351
352 // The FutureOr<T> type cannot be handled by checking whether the instance is
353 // a subtype of FutureOr and then checking whether the type argument `T`
354 // matches.
355 //
356 // Instead we would need to perform multiple checks:
357 //
358 // instance is Null || instance is T || instance is Future<T>
359 //
360 if (type.IsFutureOrType()) {
361 return false;
362 }
363
364 // NOTE: We do allow non-instantiated types here (in comparison to
365 // [CanUseSubtypeRangeCheckFor], since we handle type parameters in the type
366 // expression in some cases (see below).
367
368 Zone* zone = thread()->zone();
369 const Class& type_class = Class::Handle(zone, type.type_class());
370 const intptr_t num_type_parameters = type_class.NumTypeParameters();
371
372 // This function should only be called for generic classes.
373 ASSERT(type_class.NumTypeParameters() > 0 &&
374 Type::Cast(type).arguments() != TypeArguments::null());
375
376 const TypeArguments& ta =
377 TypeArguments::Handle(zone, Type::Cast(type).arguments());
378 ASSERT(ta.Length() == num_type_parameters);
379
380 // Ensure we can handle all type arguments
381 // via [CidRange]-based checks or that it is a type parameter.
382 AbstractType& type_arg = AbstractType::Handle(zone);
383 for (intptr_t i = 0; i < num_type_parameters; ++i) {
384 type_arg = ta.TypeAt(i);
385 if (!CanUseSubtypeRangeCheckFor(type_arg) && !type_arg.IsTypeParameter()) {
386 return false;
387 }
388 }
389
390 return true;
391}
bool CanUseSubtypeRangeCheckFor(const AbstractType &type)
Definition il.cc:305
static ObjectPtr null()
Definition object.h:433
static Object & Handle()
Definition object.h:407
Zone * zone() const
#define ASSERT(E)

◆ CanUseRecordSubtypeRangeCheckFor()

bool dart::HierarchyInfo::CanUseRecordSubtypeRangeCheckFor ( const AbstractType type)

Definition at line 393 of file il.cc.

393 {
394 ASSERT(type.IsFinalized());
395 if (!type.IsRecordType()) {
396 return false;
397 }
398 const RecordType& rec = RecordType::Cast(type);
399 Zone* zone = thread()->zone();
400 auto& field_type = AbstractType::Handle(zone);
401 for (intptr_t i = 0, n = rec.NumFields(); i < n; ++i) {
402 field_type = rec.FieldTypeAt(i);
403 if (!CanUseSubtypeRangeCheckFor(field_type)) {
404 return false;
405 }
406 }
407 return true;
408}

◆ CanUseSubtypeRangeCheckFor()

bool dart::HierarchyInfo::CanUseSubtypeRangeCheckFor ( const AbstractType type)

Definition at line 305 of file il.cc.

305 {
306 ASSERT(type.IsFinalized());
307
308 if (!type.IsInstantiated() || !type.IsType()) {
309 return false;
310 }
311
312 // The FutureOr<T> type cannot be handled by checking whether the instance is
313 // a subtype of FutureOr and then checking whether the type argument `T`
314 // matches.
315 //
316 // Instead we would need to perform multiple checks:
317 //
318 // instance is Null || instance is T || instance is Future<T>
319 //
320 if (type.IsFutureOrType()) {
321 return false;
322 }
323
324 Zone* zone = thread()->zone();
325 const Class& type_class = Class::Handle(zone, type.type_class());
326
327 // We can use class id range checks only if we don't have to test type
328 // arguments.
329 //
330 // This is e.g. true for "String" but also for "List<dynamic>". (A type for
331 // which the type arguments vector is instantiated to bounds is known as a
332 // rare type.)
333 if (type_class.IsGeneric()) {
334 const Type& rare_type = Type::Handle(zone, type_class.RareType());
335 if (!rare_type.IsSubtypeOf(type, Heap::kNew)) {
336 ASSERT(Type::Cast(type).arguments() != TypeArguments::null());
337 return false;
338 }
339 }
340
341 return true;
342}
@ kNew
Definition heap.h:38

◆ InstanceOfHasClassRange()

bool dart::HierarchyInfo::InstanceOfHasClassRange ( const AbstractType type,
intptr_t *  lower_limit,
intptr_t *  upper_limit 
)

Definition at line 410 of file il.cc.

412 {
413 ASSERT(CompilerState::Current().is_aot());
414 if (type.IsNullable()) {
415 // 'is' test for nullable types should accept null cid in addition to the
416 // class range. In most cases it is not possible to extend class range to
417 // include kNullCid.
418 return false;
419 }
421 const Class& type_class =
422 Class::Handle(thread()->zone(), type.type_class());
423 const CidRangeVector& ranges =
424 SubtypeRangesForClass(type_class,
425 /*include_abstract=*/false,
426 /*exclude_null=*/true);
427 if (ranges.length() == 1) {
428 const CidRangeValue& range = ranges[0];
429 ASSERT(!range.IsIllegalRange());
430 *lower_limit = range.cid_start;
431 *upper_limit = range.cid_end;
432 return true;
433 }
434 }
435 return false;
436}
static CompilerState & Current()
const CidRangeVector & SubtypeRangesForClass(const Class &klass, bool include_abstract, bool exclude_null)
Definition il.cc:110
MallocGrowableArray< CidRangeValue > CidRangeVector
Definition il.h:253

◆ SubtypeRangesForClass()

const CidRangeVector & dart::HierarchyInfo::SubtypeRangesForClass ( const Class klass,
bool  include_abstract,
bool  exclude_null 
)

Definition at line 110 of file il.cc.

113 {
114 ClassTable* table = thread()->isolate_group()->class_table();
115 const intptr_t cid_count = table->NumCids();
116 std::unique_ptr<CidRangeVector[]>* cid_ranges = nullptr;
117 if (include_abstract) {
118 cid_ranges = exclude_null ? &cid_subtype_ranges_abstract_nonnullable_
119 : &cid_subtype_ranges_abstract_nullable_;
120 } else {
121 cid_ranges = exclude_null ? &cid_subtype_ranges_nonnullable_
122 : &cid_subtype_ranges_nullable_;
123 }
124 if (*cid_ranges == nullptr) {
125 cid_ranges->reset(new CidRangeVector[cid_count]);
126 }
127 CidRangeVector& ranges = (*cid_ranges)[klass.id()];
128 if (ranges.length() == 0) {
129 BuildRangesFor(table, &ranges, klass, include_abstract, exclude_null);
130 }
131 return ranges;
132}
SI F table(const skcms_Curve *curve, F v)
ClassTable * class_table() const
Definition isolate.h:491
IsolateGroup * isolate_group() const
Definition thread.h:540

Member Data Documentation

◆ kNoCompatibleTAVOffset

constexpr intptr_t dart::HierarchyInfo::kNoCompatibleTAVOffset = 0
staticconstexpr

Definition at line 282 of file il.h.


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