-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
wasmtime: Implement table.get
and table.set
#1923
wasmtime: Implement table.get
and table.set
#1923
Conversation
Subscribe to Label Action
This issue or pull request has been labeled: "cranelift", "cranelift:meta", "cranelift:wasm", "wasi"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
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.
Nice!
Could this add some more tests too? Some things like:
- Using
table.get
/table.set
on afuncref
table - Calling
table.set
with aref.null
- Calling
table.get
returning aref.null
- calling
table.set
where the previous element isnull
- Calling
table.set
where the previous element had a refcount of 1 (this may be tricky?)
All of these cases are in the spec tests (except explicitly targeting replacing a |
Hm so I do think that it's worthwhile to add some more tests here. I'm a bit hesitant to rely on pure wast tests since all the interesting bits are about how host code interacts with this. For example this program will hit "attempt to subtract with overflow" because the reference count is decremented in wasm but then I do realize that the spec tests try to be somewhat exhaustive, but given that this was pretty easy to segfault I think it's worthwhile trying to be at least somewhat flavorful with tests that exercise the embedding where we have more control over GC and such. |
Yeah I aleady had a fix for the I don't think we need to duplicate anything that's already in the spec tests, just the |
13d3537
to
7499f7b
Compare
Okay, I've added a bunch of tests for pathological gc-in-externref-destructor-while-sweeping behaviors and other various re-entry into GC. Working on a fuzz target specifically for exercising |
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.
Oh man gc-in-dtor is pretty gnarly, totally forgot to think about that! Very nice tests though 👍
This all looks great to me, but as you mentioned at the beginning someone should take a look at the cranelift pieces too.
7499f7b
to
725e713
Compare
Alright, I got the fuzz target written and passing as well! |
Subscribe to Label Actioncc @fitzgen, @peterhuene
This issue or pull request has been labeled: "fuzzing", "wasmtime:api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
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 meta and frontend parts look good to me, with one minor refactoring request:
These instructions have fast, inline JIT paths for the common cases, and only call out to host VM functions for the slow paths. This required some changes to `cranelift-wasm`'s `FuncEnvironment`: instead of taking a `FuncCursor` to insert an instruction sequence within the current basic block, `FuncEnvironment::translate_table_{get,set}` now take a `&mut FunctionBuilder` so that they can create whole new basic blocks. This is necessary for implementing GC read/write barriers that involve branching (e.g. checking for null, or whether a store buffer is at capacity). Furthermore, it required that the `load`, `load_complex`, and `store` instructions handle loading and storing through an `r{32,64}` rather than just `i{32,64}` addresses. This involved making `r{32,64}` types acceptable instantiations of the `iAddr` type variable, plus a few new instruction encodings. Part of bytecodealliance#929
This new fuzz target exercises sequences of `table.get`s, `table.set`s, and GCs. It already found a couple bugs: * Some leaks due to ref count cycles between stores and host-defined functions closing over those stores. * If there are no live references for a PC, Cranelift can avoid emiting an associated stack map. This was running afoul of a debug assertion.
95ebe78
to
a2f4202
Compare
These instructions have fast, inline JIT paths for the common cases, and only
call out to host VM functions for the slow paths. This required some changes to
cranelift-wasm
'sFuncEnvironment
: instead of taking aFuncCursor
to insertan instruction sequence within the current basic block,
FuncEnvironment::translate_table_{get,set}
now take a&mut FunctionBuilder
so that they can create whole new basic blocks. This is necessary for
implementing GC read/write barriers that involve branching (e.g. checking for
null, or whether a store buffer is at capacity).
Furthermore, it required that the
load
,load_complex
, andstore
instructions handle loading and storing through an
r{32,64}
rather than justi{32,64}
addresses. This involved makingr{32,64}
types acceptableinstantiations of the
iAddr
type variable, plus a few new instructionencodings.
Part of #929