Skip to content

Improve support for memory64/shared-everything-threads in components #2104

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

Conversation

alexcrichton
Copy link
Member

Previously the validator in wasm-tools was updated to conservatively reject all aliases of exports of core memories/tables that were 64-bit or shared. This is a coarse approximation of the actual rules though which today disallow using 64-bit memories in the canonical ABI. Instead this commit updates with a few minor changes to improve the situation here, namely:

  • Aliasing core exports is now allowed for any table and memory type.
  • Usage of memories in canonical ABI positions now verifies that the memory is of the expected type, using the standard sub-typing.
  • Usage of tables in canon thread.spawn_indirect now performs a type-check via a similar method to ensure the table is of the right type.

This adjusts the behavior of a few tests here and there as well to account for some slight differences in behavior with these proposals.

Previously the validator in wasm-tools was updated to conservatively
reject all aliases of exports of core memories/tables that were 64-bit
or shared. This is a coarse approximation of the actual rules though
which today disallow using 64-bit memories in the canonical ABI. Instead
this commit updates with a few minor changes to improve the situation
here, namely:

* Aliasing core exports is now allowed for any table and memory type.
* Usage of memories in canonical ABI positions now verifies that the
  memory is of the expected type, using the standard sub-typing.
* Usage of tables in `canon thread.spawn_indirect` now performs a
  type-check via a similar method to ensure the table is of the right type.

This adjusts the behavior of a few tests here and there as well to
account for some slight differences in behavior with these proposals.
Comment on lines +3081 to +3083
if a.shared != b.shared {
bail!(offset, "mismatch in the shared flag for tables")
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll note that this check was actually entirely missing from the table-type-subtyping here (oh dear!)

@@ -3092,6 +3069,39 @@ impl<'a> SubtypeCx<'a> {
}
}

pub(crate) fn table_type(a: &TableType, b: &TableType, offset: usize) -> Result<()> {
if a.element_type != b.element_type {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll also note that this isn't fully GC-compatible because this should actually be a subtype check I think (or something like that)

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe though that this is of the more general problem of "components and gc are not well integrated yet"

@alexcrichton alexcrichton requested a review from abrown March 18, 2025 15:55
Copy link
Member

@abrown abrown left a comment

Choose a reason for hiding this comment

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

LGTM!

bail!(offset, "expected a table of shared `funcref`");
}

SubtypeCx::table_type(
Copy link
Member

Choose a reason for hiding this comment

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

I learn something new every day...


(core module $B (import "" "" (table shared 1 2 (ref null (shared func)))))
(core instance (instantiate $B (with "" (instance (export "" (table $m))))))
)
Copy link
Member

Choose a reason for hiding this comment

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

You want to keep these tests in not-accepted.wast? Or rename this file? Not a big deal if we leave things here, I suppose, just noting the file name.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tend to pay far less attention to filenames than I should unfortunately... I think I'll go ahead and merge this PR, but I think it'd be best to clean up some organization from the old tests/local/* test suite which is no longer necessary in the future

@alexcrichton alexcrichton added this pull request to the merge queue Mar 18, 2025
Merged via the queue into bytecodealliance:main with commit 1d3e4f9 Mar 18, 2025
32 checks passed
@alexcrichton alexcrichton deleted the update-some-validation branch March 18, 2025 17:45
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