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

More refactoring to remove MemoryStyle #9543

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

alexcrichton
Copy link
Member

This commit has more refactoring to simplify handling of linear memories in Wasmtime. The end goal is to remove the static/dynamic distinction and simplify the internal implementation and external interface. This is along the same lines of #9528, #9532, #9531, and #9530. The goal of this PR is a series of standalone commits which work towards futher "pushing down" the usage of MemoryStyle down to the consumers of bounds check code. The goal here is to remove layers of abstraction and instead unify everything around the same abstraction of Tunables and wasmtime_environ::Memory. Many fields in Winch/Cranelift HeapData have been removed in favor of storing Memory directly.

This PR affects generated golden tests because previously the global value for the heap bound was not generated if the heap was a "static" heap. With the eventual removal of static/dynamic distinction it's easier to just always generate this and have it not get used most of the time. Thus while the clif output tests are changing none of the actual generated code itself should be changing.

The second option is always `tunables.memory_guard_size`, so propagate
this to the various locations reading it.
Push reading `Tunables` down further into where it's needed instead of
having duplicate storage per-heap.
This commit plumbs `wasmtime_environ::Memory` further down the stack in
Winch to where heaps are processed. This avoids an extra layer of
indirection through a `Heap` type which peels apart a `Memory` to pick
out a few fields. In the future this'll be used with more helpers on
`Memory` to simplify the static/dynamic memory cases.
This commit removes the `HeapStyle` structure from Cranelift and instead
plumbs the `wasmtime_environ::Memory` type further down the stack
through in `HeapData` (same as Winch before this commit). This removes
redundant fields in `MemoryType` and continues to push down the
`MemoryStyle` structure even further.

This commit additionally and unconditionally defines a `GlobalValue` for
the heap limit of memory. This is unused most of the time for 32-bit
wasm and is conditionally used depending on how bounds checks are
generated. This is a small amount of bloat to each function since
previously functions that didn't need this `GlobalValue` elided it. A
future refactoring, however, will make it a bit more clear how this is
used even for "static" memories.
@alexcrichton alexcrichton requested review from a team as code owners November 2, 2024 03:36
@alexcrichton alexcrichton requested review from abrown and pchickey and removed request for a team November 2, 2024 03:36
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Nov 2, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant