Skip to content

Conversation

tlively
Copy link
Member

@tlively tlively commented Sep 29, 2025

Casts generally need special treatment in Unsubtyping because any
subtype of the destination type could flow into the source type and be
successfully cast, meaning all original subtypes of the destination type
that are still subtypes of the source types need to remain subtypes of
the destination type as well. However, exact casts do not have this
property because strict subtypes of the destination type will fail the
cast whether or not they remain subtypes of the destination type in the
optimized module.

Update the analysis so that exact casts require only simple subtyping
between the destination and source types.

With the upcoming stricter validation rules for descriptor types, we can
no longer use the placeholder describee trick in GlobalTypeOptimization,
so its ability to optimize out unneeded descriptors will be
significantly restricted. Because of the increasing coupling between the
validation for subtyping and descriptor relationships, it makes most
sense to optimize both at the same time in Unsubtyping.

Update Unsubtyping to start the analysis assuming no descriptors are
necessary, then add them in as it discovers that they are indeed
necessary either to preserve behavior or validitiy. Discovering new
required descriptors can imply that new subtypings are necessary and
vice versa.
Casts generally need special treatment in Unsubtyping because any
subtype of the destination type could flow into the source type and be
successfully cast, meaning all original subtypes of the destination type
that are still subtypes of the source types need to remain subtypes of
the destination type as well. However, exact casts do not have this
property because strict subtypes of the destination type will fail the
cast whether or not they remain subtypes of the destination type in the
optimized module.

Update the analysis so that exact casts require only simple subtyping
between the destination and source types.
@tlively tlively requested a review from kripken September 29, 2025 22:59
Base automatically changed from unsubtyping-optimize-descs to main October 2, 2025 01:02
@tlively tlively enabled auto-merge (squash) October 2, 2025 23:36
@tlively tlively merged commit 7ba340a into main Oct 3, 2025
16 checks passed
@tlively tlively deleted the unsubtyping-exact-casts branch October 3, 2025 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants