-
Notifications
You must be signed in to change notification settings - Fork 6
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
alloc free creates, memory import support, and more #3
base: main
Are you sure you want to change the base?
Conversation
and I changed how the names section parser reads the type, while the original implementation seems correct under the current number of subsection types, run!(32) is confusing because it should really only read one byte
I saw no good reason why some parsers should be defined within the generate! macro, and others not. For simplicity, I moved them all outside.
not a cosmetic change, will redo on another branch
Cosmetic parser changes
fix old run_manual! usage
Eliminates all uses of alloc::Box and alloc::Vec when --no-alloc is chosen. The main difficulty with removing Vec is the fact that wasm functions have multi-returns, so when calling indirect we don't know how many returns come back. This commit solves it by allocating as much space on the stack as needed for the highest possible number of returns when calling indirect. There are other non-stack-based solutions, especially the tinyvec crate allows static heapless vector functionality without usage of unsafe.
makes it a lot nicer to consume the rWasm output from another program
Turns out we only need a panic handler in no_std crates if they are dynamic libraries, which shouldn't be necessary for the crate generated by rWasm.
This makes WasmModule::new() const, which allows for static initialization, which is important in heap-less environments. It also makes access functions to global constant exports const, so global export constants can also be statically accessed, which is often useful as well.
will need this for incoming changes
This option allows passing a bytes array slice to the wasm module which will be used for the wasm memory. Since this must have a fixed size, this is currently only possible in combination with --fixed-mem-size. Such a reference to an external chunk of memory requires lifetime annotation, which is a bit messy in the printer, I might try to come up with a macro which relaxes syntax boilerplate for code generation.
the option is implicit if the WASM module imports its memory
Hey! Glad to hear you're using a fork of rWasm for some of your research! Indeed upstreaming things would be good, and I'm open to merging a lot of these changes in. Unfortunately, a few things are going to keep me busy for the next few months to be able to do a proper review of the code just yet, but a few quick comments:
|
Thank you for the feedback
done; I added a dependency for colored output
done
done |
Hey 👋 at eth-easl we're working on a fork of rWasm which we're using in one of our research projects. I would like to upstream as much as possible, so I want to open the discussion on the changes. Feel free to provide feedback on any part.
This PR adds
--no-alloc
--crate-name
notes on the changes to the code:
Vec
from indirect function calls. If the optionno-alloc
is given, it now uses a newenum
allocating an upper bound of space needed for the returns on the stack by considering the largest number of returns from any function in the compiled module.Box
to keep it "simple" with--no-alloc
. AVec
already lives on the heap, and a&mut [u8]
can too, but a memory of typemut [u8]
(--fixed-mem-size
+ not imported memory) now necessarily lives on the stack.mem_type()
function--no-alloc
requires--fixed-mem-size
trait MemoryType
1parser.rs
I think
parser.rs
syntax could use some love, but I couldn't come up with a nice solution yet. Do you have ideas?I did some basic sanity checks after the changes but I didn't test thoroughly. I added a very basic integration test.2
Footnotes
notice that for a
Vec<T>
-like type,T
should probably beSized
, which can't be dynamically dispatched (so noMemoryType
trait objects) ↩I haven't tested WASI, but I didn't make WASI-specific changes. ↩