Repository navigation
Reimplement table.{grow,fill} - #13424
alexcrichton merged 4 commits into
Conversation
This commit refactors the implementation of the `table.{grow,fill}`
WebAssembly instructions to perform more work in compiled code rather
than within the runtime itself. This shrinks the amount of libcalls
needed, for example, simplifies some internals by having them build on
each other, and additionally helps address bytecodealliance#13387 by routing more bulk
operations through a "narrow waist".
This refactors the internals of `memory.fill` and `array.fill`,
previously refactored before, to share more implementation details. The
end result is that the implementation of `table.fill` is a one-liner to
a generic "fill this thing with this value" helper. Additionally the
`table.grow` instruction is reimplemented in terms of this, meaning that
the host is responsible for growth, but compiled code is responsible for
initializing the table.
| // this creates a small window of time where the table actually has null | ||
| // entries. Given that this table isn't shared, however, this is fine | ||
| // because no other wasm instructions (or embedder code) can execute in | ||
| // this window. |
There was a problem hiding this comment.
Add a comment here that we must not have any epoch-yield points within the fill?
(This also seems important in a CM async / cooperative threads context, because otherwise, if an epoch-yield someday becomes run-concurrent-compatible and another async activation runs, it could otherwise observe state halfway through an instruction, right? I don't know if that's a valid concern or if it is statically disallowed but in any case noting the relevant invariants here, and maybe at the bulk-fill loop implementation too, seems like a good idea)
There was a problem hiding this comment.
That's a good point/question, and definitely related to #11869. For now we're fine insofar as async libcalls like yield points will lock up the entire store making it statically impossible to read or write anything within the store. While we do want to fix that (at least somewhat) in the future it's a bit of an open question how to do so. One issue is that we definitely cannot allow mutations during yield points, but that'd still be a problem here if we allow reads. I'll leave comments on that issue since I think that's probably the best place (as opposed to the code) since it's a pervasive concern and not necessarily isolated to just this part of the code.
It's unfortunate as well because I think we explicitly want epoch yields here in table growth in case it's a massive table growth...
This commit refactors the implementation of the
table.{grow,fill}WebAssembly instructions to perform more work in compiled code rather than within the runtime itself. This shrinks the amount of libcalls needed, for example, simplifies some internals by having them build on each other, and additionally helps address #13387 by routing more bulk operations through a "narrow waist".This refactors the internals of
memory.fillandarray.fill, previously refactored before, to share more implementation details. The end result is that the implementation oftable.fillis a one-liner to a generic "fill this thing with this value" helper. Additionally thetable.growinstruction is reimplemented in terms of this, meaning that the host is responsible for growth, but compiled code is responsible for initializing the table.