Skip to content

The VM needs to account for super-bounded types (supertypes of the instantiated-to-bounds type) in type check optimizations #52848

@sstrickl

Description

@sstrickl

When developing CL 312400, I originally put a check in the VM when in DEBUG mode that verified that each type argument for an InterfaceType read from kernel is a subtype of the corresponding type argument when the class type parameters were instantiated to bounds.

However, that check turned out to be too strong for the CFE as it stands currently, as the CFE can produce kernel where this assumption is broken (from a failing build):

output: ../../runtime/vm/compiler/frontend/kernel_translation_helper.cc: 3335: error:
Expected Type: ExhaustivenessCache<X0, dynamic, dynamic, dynamic, X1> to be a subtype of
  Type: ExhaustivenessCache<Object, Object, Object, Object, Object>,
but Type: dynamic is not a subtype of Type: Object

I then introduced a weaker check, that only checked that fully instantiated types read from kernel were subtypes of the type where the class is instantiated to bounds. This allowed the build to succeed, but that check failed on some tests (see this example from the log for one of the failing trybots):

/==============================================================================================\
| co19/Language/Generics/Superbounded_types/class_A05_t01 broke (Pass -> Crash, expected Pass) |
\==============================================================================================/

...

../../runtime/vm/compiler/frontend/kernel_translation_helper.cc: 3333: error:
Expected non-nullable version of Type: A to be a subtype of Type: A<num>

So currently there are cases where the CFE can generate raw (all type arguments are dynamic) or partially raw types for classes where the (partially) raw type is an invalid instantiation of the class. I'm guessing there's a similar issue with TypedefTypes as well, though I haven't verified that on the VM side.

Should the CFE provide a guarantee that all types generated by the CFE are valid subtypes of the instantiated to bounds type?

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.triagedIssue has been triaged by sub team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions