Skip to content
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

Shared memory support #9507

Merged
merged 8 commits into from
Nov 1, 2024

Conversation

atilag
Copy link
Contributor

@atilag atilag commented Oct 24, 2024

I was trying to add Shared Memory support in the wasmtime-py library, but I found out that C-API support here was not finished, so this is my bold attempt to implement something that works.

As far as a I read, threads on WASI are still in discussion and Shared Memory is part of the proposal. In the other hand there's some basic support for Shared memory already present in the Rust API interface, so I guess it's fine to try gluing the C-API with what is supported today, and make wasmtime-py works with Shared Memory (?).

@atilag atilag requested review from a team as code owners October 24, 2024 01:49
@atilag atilag requested review from alexcrichton and removed request for a team October 24, 2024 01:49
@atilag atilag marked this pull request as draft October 24, 2024 01:49
@github-actions github-actions bot added fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API. labels Oct 24, 2024
Copy link

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "fuzzing", "wasmtime:api", "wasmtime:c-api"

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

  • fitzgen: fuzzing

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

Learn more.

crates/c-api/src/extern.rs Outdated Show resolved Hide resolved
crates/c-api/src/types/extern.rs Outdated Show resolved Hide resolved
MemoryType::new64(minimum, maximum)
} else {
MemoryType::new(
Box::new(if shared {
Copy link
Member

Choose a reason for hiding this comment

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

Mind panicking here for now with unimplemented!() if both shared and memory64 are set? (we need to add a constructor for that but haven't gotten around to it yet)

Copy link
Member

Choose a reason for hiding this comment

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

Actually I take this back, this may want to use MemoryTypeBuilder to support shared 64-bit memories

@atilag
Copy link
Contributor Author

atilag commented Oct 25, 2024

Suggestions applied!
Wanted to link this issue with this other one from wasmtime-py, as this is a required dependency. We will need to rebuild the _bindings.py after this is merged.

@alexcrichton
Copy link
Member

Thanks! I think we'll still want to remove the SharedMemory arm of ExternType which will help simplify this a bit more though.

@atilag
Copy link
Contributor Author

atilag commented Oct 25, 2024

Done!

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looking good! With MemoryTypeBuilder for the implementation I think this will be good to go 👍

Comment on lines 80 to 83
/// Construct a dummy shared memory for the given memory type.
pub fn dummy_shared_memory(engine: &Engine, ty: MemoryType) -> Result<SharedMemory> {
SharedMemory::new(engine, ty)
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this still needed? (or should it perhaps be integrated elsewhere?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, I just removed it

* moving dummy shared memory
@atilag
Copy link
Contributor Author

atilag commented Oct 30, 2024

Oh, nice, the MemoryTypeBuilder made the code way more readable :)
Done!

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

There's a minor issue with clang-format in CI, but otherwise I think this is good to go 👍

@atilag
Copy link
Contributor Author

atilag commented Oct 31, 2024

Oh, no problem. I can run clang-format and see a green CI :)

@alexcrichton
Copy link
Member

I think there might be something else with clang-format in CI?

If you'd like also feel free to mark this as "ready for review" so it can be approved+merged once CI passes.

@atilag atilag marked this pull request as ready for review October 31, 2024 23:02
@atilag
Copy link
Contributor Author

atilag commented Oct 31, 2024

Yeah, might be the version of clang format usedd in the CI (15?) has different default options than the one I use locally.
Anyway, ready!
Thanks for taking a look Alex!

@alexcrichton
Copy link
Member

I dunno what's going on with clang-format myself, I've attempted to resolve the latest issue with a new commit

@alexcrichton alexcrichton added this pull request to the merge queue Nov 1, 2024
Merged via the queue into bytecodealliance:main with commit 288c151 Nov 1, 2024
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants