Stream: git-wasmtime

Topic: wasmtime / PR #4597 Add a dataflow-based representation o...


view this post on Zulip Wasmtime GitHub notifications bot (Aug 03 2022 at 16:24):

alexcrichton opened PR #4597 from component-dfg to main:

This commit updates the inlining phase of compiling a component to
creating a dataflow-based representation of a component instead of
creating a final Component with a linear list of initializers. This
dataflow graph is then linearized in a final step to create the actual
final Component.

The motivation for this commit stems primarily from my work implementing
strings in fused adapters. In doing this my plan is to defer most
low-level transcoding to the host itself rather than implementing that
in the core wasm adapter modules. This means that small
cranelift-generated trampolines will be used for adapter modules to call
which then call "transcoding libcalls". The cranelift-generated
trampolines will get raw pointers into linear memory and pass those to
the libcall which core wasm doesn't have access to when passing
arguments to an import.

Implementing this with the previous representation of a Component was
becoming too tricky to bear. The initialization of a transcoder needed
to happen at just the right time: before the adapter module which needed
it was instantiated but after the linear memories referenced had been
extracted into the VMComponentContext. The difficulty here is further
compounded by the current adapter module injection pass already being
quite complicated. Adapter modules are already renumbering the index
space of runtime instances and shuffling items around in the
GlobalInitializer list. Perhaps the worst part of this was that
memories could already be referenced by host function imports or exports
to the host, and if adapters referenced the same memory it shouldn't be
referenced twice in the component. This meant that ExtractMemory
initializers ideally needed to be shuffled around in the initializer
list to happen as early as possible instead of wherever they happened to
show up during translation.

Overall I did my best to implement the transcoders but everything always
came up short. I have decided to throw my hands up in the air and try a
completely different approach to this, namely the dataflow-based
representation in this commit. This makes it much easier to edit the
component after initial translation for injection of adapters, injection
of transcoders, adding dependencies on possibly-already-existing items,
etc. The adapter module partitioning pass in this commit was greatly
simplified to something which I believe is functionally equivalent but
is probably an order of magnitude easier to understand.

The biggest downside of this representation I believe is having a
duplicate representation of a component. The component::info was
largely duplicated into the component::dfg module in this commit.
Personally though I think this is a more appropriate tradeoff than
before because it's very easy to reason about "convert representation A
to B" code whereas it was very difficult to reason about shuffling
around GlobalInitializer items in optimal fashions. This may also have
a cost at compile-time in terms of shuffling data around, but my hope is
that we have lots of other low-hanging fruit to optimize if it ever
comes to that which allows keeping this easier-to-understand
representation.

Finally, to reiterate, the final representation of components is not
changed by this PR. To the runtime internals everything is still the
same.

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Aug 03 2022 at 16:24):

alexcrichton requested fitzgen for a review on PR #4597.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 04 2022 at 14:12):

alexcrichton updated PR #4597 from component-dfg to main.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 04 2022 at 20:36):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 04 2022 at 20:42):

alexcrichton merged PR #4597.


Last updated: Dec 23 2024 at 12:05 UTC