Add a dataflow-based representation of components (#4597)
* Add a dataflow-based representation of components 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. * Fix compile of factc
This commit is contained in:
@@ -313,17 +313,6 @@ pub enum CoreDef {
|
||||
/// function is immediately `canon lower`'d in the same instance. Such a
|
||||
/// function always traps at runtime.
|
||||
AlwaysTrap(RuntimeAlwaysTrapIndex),
|
||||
/// This refers to a core wasm function which is a synthesized fused adapter
|
||||
/// between two other core wasm functions.
|
||||
///
|
||||
/// The adapter's information is identified by `AdapterIndex` which is
|
||||
/// available through an auxiliary map created during compilation of a
|
||||
/// component. For more information see `adapt.rs`.
|
||||
///
|
||||
/// Note that this is an intermediate variant which is replaced by the time
|
||||
/// a component is fully compiled. This will be replaced with the `Export`
|
||||
/// variant which refers to the export of an adapter module.
|
||||
Adapter(AdapterIndex),
|
||||
/// This is a reference to a wasm global which represents the
|
||||
/// runtime-managed flags for a wasm instance.
|
||||
InstanceFlags(RuntimeComponentInstanceIndex),
|
||||
@@ -436,7 +425,7 @@ pub struct CanonicalOptions {
|
||||
// Note that the `repr(u8)` is load-bearing here since this is used in an
|
||||
// `extern "C" fn()` function argument which is called from cranelift-compiled
|
||||
// code so we must know the representation of this.
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[allow(missing_docs)]
|
||||
#[repr(u8)]
|
||||
pub enum StringEncoding {
|
||||
|
||||
Reference in New Issue
Block a user