Skip to content

Update TypeMerging for exact types #7580

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged

Update TypeMerging for exact types #7580

merged 1 commit into from
May 13, 2025

Conversation

tlively
Copy link
Member

@tlively tlively commented May 9, 2025

TypeMerging was already careful not to merge a subtype and its supertype
where there is a cast to the subtype that could differentiate it from
its supertype. Now with exact types, it's possible to have an exact cast
to the supertype that can differentiate it from the subtype as well.
Update the pass to collect types used as the target of exact casts and
ensure they are not merged with their subtypes.

It would be natural to use a single map from HeapType to bool to track
the cast target types and whether each one is used in an exact cast, but
that would regress performance because this pass previously used a
SmallSet to track cast types. I spent a few hours trying to create a
SmallMap that shared most of its code with SmallSet, but it would
require more time to make that work. For now, just use a second SmallSet
to track exact exact casts.

TypeMerging was already careful not to merge a subtype and its supertype
where there is a cast to the subtype that could differentiate it from
its supertype. Now with exact types, it's possible to have an exact cast
to the supertype that can differentiate it from the subtype as well.
Update the pass to collect types used as the target of exact casts and
ensure they are not merged with their subtypes.

It would be natural to use a single map from HeapType to bool to track
the cast target types and whether each one is used in an exact cast, but
that would regress performance because this pass previously used a
SmallSet to track cast types. I spent a few hours trying to create a
SmallMap that shared most of its code with SmallSet, but it would
require more time to make that work. For now, just use a second SmallSet
to track exact exact casts.
@tlivelytlively requested a review from kripken May 9, 2025 18:27
@tlivelytlively merged commit 677e0c6 into main May 13, 2025
14 checks passed
@tlivelytlively deleted the exact-type-merging branch May 13, 2025 16:56
Sign up for free to join this conversation on . 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