-
Notifications
You must be signed in to change notification settings - Fork 824
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
Redesign the API for accessing the contents of a Wasm memory #2646
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR implementation looks good to me.
As a side comment, I think it might be worth to have read
and write
operations on a MemoryBuffer
(new abstraction) instead than in a Memory
.
That way, we will be a bit closer to the js API and we will solve easily the overhead of caching/creating a uint8view
.
Could we just create a view when the memory is created and keep that view alive for the whole lifetime of the memory? |
That sounds good. In the case of JS, if you want to access the memory buffer, you can do Funnily enough, in JS you need to cast again the buffer into a If we could follow a similar API in Rust that would be ideal. Thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we may want to create a buffer/view abstraction on the future to not operate on read/writes directly on memory, but the current implementation is also good until we decide if we want another abstraction or not.
Description
read
/read_uninit
/write
methods ofMemory
. These functions are thread-safe even when there are concurrent modifications to the memory.ValueType
trait has been reworked to also support zeroing out padding bytes in a type. This is necessary to avoid leaking uninitialized data into Wasm memory.ValueType
can now be safely derived with#[derive(ValueType)]
.unsafe impl
is no longer needed.WasmPtr
now dereferences toWasmRef
andWasmSlice
instead of giving raw access to aCell
.WasmPtr
is now generic over the memory size, allowing for 32-bit and 64-bitWasmPtr
s. This is done through aMemorySize
trait andMemory32
/Memory64
types which implement it.WasmRef
andWasmSlice
types are added. UnlikeWasmPtr
these types contain a reference to aMemory
.MemoryView
has been removed, it is superseded byWasmSlice
.Review