Skip to content

Conversation

@alexcrichton
Copy link
Member

This series of commits removes all of the vm::Export* types from Wasmtime. These were all relatively unsafe types which were schlepping around unsafe pointers from point A to point B. In lieu of this and given prior refactorings this commit replaces all of these items with the top-level crate definitions (e.g. crate::Func instead of ExportFunc). The goal here is to improve safety and generally reduce unsafe functions and blocks necessary. A nice benefit is that from a vm::Instance you can now directly load all top-level types such as crate::Table.

This commit removes the unsafe function `Table::from_wasmtime_table`.
This goes a bit further and removes `ExportTable` entirely as well which
means that table lookup on a `vm::Instance` directly returns a
`wasmtime::Table` without any need to translate back-and-forth.
Like the previous commit, but for tags.
Like the previous commit, but for globals.
Like the previous commit, but for memories.
Like previous commits, but for functions.
@alexcrichton alexcrichton requested a review from a team as a code owner July 11, 2025 23:32
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team July 11, 2025 23:32
@github-actions github-actions bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime labels Jul 12, 2025
@github-actions
Copy link

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "wasmtime:api", "wasmtime:ref-types"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: wasmtime:ref-types

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

LGTM modulo one safety comment/question below that should be addressed before merging

Comment on lines -422 to -427
debug_assert!(
wasmtime_export
.table
.ref_type
.is_canonicalized_for_runtime_usage()
);
Copy link
Member

Choose a reason for hiding this comment

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

yesss

Comment on lines 581 to 582
let func_ref = self.get_func_ref(index).unwrap();
ExportFunction { func_ref }
unsafe { crate::Func::from_vm_func_ref(store, func_ref) }
Copy link
Member

Choose a reason for hiding this comment

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

Can we actually encapsulate the unsafety here? Because from_vm_func_ref requires that the store owns the given funcref, but because we take the store as an argument but get the funcref from self, we don't technically have the guarantee that the given store owns this funcref. So I think either this function should be unsafe because it relies on passing the correct StoreId in, or we need to get that StoreId from self somehow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point yeah, I meant to come back and fix this up but forgot to do so. It's a bit unfortunate how infectious the unsafety is here but I agree it's required to be sound regardless.

@alexcrichton alexcrichton enabled auto-merge July 14, 2025 20:51
@alexcrichton alexcrichton added this pull request to the merge queue Jul 14, 2025
Merged via the queue into bytecodealliance:main with commit 2b83228 Jul 14, 2025
42 checks passed
@alexcrichton alexcrichton deleted the less-exports branch July 14, 2025 21:29
bongjunj pushed a commit to prosyslab/wasmtime that referenced this pull request Oct 20, 2025
* Remove `Table::from_wasmtime_table`

This commit removes the unsafe function `Table::from_wasmtime_table`.
This goes a bit further and removes `ExportTable` entirely as well which
means that table lookup on a `vm::Instance` directly returns a
`wasmtime::Table` without any need to translate back-and-forth.

* Remove `Tag::from_wasmtime_tag`

Like the previous commit, but for tags.

* Remove `Global::from_wasmtime_global`

Like the previous commit, but for globals.

* Remove `Memory::from_wasmtime_memory`

Like the previous commit, but for memories.

* Remove `Func::from_wasmtime_function`

Like previous commits, but for functions.

* Fix lints

* Fill out missing safety comment

* Review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants