Skip to content

Do not let GUFA refine casts to exact when invalid#7530

Merged
tlively merged 18 commits intomainfrom
gufa-exact-casts
Apr 21, 2025
Merged

Do not let GUFA refine casts to exact when invalid#7530
tlively merged 18 commits intomainfrom
gufa-exact-casts

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented Apr 18, 2025

We already prevented GUFA from introduce new exact casts when custom
descriptors is not enabled, but now prevent it from refining existing
casts to be exact as well.

tlively added 18 commits April 17, 2025 17:20
We previously allowed trivial exact casts (i.e. those where the input
and target types are the same) to validate even without custom
descriptors enabled to ensure that finalization always produces valid
casts. But validation can also produce casts where the cast target is a
non-nullable exact reference and the input type is a nullable exact
reference to the same heap type. Update validation to allow these casts.

This is safe because erasing the exactness of the input and cast types
does not change the results of these casts. They succeed iff the input
is a non-null value.
Do not merge types that differ in exactness.
RemoveUnusedBrs can introduce new casts when optimizing out br_on_cast
and br_on_cast_fail instructions. This happens when the pass finds a
more precise type for the fallthrough value reaching the casting branch,
allowing it to improve the cast target type. When the branch is
subsequently optimized out, this precise type information is recovered
with an inserted cast.

Update the pass to avoid creating invalid casts to exact types when
custom descriptors is not enabled.
These features were previously missed when reading target features
sections.
There are several places in the code where we need to make a type
inexact only if custom descriptors is disabled. Add a helper to slightly
simplify those places.
TypeRefining (both the normal and GUFA variants) is able to infer that a
field can be more precise than is immediately apparent from the type of
an expression set to that field. In these cases, the pass inserts a cast
to recover the more precise type information. When custom descriptors
are not enabled, casts to exact types invalid, so avoid introducing new
exactness that might need such invalid casts in that case.
We already prevented GUFA from introduce new exact casts when custom
descriptors is not enabled, but now prevent it from refining existing
casts to be exact as well.
@tlively tlively requested a review from kripken April 18, 2025 20:38
;; We can only refine this cast target to be exact if custom descriptors are
;; allowed.
(ref.cast (ref $foo)
(global.get $g)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these globals? GUFA can infer exactness itself, it doesn't need the not-yet-existing code for struct.new that you mentioned elsewhere. Unless we don't have the GUFA code to turn GUFA exact into Type exact?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, GUFA doesn't know that an exact reference turns into a depth 1 trivial cone and it doesn't know that a trivial cone can be materialized as an exact reference.

Base automatically changed from gufa-type-refining-exact to main April 21, 2025 21:30
@tlively tlively merged commit aee3229 into main Apr 21, 2025
27 of 28 checks passed
@tlively tlively deleted the gufa-exact-casts branch April 21, 2025 22:47
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