Skip to content

Update exact reference semantics #7499

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 16, 2025
Merged

Update exact reference semantics #7499

merged 17 commits into from
Apr 16, 2025

Conversation

tlively
Copy link
Member

@tlively tlively commented Apr 15, 2025

Disallow exact references to abstract heap types and update subtyping
to match the current proposed semantics.

tlively added 4 commits April 14, 2025 19:26
Revert the following PRs that introduced exactness on HeapType:

 - #7446
 - #7444
 - #7432
 - #7412
 - #7396

Keep only the changes to wasm-type-printing.cpp to fix the assertions
that subclasses of TypeNameGeneratorBase correctly override getNames.

Although putting exactness on heap types makes the most sense in the
Custom Descriptors spec, it is not a great fit for how HeapType is used
in Binaryen. In almost all cases, HeapType is used to represent heap
type definitions rather than the dynamic types of values. Letting
HeapType represent exact heap types is not useful in those cases and
opens up a new class of possible bugs.

To avoid these bugs, we had been introducing a new HeapTypeDef type to
represent heap type definitions, but nearly all uses of HeapType would
have had to have been replaced with HeapTypeDef. Rather than introduce
HeapTypeDef as a third type alongside Type and HeapType, it will be
simpler to continue using HeapType to represent heap type definitions
and Type to represent the dynamic types of values, including their
exactness. While exactness will syntactically be part of the heap type,
it will be part of the `Type` in Binaryen IR.

A follow-on PR will restore the original work on exact references, and
PRs following that one will update the encoding, parsing, and printing
of exact references to match the current spec.
Having decided that storing exactness on the Type rather than HeapType
makes the most sense for our IR, revert the following PRs:

 - #7404
 - #7402

This will restore the original work on exact references. Follow-on PRs
will update it to match the current spec.
In preparation for disallowing inexact references to abstract heap
types, which are no longer allowed by the Custom Descriptors proposal.
Disallow exact references to abstract heap types and update subtyping
to match the current proposed semantics.
@tlively tlively requested a review from kripken April 15, 2025 02:31
@@ -795,13 +795,11 @@ Type Type::getLeastUpperBound(Type a, Type b) {
if (auto heapType = HeapType::getLeastUpperBound(heapTypeA, heapTypeB)) {
auto nullability =
(a.isNullable() || b.isNullable()) ? Nullable : NonNullable;
auto exactness = (a.isInexact() || b.isInexact()) ? Inexact : Exact;
// The LUB can only be exact if the heap types are the same or one of them
// is bottom.
Copy link
Member

Choose a reason for hiding this comment

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

This comment still seems useful, perhaps modified?


assertLUB(exactSup, exactSup, exactSup, exactSup);
assertLUB(exactSup, nullExactSup, nullExactSup, exactSup);
assertLUB(exactSup, sub, sup, none);
Copy link
Member

Choose a reason for hiding this comment

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

About the glb being none, how can I see that in the lattice diagram? I'm confused as to where exact types fit in a lattice like this:

 any
  |
super
  |
 sub
  |
none

Copy link
Member Author

Choose a reason for hiding this comment

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

  any
  |  \
super .
|   \
sub  exact super
|  \           \
.   exact sub   .
    |
    .
....
\||/
none

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@@ -1,6 +1,6 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt -all --preserve-type-order --string-lowering -S -o - | filecheck %s
;; RUN: wasm-opt %s -all --preserve-type-order --string-lowering -S -o - | filecheck %s
Copy link
Member

Choose a reason for hiding this comment

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

Is there any harm to using foreach with a single module? it's future-proof...

Copy link
Member Author

Choose a reason for hiding this comment

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

The only downside is that it makes it slightly more annoying to run the test manually, e.g. to repro bugs. Not much of a downside, but also a very easy change to make or undo, so I think it's worth it.

Base automatically changed from inexact-ref-null to main April 16, 2025 00:51
@tlively tlively merged commit ac98ba6 into main Apr 16, 2025
14 checks passed
@tlively tlively deleted the no-basic-exact-types branch April 16, 2025 01:58
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