Repository: bytecodealliance/wasmtime
Pull request #2093 (2020-08-04 19:15:59)

Start compiling module-linking modules 


This commit is intended to be the first of many in implementing the
module linking proposal. At this time this builds on #2059 so it
shouldn't land yet. The goal of this commit is to compile bare-bones
modules which use module linking, e.g. those with nested modules.

My hope with module linking is that almost everything in wasmtime only
needs mild refactorings to handle it. The goal is that all per-module
structures are still per-module and at the top level there's just a
`Vec` containing a bunch of modules. That's implemented currently where
`wasmtime::Module` contains `Arc<[CompiledModule]>` and an index of
which one it's pointing to. This should enable
serialization/deserialization of any module in a nested modules
scenario, no matter how you got it.

Tons of features of the module linking proposal are missing from this
commit. For example instantiation flat out doesn't work, nor does
import/export of modules or instances. That'll be coming as future
commits, but the purpose here is to start laying groundwork in Wasmtime
for handling lots of modules in lots of places.



github-actions[bot]: #### Subscribe to Label Action

cc @bnjbvr, @fitzgen, @peterhuene

<details>
This issue or pull request has been labeled: "cranelift", "cranelift:wasm", "fuzzing", "lightbeam", "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

* bnjbvr: cranelift
* fitzgen: fuzzing
* peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.

[Learn more.](https://github.com/bytecodealliance/subscribe-to-label-action)
</details>
alexcrichton: Ok I've rebased this now and I think it should be ready for review!

Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index e0a4c535b..910a032c7 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -55,9 +55,11 @@ jobs:
     - uses: actions/checkout@v2
       with:
         submodules: true
+    # Note that we use nightly Rust here to get intra-doc links which are a
+    # nightly-only feature right now.
     - uses: ./.github/actions/install-rust
       with:
-        toolchain: nightly-2020-11-02
+        toolchain: nightly
     - run: cargo doc --no-deps --all --exclude wasmtime-cli --exclude test-programs --exclude cranelift-codegen-meta
     - run: cargo doc --package cranelift-codegen-meta --document-private-items
     - uses: actions/upload-artifact@v1
@@ -91,8 +93,6 @@ jobs:
       with:
         submodules: true
     - uses: ./.github/actions/install-rust
-      with:
-        toolchain: nightly-2020-11-02
 
     # Check some feature combinations of the `wasmtime` crate
     - run: cargo check --manifest-path crates/wasmtime/Cargo.toml --no-default-features
@@ -140,9 +140,11 @@ jobs:
     - uses: actions/checkout@v2
       with:
         submodules: true
+    # Note that building with fuzzers requires nightly since it uses unstable
+    # flags to rustc.
     - uses: ./.github/actions/install-rust
       with:
-        toolchain: nightly-2020-11-02
+        toolchain: nightly
     - run: cargo install cargo-fuzz --vers "^0.8"
     - run: cargo fetch
       working-directory: ./fuzz
@@ -199,7 +201,7 @@ jobs:
             rust: beta
           - build: nightly
             os: ubuntu-latest
-            rust: nightly-2020-11-02
+            rust: nightly
           - build: macos
             os: macos-latest
             rust: stable
@@ -268,12 +270,10 @@ jobs:
       env:
         RUST_BACKTRACE: 1
 
-    # Build and test lightbeam if we're using the nightly toolchain. Note that
+    # Build and test lightbeam. Note that
     # Lightbeam tests fail right now, but we don't want to block on that.
     - run: cargo build --package lightbeam
-      if: matrix.build == 'nightly'
     - run: cargo test --package lightbeam
-      if: matrix.build == 'nightly'
       continue-on-error: true
       env:
         RUST_BACKTRACE: 1
@@ -290,7 +290,7 @@ jobs:
         submodules: true
     - uses: ./.github/actions/install-rust
       with:
-        toolchain: nightly-2020-11-02
+        toolchain: nightly
     - uses: ./.github/actions/define-llvm-env
 
     # Install wasm32 targets in order to build various tests throughout the
@@ -301,7 +301,7 @@ jobs:
     # Run the x64 CI script.
     - run: ./ci/run-experimental-x64-ci.sh
       env:
-        CARGO_VERSION: "+nightly-2020-11-02"
+        CARGO_VERSION: "+nightly"
         RUST_BACKTRACE: 1
 
   # Verify that cranelift's code generation is deterministic
diff --git a/Cargo.lock b/Cargo.lock
index b83f6bb1a..b9441fb68 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -183,20 +183,22 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
 
 [[package]]
 name = "capstone"
-version = "0.6.0"
+version = "0.7.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "031ba51c39151a1d6336ec859646153187204b0147c7b3f6fe2de636f1b8dbb3"
+checksum = "f60e7f097987a09a9b678c6214b5a5eb326f9fc1e3eac88cce5d086c2b3b8dc9"
 dependencies = [
  "capstone-sys",
+ "libc",
 ]
 
 [[package]]
 name = "capstone-sys"
-version = "0.10.0"
+version = "0.11.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fae25eddcb80e24f98c35952c37a91ff7f8d0f60dbbdafb9763e8d5cc566b8d7"
+checksum = "aebe07897b48983847943662bfc3198aabfa51636c81313c1955d04d857ed739"
 dependencies = [
  "cc",
+ "libc",
 ]
 
 [[package]]
@@ -710,14 +712,14 @@ dependencies = [
 
 [[package]]
 name = "dynasm"
-version = "0.5.2"
+version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "42a814e1edeb85dd2a3c6fc0d6bf76d02ca5695d438c70ecee3d90774f3259c5"
+checksum = "62a59fbab09460c1569eeea9b5e4cf62f13f5198b1c2ba0e5196dd7fdd17cd42"
 dependencies = [
  "bitflags",
  "byteorder",
  "lazy_static",
- "owning_ref",
+ "proc-macro-error",
  "proc-macro2",
  "quote",
  "syn",
@@ -725,11 +727,12 @@ dependencies = [
 
 [[package]]
 name = "dynasmrt"
-version = "0.5.2"
+version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8a393aaeb4441a48bcf47b5b6155971f82cc1eb77e22855403ccc0415ac8328d"
+checksum = "85bec3edae2841d37b1c3dc7f3fd403c9061f26e9ffeeee97a3ea909b1bb2ef1"
 dependencies = [
  "byteorder",
+ "dynasm",
  "memmap",
 ]
 
@@ -1070,6 +1073,7 @@ name = "lightbeam"
 version = "0.21.0"
 dependencies = [
  "anyhow",
+ "arrayvec",
  "capstone",
  "cranelift-codegen",
  "derive_more",
@@ -1082,7 +1086,6 @@ dependencies = [
  "more-asserts",
  "quickcheck",
  "smallvec",
- "staticvec",
  "thiserror",
  "typemap",
  "wasmparser 0.65.0",
@@ -1247,15 +1250,6 @@ dependencies = [
  "winapi",
 ]
 
-[[package]]
-name = "owning_ref"
-version = "0.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce"
-dependencies = [
- "stable_deref_trait",
-]
-
 [[package]]
 name = "peepmatic"
 version = "0.68.0"
@@ -1853,12 +1847,6 @@ version = "1.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
 
-[[package]]
-name = "staticvec"
-version = "0.10.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c87f4be0fd89694157f3814ca88715ad8ba6010c453b1e89ca264aee04d70b9"
-
 [[package]]
 name = "strsim"
 version = "0.8.0"
diff --git a/cranelift/Cargo.toml b/cranelift/Cargo.toml
index 5f9e6960b..9594f22bf 100644
--- a/cranelift/Cargo.toml
+++ b/cranelift/Cargo.toml
@@ -32,7 +32,7 @@ cranelift = { path = "umbrella", version = "0.68.0" }
 filecheck = "0.5.0"
 log = "0.4.8"
 term = "0.6.1"
-capstone = { version = "0.6.0", optional = true }
+capstone = { version = "0.7.0", optional = true }
 wat = { version = "1.0.18", optional = true }
 target-lexicon = { version = "0.11", features = ["std"] }
 peepmatic-souper = { path = "./peepmatic/crates/souper", version = "0.68.0", optional = true }
diff --git a/cranelift/src/disasm.rs b/cranelift/src/disasm.rs
index 413bafcd3..90dec397a 100644
--- a/cranelift/src/disasm.rs
+++ b/cranelift/src/disasm.rs
@@ -133,35 +133,40 @@ cfg_if! {
                 Architecture::X86_32(_) => Capstone::new()
                     .x86()
                     .mode(arch::x86::ArchMode::Mode32)
-                    .build()?,
+                    .build()
+                    .map_err(map_caperr)?,
                 Architecture::X86_64 => Capstone::new()
                     .x86()
                     .mode(arch::x86::ArchMode::Mode64)
-                    .build()?,
+                    .build()
+                    .map_err(map_caperr)?,
                 Architecture::Arm(arm) => {
                     if arm.is_thumb() {
                         Capstone::new()
                             .arm()
                             .mode(arch::arm::ArchMode::Thumb)
-                            .build()?
+                            .build()
+                            .map_err(map_caperr)?
                     } else {
                         Capstone::new()
                             .arm()
                             .mode(arch::arm::ArchMode::Arm)
-                            .build()?
+                            .build()
+                            .map_err(map_caperr)?
                     }
                 }
                 Architecture::Aarch64 {..} => {
                     let mut cs = Capstone::new()
                         .arm64()
                         .mode(arch::arm64::ArchMode::Arm)
-                        .build()?;
+                        .build()
+                        .map_err(map_caperr)?;
                     // AArch64 uses inline constants rather than a separate constant pool right now.
                     // Without this option, Capstone will stop disassembling as soon as it sees
                     // an inline constant that is not also a valid instruction. With this option,
                     // Capstone will print a `.byte` directive with the bytes of the inline constant
                     // and continue to the next instruction.
-                    cs.set_skipdata(true)?;
+                    cs.set_skipdata(true).map_err(map_caperr)?;
                     cs
                 }
                 _ => anyhow::bail!("Unknown ISA"),
@@ -208,6 +213,10 @@ cfg_if! {
             }
             Ok(())
         }
+
+        fn map_caperr(err: capstone::Error) -> anyhow::Error{
+            anyhow::format_err!("{}", err)
+        }
     } else {
         pub fn print_disassembly(_: &dyn TargetIsa, _: &[u8]) -> Result<()> {
             println!("\nNo disassembly available.");
diff --git a/cranelift/wasm/src/environ/spec.rs b/cranelift/wasm/src/environ/spec.rs
index 06e207e4f..b01cd4376 100644
--- a/cranelift/wasm/src/environ/spec.rs
+++ b/cranelift/wasm/src/environ/spec.rs
@@ -847,4 +847,31 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
     fn wasm_features(&self) -> WasmFeatures {
         WasmFeatures::default()
     }
+
+    /// Indicates that this module will have `amount` submodules.
+    ///
+    /// Note that this is just child modules of this module, and each child
+    /// module may have yet more submodules.
+    fn reserve_modules(&mut self, amount: u32) {
+        drop(amount);
+    }
+
+    /// Called at the beginning of translating a module.
+    ///
+    /// The `index` argument is a monotonically increasing index which
+    /// corresponds to the nth module that's being translated. This is not the
+    /// 32-bit index in the current module's index space. For example the first
+    /// call to `module_start` will have index 0.
+    ///
+    /// Note that for nested modules this may be called multiple times.
+    fn module_start(&mut self, index: usize) {
+        drop(index);
+    }
+
+    /// Called at the end of translating a module.
+    ///
+    /// Note that for nested modules this may be called multiple times.
+    fn module_end(&mut self, index: usize) {
+        drop(index);
+    }
 }
diff --git a/cranelift/wasm/src/module_translator.rs b/cranelift/wasm/src/module_translator.rs
index 89e6923fc..0b1794158 100644
--- a/cranelift/wasm/src/module_translator.rs
+++ b/cranelift/wasm/src/module_translator.rs
@@ -8,6 +8,7 @@ use crate::sections_translator::{
 };
 use crate::state::ModuleTranslationState;
 use cranelift_codegen::timing;
+use std::prelude::v1::*;
 use wasmparser::{NameSectionReader, Parser, Payload, Validator};
 
 /// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cranelift IR
@@ -20,14 +21,23 @@ pub fn translate_module<'data>(
     let mut module_translation_state = ModuleTranslationState::new();
     let mut validator = Validator::new();
     validator.wasm_features(environ.wasm_features());
+    let mut stack = Vec::new();
+    let mut modules = 1;
+    let mut cur_module = 0;
 
     for payload in Parser::new(0).parse_all(data) {
         match payload? {
             Payload::Version { num, range } => {
                 validator.version(num, &range)?;
+                environ.module_start(cur_module);
             }
             Payload::End => {
                 validator.end()?;
+                environ.module_end(cur_module);
+                if let Some((other, other_index)) = stack.pop() {
+                    validator = other;
+                    cur_module = other_index;
+                }
             }
 
             Payload::TypeSection(types) => {
@@ -97,7 +107,7 @@ pub fn translate_module<'data>(
 
             Payload::ModuleSection(s) => {
                 validator.module_section(&s)?;
-                unimplemented!("module linking not implemented yet")
+                environ.reserve_modules(s.get_count());
             }
             Payload::InstanceSection(s) => {
                 validator.instance_section(&s)?;
@@ -113,11 +123,14 @@ pub fn translate_module<'data>(
                 size: _,
             } => {
                 validator.module_code_section_start(count, &range)?;
-                unimplemented!("module linking not implemented yet")
             }
 
             Payload::ModuleCodeSectionEntry { .. } => {
-                unimplemented!("module linking not implemented yet")
+                let subvalidator = validator.module_code_section_entry();
+                stack.push((validator, cur_module));
+                validator = subvalidator;
+                cur_module = modules;
+                modules += 1;
             }
 
             Payload::CustomSection {
diff --git a/cranelift/wasm/src/sections_translator.rs b/cranelift/wasm/src/sections_translator.rs
index da52b2846..a2bb64955 100644
--- a/cranelift/wasm/src/sections_translator.rs
+++ b/cranelift/wasm/src/sections_translator.rs
@@ -41,25 +41,43 @@ pub fn parse_type_section(
     environ.reserve_signatures(count)?;
 
     for entry in types {
-        if let Ok(TypeDef::Func(wasm_func_ty)) = entry {
-            let mut sig =
-                Signature::new(ModuleEnvironment::target_config(environ).default_call_conv);
-            sig.params.extend(wasm_func_ty.params.iter().map(|ty| {
-                let cret_arg: ir::Type = type_to_type(*ty, environ)
-                    .expect("only numeric types are supported in function signatures");
-                AbiParam::new(cret_arg)
-            }));
-            sig.returns.extend(wasm_func_ty.returns.iter().map(|ty| {
-                let cret_arg: ir::Type = type_to_type(*ty, environ)
-                    .expect("only numeric types are supported in function signatures");
-                AbiParam::new(cret_arg)
-            }));
-            environ.declare_signature(wasm_func_ty.clone().try_into()?, sig)?;
-            module_translation_state
-                .wasm_types
-                .push((wasm_func_ty.params, wasm_func_ty.returns));
-        } else {
-            unimplemented!("module linking not implemented yet")
+        match entry? {
+            TypeDef::Func(wasm_func_ty) => {
+                let mut sig =
+                    Signature::new(ModuleEnvironment::target_config(environ).default_call_conv);
+                sig.params.extend(wasm_func_ty.params.iter().map(|ty| {
+                    let cret_arg: ir::Type = type_to_type(*ty, environ)
+                        .expect("only numeric types are supported in function signatures");
+                    AbiParam::new(cret_arg)
+                }));
+                sig.returns.extend(wasm_func_ty.returns.iter().map(|ty| {
+                    let cret_arg: ir::Type = type_to_type(*ty, environ)
+                        .expect("only numeric types are supported in function signatures");
+                    AbiParam::new(cret_arg)
+                }));
+                environ.declare_signature(wasm_func_ty.clone().try_into()?, sig)?;
+                module_translation_state
+                    .wasm_types
+                    .push((wasm_func_ty.params, wasm_func_ty.returns));
+            }
+
+            // Not implemented yet for module linking. Push dummy function types
+            // though to keep the function type index space consistent. We'll
+            // want an actual implementation here that handles this eventually.
+            TypeDef::Module(_) | TypeDef::Instance(_) => {
+                let sig =
+                    Signature::new(ModuleEnvironment::target_config(environ).default_call_conv);
+                environ.declare_signature(
+                    crate::environ::WasmFuncType {
+                        params: Box::new([]),
+                        returns: Box::new([]),
+                    },
+                    sig,
+                )?;
+                module_translation_state
+                    .wasm_types
+                    .push((Box::new([]), Box::new([])));
+            }
         }
     }
     Ok(())
diff --git a/crates/cranelift/src/lib.rs b/crates/cranelift/src/lib.rs
index 30ba228b2..f128ab571 100644
--- a/crates/cranelift/src/lib.rs
+++ b/crates/cranelift/src/lib.rs
@@ -99,7 +99,7 @@ use std::sync::Mutex;
 use wasmtime_environ::{
     CompileError, CompiledFunction, Compiler, FunctionAddressMap, FunctionBodyData,
     InstructionAddressMap, ModuleTranslation, Relocation, RelocationTarget, StackMapInformation,
-    TrapInformation,
+    TrapInformation, Tunables,
 };
 
 mod func_environ;
@@ -356,9 +356,9 @@ impl Compiler for Cranelift {
         func_index: DefinedFuncIndex,
         mut input: FunctionBodyData<'_>,
         isa: &dyn isa::TargetIsa,
+        tunables: &Tunables,
     ) -> Result<CompiledFunction, CompileError> {
         let module = &translation.module;
-        let tunables = &translation.tunables;
         let func_index = module.func_index(func_index);
         let mut context = Context::new();
         context.func.name = get_func_name(func_index);
diff --git a/crates/environ/src/compilation.rs b/crates/environ/src/compilation.rs
index c3ecd2e45..5008273bc 100644
--- a/crates/environ/src/compilation.rs
+++ b/crates/environ/src/compilation.rs
@@ -1,7 +1,7 @@
 //! A `Compilation` contains the compiled function bodies for a WebAssembly
 //! module.
 
-use crate::{FunctionAddressMap, FunctionBodyData, ModuleTranslation};
+use crate::{FunctionAddressMap, FunctionBodyData, ModuleTranslation, Tunables};
 use cranelift_codegen::{binemit, ir, isa, isa::unwind::UnwindInfo};
 use cranelift_entity::PrimaryMap;
 use cranelift_wasm::{DefinedFuncIndex, FuncIndex, WasmError};
@@ -103,5 +103,6 @@ pub trait Compiler: Send + Sync {
         index: DefinedFuncIndex,
         data: FunctionBodyData<'_>,
         isa: &dyn isa::TargetIsa,
+        tunables: &Tunables,
     ) -> Result<CompiledFunction, CompileError>;
 }
diff --git a/crates/environ/src/module.rs b/crates/environ/src/module.rs
index 54a162e4d..d2c651578 100644
--- a/crates/environ/src/module.rs
+++ b/crates/environ/src/module.rs
@@ -325,6 +325,12 @@ impl Module {
     }
 }
 
+impl Default for Module {
+    fn default() -> Module {
+        Module::new()
+    }
+}
+
 mod passive_data_serde {
     use super::{Arc, DataIndex, HashMap};
     use serde::{de::MapAccess, de::Visitor, ser::SerializeMap, Deserializer, Serializer};
diff --git a/crates/environ/src/module_environ.rs b/crates/environ/src/module_environ.rs
index 60e105924..85ae46ba8 100644
--- a/crates/environ/src/module_environ.rs
+++ b/crates/environ/src/module_environ.rs
@@ -6,12 +6,13 @@ use cranelift_codegen::isa::TargetFrontendConfig;
 use cranelift_entity::PrimaryMap;
 use cranelift_wasm::{
     self, translate_module, DataIndex, DefinedFuncIndex, ElemIndex, FuncIndex, Global, GlobalIndex,
-    Memory, MemoryIndex, ModuleTranslationState, SignatureIndex, Table, TableIndex,
-    TargetEnvironment, WasmError, WasmFuncType, WasmResult,
+    Memory, MemoryIndex, SignatureIndex, Table, TableIndex, TargetEnvironment, WasmError,
+    WasmFuncType, WasmResult,
 };
 use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
 use std::convert::TryFrom;
+use std::mem;
 use std::path::PathBuf;
 use std::sync::Arc;
 use wasmparser::Type as WasmType;
@@ -19,19 +20,29 @@ use wasmparser::{FuncValidator, FunctionBody, ValidatorResources, WasmFeatures};
 
 /// Object containing the standalone environment information.
 pub struct ModuleEnvironment<'data> {
-    /// The result to be filled in.
+    /// The current module being translated
     result: ModuleTranslation<'data>,
-    code_index: u32,
+
+    /// Modules which have finished translation. This only really applies for
+    /// the module linking proposal.
+    results: Vec<ModuleTranslation<'data>>,
+
+    /// Modules which are in-progress for being translated (our parents) and
+    /// we'll resume once we finish the current module. This is only applicable
+    /// with the module linking proposal.
+    in_progress: Vec<ModuleTranslation<'data>>,
+
+    // Various bits and pieces of configuration
     features: WasmFeatures,
+    target_config: TargetFrontendConfig,
+    tunables: Tunables,
 }
 
 /// The result of translating via `ModuleEnvironment`. Function bodies are not
 /// yet translated, and data initializers have not yet been copied out of the
 /// original buffer.
+#[derive(Default)]
 pub struct ModuleTranslation<'data> {
-    /// Compilation setting flags.
-    pub target_config: TargetFrontendConfig,
-
     /// Module information.
     pub module: Module,
 
@@ -44,14 +55,14 @@ pub struct ModuleTranslation<'data> {
     /// References to the data initializers.
     pub data_initializers: Vec<DataInitializer<'data>>,
 
-    /// Tunable parameters.
-    pub tunables: Tunables,
+    /// DWARF debug information, if enabled, parsed from the module.
+    pub debuginfo: DebugInfoData<'data>,
 
-    /// The decoded Wasm types for the module.
-    pub module_translation: Option<ModuleTranslationState>,
+    /// Indexes into the returned list of translations that are submodules of
+    /// this module.
+    pub submodules: Vec<usize>,
 
-    /// DWARF debug information, if enabled, parsed from the module.
-    pub debuginfo: Option<DebugInfoData<'data>>,
+    code_index: u32,
 }
 
 /// Contains function data: byte code and its offset in the module.
@@ -111,36 +122,25 @@ impl<'data> ModuleEnvironment<'data> {
         features: &WasmFeatures,
     ) -> Self {
         Self {
-            result: ModuleTranslation {
-                target_config,
-                module: Module::new(),
-                native_signatures: PrimaryMap::new(),
-                function_body_inputs: PrimaryMap::new(),
-                data_initializers: Vec::new(),
-                tunables: tunables.clone(),
-                module_translation: None,
-                debuginfo: if tunables.debug_info {
-                    Some(DebugInfoData::default())
-                } else {
-                    None
-                },
-            },
-            code_index: 0,
+            result: ModuleTranslation::default(),
+            results: Vec::with_capacity(1),
+            in_progress: Vec::new(),
+            target_config,
+            tunables: tunables.clone(),
             features: *features,
         }
     }
 
     fn pointer_type(&self) -> ir::Type {
-        self.result.target_config.pointer_type()
+        self.target_config.pointer_type()
     }
 
     /// Translate a wasm module using this environment. This consumes the
     /// `ModuleEnvironment` and produces a `ModuleTranslation`.
-    pub fn translate(mut self, data: &'data [u8]) -> WasmResult<ModuleTranslation<'data>> {
-        assert!(self.result.module_translation.is_none());
-        let module_translation = translate_module(data, &mut self)?;
-        self.result.module_translation = Some(module_translation);
-        Ok(self.result)
+    pub fn translate(mut self, data: &'data [u8]) -> WasmResult<Vec<ModuleTranslation<'data>>> {
+        translate_module(data, &mut self)?;
+        assert!(self.results.len() > 0);
+        Ok(self.results)
     }
 
     fn declare_export(&mut self, export: EntityIndex, name: &str) -> WasmResult<()> {
@@ -152,13 +152,13 @@ impl<'data> ModuleEnvironment<'data> {
     }
 
     fn register_dwarf_section(&mut self, name: &str, data: &'data [u8]) {
-        let info = match &mut self.result.debuginfo {
-            Some(info) => info,
-            None => return,
-        };
+        if !self.tunables.debug_info {
+            return;
+        }
         if !name.starts_with(".debug_") {
             return;
         }
+        let info = &mut self.result.debuginfo;
         let dwarf = &mut info.dwarf;
         let endian = gimli::LittleEndian;
         let slice = gimli::EndianSlice::new(data, endian);
@@ -190,7 +190,7 @@ impl<'data> ModuleEnvironment<'data> {
 
 impl<'data> TargetEnvironment for ModuleEnvironment<'data> {
     fn target_config(&self) -> TargetFrontendConfig {
-        self.result.target_config
+        self.target_config
     }
 
     fn reference_type(&self, ty: cranelift_wasm::WasmType) -> ir::Type {
@@ -242,9 +242,7 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
             EntityIndex::Function(func_index),
         ));
         self.result.module.num_imported_funcs += 1;
-        if let Some(info) = &mut self.result.debuginfo {
-            info.wasm_file.imported_func_count += 1;
-        }
+        self.result.debuginfo.wasm_file.imported_func_count += 1;
         Ok(())
     }
 
@@ -254,7 +252,7 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
             self.result.module.num_imported_tables,
             "Imported tables must be declared first"
         );
-        let plan = TablePlan::for_table(table, &self.result.tunables);
+        let plan = TablePlan::for_table(table, &self.tunables);
         let table_index = self.result.module.table_plans.push(plan);
         self.result.module.imports.push((
             module.to_owned(),
@@ -279,7 +277,7 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
         if memory.shared {
             return Err(WasmError::Unsupported("shared memories".to_owned()));
         }
-        let plan = MemoryPlan::for_memory(memory, &self.result.tunables);
+        let plan = MemoryPlan::for_memory(memory, &self.tunables);
         let memory_index = self.result.module.memory_plans.push(plan);
         self.result.module.imports.push((
             module.to_owned(),
@@ -336,7 +334,7 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
     }
 
     fn declare_table(&mut self, table: Table) -> WasmResult<()> {
-        let plan = TablePlan::for_table(table, &self.result.tunables);
+        let plan = TablePlan::for_table(table, &self.tunables);
         self.result.module.table_plans.push(plan);
         Ok(())
     }
@@ -353,7 +351,7 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
         if memory.shared {
             return Err(WasmError::Unsupported("shared memories".to_owned()));
         }
-        let plan = MemoryPlan::for_memory(memory, &self.result.tunables);
+        let plan = MemoryPlan::for_memory(memory, &self.tunables);
         self.result.module.memory_plans.push(plan);
         Ok(())
     }
@@ -444,9 +442,7 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
     }
 
     fn reserve_function_bodies(&mut self, _count: u32, offset: u64) {
-        if let Some(info) = &mut self.result.debuginfo {
-            info.wasm_file.code_section_offset = offset;
-        }
+        self.result.debuginfo.wasm_file.code_section_offset = offset;
     }
 
     fn define_function_body(
@@ -454,8 +450,8 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
         validator: FuncValidator<ValidatorResources>,
         body: FunctionBody<'data>,
     ) -> WasmResult<()> {
-        if let Some(info) = &mut self.result.debuginfo {
-            let func_index = self.code_index + self.result.module.num_imported_funcs as u32;
+        if self.tunables.debug_info {
+            let func_index = self.result.code_index + self.result.module.num_imported_funcs as u32;
             let func_index = FuncIndex::from_u32(func_index);
             let sig_index = self.result.module.functions[func_index];
             let sig = &self.result.module.signatures[sig_index];
@@ -463,15 +459,19 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
             for pair in body.get_locals_reader()? {
                 locals.push(pair?);
             }
-            info.wasm_file.funcs.push(FunctionMetadata {
-                locals: locals.into_boxed_slice(),
-                params: sig.params.iter().cloned().map(|i| i.into()).collect(),
-            });
+            self.result
+                .debuginfo
+                .wasm_file
+                .funcs
+                .push(FunctionMetadata {
+                    locals: locals.into_boxed_slice(),
+                    params: sig.params.iter().cloned().map(|i| i.into()).collect(),
+                });
         }
         self.result
             .function_body_inputs
             .push(FunctionBodyData { validator, body });
-        self.code_index += 1;
+        self.result.code_index += 1;
         Ok(())
     }
 
@@ -520,8 +520,8 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
 
     fn declare_module_name(&mut self, name: &'data str) {
         self.result.module.name = Some(name.to_string());
-        if let Some(info) = &mut self.result.debuginfo {
-            info.name_section.module_name = Some(name);
+        if self.tunables.debug_info {
+            self.result.debuginfo.name_section.module_name = Some(name);
         }
     }
 
@@ -530,16 +530,20 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
             .module
             .func_names
             .insert(func_index, name.to_string());
-        if let Some(info) = &mut self.result.debuginfo {
-            info.name_section
+        if self.tunables.debug_info {
+            self.result
+                .debuginfo
+                .name_section
                 .func_names
                 .insert(func_index.as_u32(), name);
         }
     }
 
     fn declare_local_name(&mut self, func_index: FuncIndex, local: u32, name: &'data str) {
-        if let Some(info) = &mut self.result.debuginfo {
-            info.name_section
+        if self.tunables.debug_info {
+            self.result
+                .debuginfo
+                .name_section
                 .locals_names
                 .entry(func_index.as_u32())
                 .or_insert(HashMap::new())
@@ -574,6 +578,34 @@ and for re-adding support for interface types you can see this issue:
     fn wasm_features(&self) -> WasmFeatures {
         self.features
     }
+
+    fn reserve_modules(&mut self, amount: u32) {
+        let extra = self.results.capacity() + (amount as usize) - self.results.len();
+        self.results.reserve(extra);
+        self.result.submodules.reserve(amount as usize);
+    }
+
+    fn module_start(&mut self, index: usize) {
+        // skip the first module since `self.result` is already empty and we'll
+        // be translating into that.
+        if index > 0 {
+            let in_progress = mem::replace(&mut self.result, ModuleTranslation::default());
+            self.in_progress.push(in_progress);
+        }
+    }
+
+    fn module_end(&mut self, index: usize) {
+        let to_continue = match self.in_progress.pop() {
+            Some(m) => m,
+            None => {
+                assert_eq!(index, 0);
+                ModuleTranslation::default()
+            }
+        };
+        let finished = mem::replace(&mut self.result, to_continue);
+        self.result.submodules.push(self.results.len());
+        self.results.push(finished);
+    }
 }
 
 /// Add environment-specific function parameters.
diff --git a/crates/jit/src/compiler.rs b/crates/jit/src/compiler.rs
index 86adb133d..48fcb2c68 100644
--- a/crates/jit/src/compiler.rs
+++ b/crates/jit/src/compiler.rs
@@ -3,6 +3,8 @@
 use crate::instantiate::SetupError;
 use crate::object::{build_object, ObjectUnwindInfo};
 use object::write::Object;
+#[cfg(feature = "parallel-compilation")]
+use rayon::prelude::*;
 use std::hash::{Hash, Hasher};
 use std::mem;
 use wasmparser::WasmFeatures;
@@ -127,31 +129,21 @@ impl Compiler {
         translation: &mut ModuleTranslation,
     ) -> Result<Compilation, SetupError> {
         let functions = mem::take(&mut translation.function_body_inputs);
-        cfg_if::cfg_if! {
-            if #[cfg(feature = "parallel-compilation")] {
-                use rayon::prelude::*;
-                let iter = functions
-                    .into_iter()
-                    .collect::<Vec<_>>()
-                    .into_par_iter();
-            } else {
-                let iter = functions.into_iter();
-            }
-        }
-        let funcs = iter
+        let functions = functions.into_iter().collect::<Vec<_>>();
+        let funcs = maybe_parallel!(functions.(into_iter | into_par_iter))
             .map(|(index, func)| {
                 self.compiler
-                    .compile_function(translation, index, func, &*self.isa)
+                    .compile_function(translation, index, func, &*self.isa, &self.tunables)
             })
             .collect::<Result<Vec<_>, _>>()?
             .into_iter()
             .collect::<CompiledFunctions>();
 
-        let dwarf_sections = if translation.debuginfo.is_some() && !funcs.is_empty() {
+        let dwarf_sections = if self.tunables.debug_info && !funcs.is_empty() {
             transform_dwarf_data(
                 &*self.isa,
                 &translation.module,
-                translation.debuginfo.as_ref().unwrap(),
+                &translation.debuginfo,
                 &funcs,
             )?
         } else {
@@ -191,6 +183,9 @@ impl Hash for Compiler {
         isa.frontend_config().hash(hasher);
         tunables.hash(hasher);
 
+        // Catch accidental bugs of reusing across crate versions.
+        env!("CARGO_PKG_VERSION").hash(hasher);
+
         // TODO: ... and should we hash anything else? There's a lot of stuff in
         // `TargetIsa`, like registers/encodings/etc. Should we be hashing that
         // too? It seems like wasmtime doesn't configure it too too much, but
diff --git a/crates/jit/src/instantiate.rs b/crates/jit/src/instantiate.rs
index e8b224ebe..7807c80c3 100644
--- a/crates/jit/src/instantiate.rs
+++ b/crates/jit/src/instantiate.rs
@@ -8,6 +8,8 @@ use crate::compiler::{Compilation, Compiler};
 use crate::link::link_module;
 use crate::object::ObjectUnwindInfo;
 use object::File as ObjectFile;
+#[cfg(feature = "parallel-compilation")]
+use rayon::prelude::*;
 use serde::{Deserialize, Serialize};
 use std::any::Any;
 use std::sync::Arc;
@@ -71,70 +73,75 @@ pub struct CompilationArtifacts {
     debug_info: bool,
 }
 
-#[derive(Serialize, Deserialize, Clone)]
-struct FunctionInfo {
-    traps: Vec<TrapInformation>,
-    address_map: FunctionAddressMap,
-    stack_maps: Vec<StackMapInformation>,
-}
-
 impl CompilationArtifacts {
-    /// Builds compilation artifacts.
-    pub fn build(compiler: &Compiler, data: &[u8]) -> Result<Self, SetupError> {
-        let environ = ModuleEnvironment::new(
+    /// Creates a `CompilationArtifacts` for a singular translated wasm module.
+    pub fn build(
+        compiler: &Compiler,
+        data: &[u8],
+    ) -> Result<Vec<CompilationArtifacts>, SetupError> {
+        let translations = ModuleEnvironment::new(
             compiler.frontend_config(),
             compiler.tunables(),
             compiler.features(),
-        );
-
-        let mut translation = environ
-            .translate(data)
-            .map_err(|error| SetupError::Compile(CompileError::Wasm(error)))?;
-
-        let Compilation {
-            obj,
-            unwind_info,
-            funcs,
-        } = compiler.compile(&mut translation)?;
-
-        let ModuleTranslation {
-            module,
-            data_initializers,
-            ..
-        } = translation;
-
-        let data_initializers = data_initializers
-            .into_iter()
-            .map(OwnedDataInitializer::new)
-            .collect::<Vec<_>>()
-            .into_boxed_slice();
-
-        let obj = obj.write().map_err(|_| {
-            SetupError::Instantiate(InstantiationError::Resource(
-                "failed to create image memory".to_string(),
-            ))
-        })?;
-
-        Ok(Self {
-            module,
-            obj: obj.into_boxed_slice(),
-            unwind_info: unwind_info.into_boxed_slice(),
-            data_initializers,
-            funcs: funcs
-                .into_iter()
-                .map(|(_, func)| FunctionInfo {
-                    stack_maps: func.stack_maps,
-                    traps: func.traps,
-                    address_map: func.address_map,
+        )
+        .translate(data)
+        .map_err(|error| SetupError::Compile(CompileError::Wasm(error)))?;
+
+        maybe_parallel!(translations.(into_iter | into_par_iter))
+            .map(|mut translation| {
+                let Compilation {
+                    obj,
+                    unwind_info,
+                    funcs,
+                } = compiler.compile(&mut translation)?;
+
+                let ModuleTranslation {
+                    module,
+                    data_initializers,
+                    ..
+                } = translation;
+
+                let data_initializers = data_initializers
+                    .into_iter()
+                    .map(OwnedDataInitializer::new)
+                    .collect::<Vec<_>>()
+                    .into_boxed_slice();
+
+                let obj = obj.write().map_err(|_| {
+                    SetupError::Instantiate(InstantiationError::Resource(
+                        "failed to create image memory".to_string(),
+                    ))
+                })?;
+
+                Ok(CompilationArtifacts {
+                    module,
+                    obj: obj.into_boxed_slice(),
+                    unwind_info: unwind_info.into_boxed_slice(),
+                    data_initializers,
+                    funcs: funcs
+                        .into_iter()
+                        .map(|(_, func)| FunctionInfo {
+                            stack_maps: func.stack_maps,
+                            traps: func.traps,
+                            address_map: func.address_map,
+                        })
+                        .collect(),
+                    debug_info: compiler.tunables().debug_info,
                 })
-                .collect(),
-            debug_info: compiler.tunables().debug_info,
-        })
+            })
+            .collect::<Result<Vec<_>, SetupError>>()
     }
 }
 
 struct FinishedFunctions(PrimaryMap<DefinedFuncIndex, *mut [VMFunctionBody]>);
 
+#[derive(Serialize, Deserialize, Clone)]
+struct FunctionInfo {
+    traps: Vec<TrapInformation>,
+    address_map: FunctionAddressMap,
+    stack_maps: Vec<StackMapInformation>,
+}
+
 unsafe impl Send for FinishedFunctions {}
 unsafe impl Sync for FinishedFunctions {}
 
@@ -147,25 +154,24 @@ pub struct ModuleCode {
 
 /// A compiled wasm module, ready to be instantiated.
 pub struct CompiledModule {
+    artifacts: CompilationArtifacts,
     module: Arc<Module>,
     code: Arc<ModuleCode>,
     finished_functions: FinishedFunctions,
     trampolines: PrimaryMap<SignatureIndex, VMTrampoline>,
-    data_initializers: Box<[OwnedDataInitializer]>,
-    funcs: PrimaryMap<DefinedFuncIndex, FunctionInfo>,
-    obj: Box<[u8]>,
-    unwind_info: Box<[ObjectUnwindInfo]>,
 }
 
 impl CompiledModule {
-    /// Compile a data buffer into a `CompiledModule`, which may then be instantiated.
-    pub fn new<'data>(
-        compiler: &Compiler,
-        data: &'data [u8],
+    /// Creates a list of compiled modules from the given list of compilation
+    /// artifacts.
+    pub fn from_artifacts_list(
+        artifacts: Vec<CompilationArtifacts>,
+        isa: &dyn TargetIsa,
         profiler: &dyn ProfilingAgent,
-    ) -> Result<Self, SetupError> {
-        let artifacts = CompilationArtifacts::build(compiler, data)?;
-        Self::from_artifacts(artifacts, compiler.isa(), profiler)
+    ) -> Result<Vec<Self>, SetupError> {
+        maybe_parallel!(artifacts.(into_iter | into_par_iter))
+            .map(|a| CompiledModule::from_artifacts(a, isa, profiler))
+            .collect()
     }
 
     /// Creates `CompiledModule` directly from `CompilationArtifacts`.
@@ -174,67 +180,51 @@ impl CompiledModule {
         isa: &dyn TargetIsa,
         profiler: &dyn ProfilingAgent,
     ) -> Result<Self, SetupError> {
-        let CompilationArtifacts {
-            module,
-            obj,
-            unwind_info,
-            data_initializers,
-            funcs,
-            debug_info,
-        } = artifacts;
-
         // Allocate all of the compiled functions into executable memory,
         // copying over their contents.
-        let (code_memory, code_range, finished_functions, trampolines) =
-            build_code_memory(isa, &obj, &module, &unwind_info).map_err(|message| {
-                SetupError::Instantiate(InstantiationError::Resource(format!(
-                    "failed to build code memory for functions: {}",
-                    message
-                )))
-            })?;
+        let (code_memory, code_range, finished_functions, trampolines) = build_code_memory(
+            isa,
+            &artifacts.obj,
+            &artifacts.module,
+            &artifacts.unwind_info,
+        )
+        .map_err(|message| {
+            SetupError::Instantiate(InstantiationError::Resource(format!(
+                "failed to build code memory for functions: {}",
+                message
+            )))
+        })?;
 
         // Register GDB JIT images; initialize profiler and load the wasm module.
-        let dbg_jit_registration = if debug_info {
-            let bytes = create_dbg_image(obj.to_vec(), code_range, &module, &finished_functions)?;
-
-            profiler.module_load(&module, &finished_functions, Some(&bytes));
-
+        let dbg_jit_registration = if artifacts.debug_info {
+            let bytes = create_dbg_image(
+                artifacts.obj.to_vec(),
+                code_range,
+                &artifacts.module,
+                &finished_functions,
+            )?;
+            profiler.module_load(&artifacts.module, &finished_functions, Some(&bytes));
             let reg = GdbJitImageRegistration::register(bytes);
             Some(reg)
         } else {
-            profiler.module_load(&module, &finished_functions, None);
+            profiler.module_load(&artifacts.module, &finished_functions, None);
             None
         };
 
         let finished_functions = FinishedFunctions(finished_functions);
 
         Ok(Self {
-            module: Arc::new(module),
+            module: Arc::new(artifacts.module.clone()),
+            artifacts,
             code: Arc::new(ModuleCode {
                 code_memory,
                 dbg_jit_registration,
             }),
             finished_functions,
             trampolines,
-            data_initializers,
-            funcs,
-            obj,
-            unwind_info,
         })
     }
 
-    /// Extracts `CompilationArtifacts` from the compiled module.
-    pub fn to_compilation_artifacts(&self) -> CompilationArtifacts {
-        CompilationArtifacts {
-            module: (*self.module).clone(),
-            obj: self.obj.clone(),
-            unwind_info: self.unwind_info.clone(),
-            data_initializers: self.data_initializers.clone(),
-            funcs: self.funcs.clone(),
-            debug_info: self.code.dbg_jit_registration.is_some(),
-        }
-    }
-
     /// Crate an `Instance` from this `CompiledModule`.
     ///
     /// Note that if only one instance of this module is needed, it may be more
@@ -267,10 +257,15 @@ impl CompiledModule {
             stack_map_registry,
         )
     }
+    /// Extracts `CompilationArtifacts` from the compiled module.
+    pub fn compilation_artifacts(&self) -> &CompilationArtifacts {
+        &self.artifacts
+    }
 
     /// Returns data initializers to pass to `InstanceHandle::initialize`
     pub fn data_initializers(&self) -> Vec<DataInitializer<'_>> {
-        self.data_initializers
+        self.artifacts
+            .data_initializers
             .iter()
             .map(|init| DataInitializer {
                 location: init.location.clone(),
@@ -307,10 +302,12 @@ impl CompiledModule {
     pub fn stack_maps(
         &self,
     ) -> impl Iterator<Item = (*mut [VMFunctionBody], &[StackMapInformation])> {
-        self.finished_functions()
-            .values()
-            .copied()
-            .zip(self.funcs.values().map(|f| f.stack_maps.as_slice()))
+        self.finished_functions().values().copied().zip(
+            self.artifacts
+                .funcs
+                .values()
+                .map(|f| f.stack_maps.as_slice()),
+        )
     }
 
     /// Iterates over all functions in this module, returning information about
@@ -327,7 +324,7 @@ impl CompiledModule {
     > {
         self.finished_functions()
             .iter()
-            .zip(self.funcs.values())
+            .zip(self.artifacts.funcs.values())
             .map(|((i, alloc), func)| (i, *alloc, func.traps.as_slice(), &func.address_map))
     }
 
diff --git a/crates/jit/src/lib.rs b/crates/jit/src/lib.rs
index 28c1d701c..faa3e8150 100644
--- a/crates/jit/src/lib.rs
+++ b/crates/jit/src/lib.rs
@@ -21,6 +21,20 @@
     )
 )]
 
+#[cfg(feature = "parallel-compilation")]
+macro_rules! maybe_parallel {
+    ($e:ident.($serial:ident | $parallel:ident)) => {
+        $e.$parallel()
+    };
+}
+
+#[cfg(not(feature = "parallel-compilation"))]
+macro_rules! maybe_parallel {
+    ($e:ident.($serial:ident | $parallel:ident)) => {
+        $e.$serial()
+    };
+}
+
 mod code_memory;
 mod compiler;
 mod instantiate;
diff --git a/crates/lightbeam/Cargo.toml b/crates/lightbeam/Cargo.toml
index 2811cd21b..c8a8dac61 100644
--- a/crates/lightbeam/Cargo.toml
+++ b/crates/lightbeam/Cargo.toml
@@ -11,17 +11,17 @@ keywords = ["webassembly", "wasm", "compile", "compiler", "jit"]
 edition = "2018"
 
 [dependencies]
-capstone = "0.6.0"
+arrayvec = "0.5"
+capstone = "0.7.0"
 cranelift-codegen = { path = "../../cranelift/codegen", version = "0.68.0" }
 derive_more = "0.99"
-dynasm = "0.5.2"
-dynasmrt = "0.5.2"
+dynasm = "1.0.0"
+dynasmrt = "1.0.0"
 iter-enum = "0.2"
 itertools = "0.9.0"
 memoffset = "0.6.0"
 more-asserts = "0.2.1"
 smallvec = "1.0.0"
-staticvec = "0.10"
 thiserror = "1.0.9"
 typemap = "0.3"
 wasmparser = "0.65.0"
diff --git a/crates/lightbeam/src/disassemble.rs b/crates/lightbeam/src/disassemble.rs
index 0b07b8e6f..07d808803 100644
--- a/crates/lightbeam/src/disassemble.rs
+++ b/crates/lightbeam/src/disassemble.rs
@@ -2,6 +2,7 @@ use capstone::prelude::*;
 use dynasmrt::AssemblyOffset;
 use std::error::Error;
 use std::fmt::{Display, Write};
+use std::io;
 
 pub fn disassemble<D: Display>(
     mem: &[u8],
@@ -10,10 +11,11 @@ pub fn disassemble<D: Display>(
     let cs = Capstone::new()
         .x86()
         .mode(arch::x86::ArchMode::Mode64)
-        .build()?;
+        .build()
+        .map_err(map_caperr)?;
 
     println!("{} bytes:", mem.len());
-    let insns = cs.disasm_all(&mem, 0x0)?;
+    let insns = cs.disasm_all(&mem, 0x0).map_err(map_caperr)?;
     for i in insns.iter() {
         let mut line = String::new();
 
@@ -49,3 +51,7 @@ pub fn disassemble<D: Display>(
 
     Ok(())
 }
+
+fn map_caperr(err: capstone::Error) -> Box<dyn Error> {
+    Box::new(io::Error::new(io::ErrorKind::Other, err.to_string()))
+}
diff --git a/crates/lightbeam/src/lib.rs b/crates/lightbeam/src/lib.rs
index 43eed4dc8..374f737aa 100644
--- a/crates/lightbeam/src/lib.rs
+++ b/crates/lightbeam/src/lib.rs
@@ -1,5 +1,4 @@
 #![cfg_attr(test, feature(test))]
-#![feature(proc_macro_hygiene)]
 
 #[cfg(test)]
 extern crate test;
diff --git a/crates/lightbeam/src/microwasm.rs b/crates/lightbeam/src/microwasm.rs
index 99b8b04a0..af20a1a3e 100644
--- a/crates/lightbeam/src/microwasm.rs
+++ b/crates/lightbeam/src/microwasm.rs
@@ -1569,9 +1569,17 @@ where
     fn next(
         &mut self,
     ) -> Result<Option<impl ExactSizeIterator<Item = OperatorFromWasm> + '_>, Error> {
+        use arrayvec::ArrayVec;
         use derive_more::From;
         use iter_enum::{ExactSizeIterator, Iterator};
-        use staticvec::{staticvec, StaticVec, StaticVecIntoIter};
+
+        macro_rules! vec {
+            ($($a:expr),* $(,)?) => {{
+                let mut a = ArrayVec::new();
+                $(a.push($a);)*
+                vec(a)
+            }};
+        }
 
         struct Consts {
             inner: <Vec<Value> as IntoIterator>::IntoIter,
@@ -1601,13 +1609,13 @@ where
             Output::Consts(impl_trait_hack(consts))
         }
 
-        fn vec(vals: impl Into<StaticVec<OperatorFromWasm, 5>>) -> Output {
-            vals.into().into_iter().into()
+        fn vec(vals: ArrayVec<[OperatorFromWasm; 5]>) -> Output {
+            vals.into_iter().into()
         }
 
         fn iter(vals: impl IntoIterator<Item = OperatorFromWasm>) -> Output {
             let mut vals = vals.into_iter();
-            let v = StaticVec::from_iter(vals.by_ref());
+            let v = ArrayVec::from_iter(vals.by_ref());
             if let Some(next) = vals.next() {
                 let mut v = Vec::from_iter(v);
                 v.push(next);
@@ -1629,7 +1637,7 @@ where
         #[derive(From, Iterator, ExactSizeIterator)]
         enum Output {
             Consts(Consts),
-            FixedLength(StaticVecIntoIter<OperatorFromWasm, 5>),
+            FixedLength(arrayvec::IntoIter<[OperatorFromWasm; 5]>),
             VariableLength(std::vec::IntoIter<OperatorFromWasm>),
             None(std::iter::Empty<OperatorFromWasm>),
             One(std::iter::Once<OperatorFromWasm>),
@@ -1718,13 +1726,13 @@ where
                                 has_else: false, ..
                             } = block.kind
                             {
-                                break vec([
+                                break vec![
                                     Operator::Label((block.id, NameTag::Else)),
                                     Operator::Br {
                                         target: BrTarget::Label(end_label),
                                     },
                                     Operator::Label(end_label),
-                                ]);
+                                ];
                             } else {
                                 break one(Operator::Label((block.id, NameTag::End)));
                             }
@@ -1788,14 +1796,14 @@ where
                 let block_param_type_wasm = self.block_params_with_wasm_type(ty)?;
                 let label = (id, NameTag::Header);
 
-                vec([
+                vec![
                     Operator::loop_(self.block_params(), label),
                     Operator::end(block_param_type_wasm.collect(), (id, NameTag::End)),
                     Operator::Br {
                         target: BrTarget::Label(label),
                     },
                     Operator::Label(label),
-                ])
+                ]
             }
             WasmOperator::If { ty } => {
                 let id = self.next_id();
@@ -1814,7 +1822,7 @@ where
                     (id, NameTag::Else),
                     (id, NameTag::End),
                 );
-                vec([
+                vec![
                     Operator::block(self.block_params(), then),
                     Operator::block(self.block_params(), else_),
                     Operator::end(block_param_type_wasm.collect(), end),
@@ -1823,7 +1831,7 @@ where
                         else_: BrTarget::Label(else_).into(),
                     },
                     Operator::Label(then),
-                ])
+                ]
             }
             WasmOperator::Else => {
                 let block = self
@@ -1844,12 +1852,15 @@ where
 
                 let label = (block.id, NameTag::Else);
 
-                iter(to_drop.into_iter().map(Operator::Drop).chain(staticvec![
-                    Operator::Br {
-                        target: BrTarget::Label((block.id, NameTag::End)),
-                    },
-                    Operator::Label(label)
-                ]))
+                iter(
+                    to_drop
+                        .into_iter()
+                        .map(Operator::Drop)
+                        .chain(Some(Operator::Br {
+                            target: BrTarget::Label((block.id, NameTag::End)),
+                        }))
+                        .chain(Some(Operator::Label(label))),
+                )
             }
             WasmOperator::End => {
                 let block = self
@@ -1869,16 +1880,19 @@ where
                     let else_ = (block.id, NameTag::Else);
                     let end = (block.id, NameTag::End);
 
-                    iter(to_drop.map(Operator::Drop).into_iter().chain(staticvec![
-                        Operator::Br {
-                            target: BrTarget::Label(end),
-                        },
-                        Operator::Label(else_),
-                        Operator::Br {
-                            target: BrTarget::Label(end),
-                        },
-                        Operator::Label(end),
-                    ]))
+                    iter(
+                        to_drop
+                            .map(Operator::Drop)
+                            .into_iter()
+                            .chain(Some(Operator::Br {
+                                target: BrTarget::Label(end),
+                            }))
+                            .chain(Some(Operator::Label(else_)))
+                            .chain(Some(Operator::Br {
+                                target: BrTarget::Label(end),
+                            }))
+                            .chain(Some(Operator::Label(end))),
+                    )
                 } else {
                     if self.control_frames.is_empty() {
                         self.is_done = true;
@@ -1889,12 +1903,15 @@ where
                     } else if block.needs_end_label() {
                         let label = (block.id, NameTag::End);
 
-                        iter(to_drop.map(Operator::Drop).into_iter().chain(staticvec![
-                            Operator::Br {
-                                target: BrTarget::Label(label),
-                            },
-                            Operator::Label(label)
-                        ]))
+                        iter(
+                            to_drop
+                                .map(Operator::Drop)
+                                .into_iter()
+                                .chain(Some(Operator::Br {
+                                    target: BrTarget::Label(label),
+                                }))
+                                .chain(Some(Operator::Label(label))),
+                        )
                     } else {
                         iter(to_drop.map(Operator::Drop).into_iter())
                     }
@@ -1923,7 +1940,7 @@ where
                 let block = &mut self.control_frames[relative_depth as _];
                 block.mark_branched_to();
 
-                vec([
+                vec![
                     Operator::block(params, label),
                     Operator::BrIf {
                         then: BrTargetDrop {
@@ -1933,7 +1950,7 @@ where
                         else_: BrTarget::Label(label).into(),
                     },
                     Operator::Label(label),
-                ])
+                ]
             }
             WasmOperator::BrTable { table } => {
                 self.unreachable = true;
@@ -2007,7 +2024,7 @@ where
                 let depth = depth
                     .try_into()
                     .map_err(|_| Error::Microwasm("LocalSet - Local out of range".into()))?;
-                vec([Operator::Swap(depth), Operator::Drop(0..=0)])
+                vec![Operator::Swap(depth), Operator::Drop(0..=0)]
             }
             WasmOperator::LocalTee { local_index } => {
                 let depth = self
@@ -2017,11 +2034,11 @@ where
                 let depth = depth
                     .try_into()
                     .map_err(|_| Error::Microwasm("LocalTee - Local out of range".into()))?;
-                vec([
+                vec![
                     Operator::Pick(0),
                     Operator::Swap(depth),
                     Operator::Drop(0..=0),
-                ])
+                ]
             }
             WasmOperator::GlobalGet { global_index } => one(Operator::GlobalGet(global_index)),
             WasmOperator::GlobalSet { global_index } => one(Operator::GlobalSet(global_index)),
diff --git a/crates/lightbeam/wasmtime/src/lib.rs b/crates/lightbeam/wasmtime/src/lib.rs
index 50309f6c6..a1e67c627 100644
--- a/crates/lightbeam/wasmtime/src/lib.rs
+++ b/crates/lightbeam/wasmtime/src/lib.rs
@@ -14,7 +14,7 @@ use wasmtime_environ::wasm::{
 use wasmtime_environ::{
     entity::PrimaryMap, BuiltinFunctionIndex, CompileError, CompiledFunction, Compiler,
     FunctionBodyData, Module, ModuleTranslation, Relocation, RelocationTarget, TrapInformation,
-    VMOffsets,
+    Tunables, VMOffsets,
 };
 
 /// A compiler that compiles a WebAssembly module with Lightbeam, directly translating the Wasm file.
@@ -27,8 +27,9 @@ impl Compiler for Lightbeam {
         i: DefinedFuncIndex,
         function_body: FunctionBodyData<'_>,
         isa: &dyn isa::TargetIsa,
+        tunables: &Tunables,
     ) -> Result<CompiledFunction, CompileError> {
-        if translation.tunables.debug_info {
+        if tunables.debug_info {
             return Err(CompileError::DebugInfoNotSupported);
         }
         let func_index = translation.module.func_index(i);
diff --git a/crates/wasmtime/src/module.rs b/crates/wasmtime/src/module.rs
index 1b4967dfd..9da0181a8 100644
--- a/crates/wasmtime/src/module.rs
+++ b/crates/wasmtime/src/module.rs
@@ -1,8 +1,9 @@
 use crate::frame_info::GlobalFrameInfoRegistration;
-use crate::runtime::{Config, Engine};
 use crate::types::{EntityType, ExportType, ExternType, ImportType};
+use crate::Engine;
 use anyhow::{bail, Context, Result};
 use bincode::Options;
+use std::hash::Hash;
 use std::path::Path;
 use std::sync::{Arc, Mutex};
 use wasmparser::Validator;
@@ -81,7 +82,8 @@ use wasmtime_jit::{CompilationArtifacts, CompiledModule};
 #[derive(Clone)]
 pub struct Module {
     engine: Engine,
-    compiled: Arc<CompiledModule>,
+    compiled: Arc<[CompiledModule]>,
+    index: usize,
     frame_info_registration: Arc<Mutex<Option<Option<Arc<GlobalFrameInfoRegistration>>>>>,
 }
 
@@ -164,8 +166,7 @@ impl Module {
     /// See [`Module::new`] for other details.
     pub fn new_with_name(engine: &Engine, bytes: impl AsRef<[u8]>, name: &str) -> Result<Module> {
         let mut module = Module::new(engine, bytes.as_ref())?;
-        Arc::get_mut(&mut module.compiled)
-            .unwrap()
+        Arc::get_mut(&mut module.compiled).unwrap()[module.index]
             .module_mut()
             .expect("mutable module")
             .name = Some(name.to_string());
@@ -248,7 +249,7 @@ impl Module {
         #[cfg(not(feature = "cache"))]
         let artifacts = CompilationArtifacts::build(engine.compiler(), binary)?;
 
-        let compiled = CompiledModule::from_artifacts(
+        let compiled = CompiledModule::from_artifacts_list(
             artifacts,
             engine.compiler().isa(),
             &*engine.config().profiler,
@@ -256,7 +257,8 @@ impl Module {
 
         Ok(Module {
             engine: engine.clone(),
-            compiled: Arc::new(compiled),
+            index: compiled.len() - 1,
+            compiled: compiled.into(),
             frame_info_registration: Arc::new(Mutex::new(None)),
         })
     }
@@ -290,8 +292,12 @@ impl Module {
     /// Serialize compilation artifacts to the buffer. See also `deseriaize`.
     pub fn serialize(&self) -> Result<Vec<u8>> {
         let artifacts = (
-            compiler_fingerprint(self.engine.config()),
-            self.compiled.to_compilation_artifacts(),
+            compiler_fingerprint(&self.engine),
+            self.compiled
+                .iter()
+                .map(|i| i.compilation_artifacts())
+                .collect::<Vec<_>>(),
+            self.index,
         );
 
         let buffer = bincode_options().serialize(&artifacts)?;
@@ -308,16 +314,16 @@ impl Module {
     /// for modifications or curruptions. All responsibily of signing and its
     /// verification falls on the embedder.
     pub fn deserialize(engine: &Engine, serialized: &[u8]) -> Result<Module> {
-        let expected_fingerprint = compiler_fingerprint(engine.config());
+        let expected_fingerprint = compiler_fingerprint(engine);
 
-        let (fingerprint, artifacts) = bincode_options()
-            .deserialize::<(u64, CompilationArtifacts)>(serialized)
+        let (fingerprint, artifacts, index) = bincode_options()
+            .deserialize::<(u64, _, _)>(serialized)
             .context("Deserialize compilation artifacts")?;
         if fingerprint != expected_fingerprint {
             bail!("Incompatible compilation artifact");
         }
 
-        let compiled = CompiledModule::from_artifacts(
+        let compiled = CompiledModule::from_artifacts_list(
             artifacts,
             engine.compiler().isa(),
             &*engine.config().profiler,
@@ -325,13 +331,14 @@ impl Module {
 
         Ok(Module {
             engine: engine.clone(),
-            compiled: Arc::new(compiled),
+            index,
+            compiled: compiled.into(),
             frame_info_registration: Arc::new(Mutex::new(None)),
         })
     }
 
     pub(crate) fn compiled_module(&self) -> &CompiledModule {
-        &self.compiled
+        &self.compiled[self.index]
     }
 
     /// Returns identifier/name that this [`Module`] has. This name
@@ -359,7 +366,7 @@ impl Module {
     /// # }
     /// ```
     pub fn name(&self) -> Option<&str> {
-        self.compiled.module().name.as_deref()
+        self.compiled_module().module().name.as_deref()
     }
 
     /// Returns the list of imports that this [`Module`] has and must be
@@ -414,7 +421,7 @@ impl Module {
     pub fn imports<'module>(
         &'module self,
     ) -> impl ExactSizeIterator<Item = ImportType<'module>> + 'module {
-        let module = self.compiled.module();
+        let module = self.compiled_module().module();
         module
             .imports
             .iter()
@@ -481,7 +488,7 @@ impl Module {
     pub fn exports<'module>(
         &'module self,
     ) -> impl ExactSizeIterator<Item = ExportType<'module>> + 'module {
-        let module = self.compiled.module();
+        let module = self.compiled_module().module();
         module.exports.iter().map(move |(name, entity_index)| {
             let r#type = EntityType::new(entity_index, module);
             ExportType::new(name, r#type)
@@ -532,7 +539,7 @@ impl Module {
     /// # }
     /// ```
     pub fn get_export<'module>(&'module self, name: &'module str) -> Option<ExternType> {
-        let module = self.compiled.module();
+        let module = self.compiled_module().module();
         let entity_index = module.exports.get(name)?;
         Some(EntityType::new(entity_index, module).extern_type())
     }
@@ -550,7 +557,7 @@ impl Module {
         if let Some(info) = &*info {
             return info.clone();
         }
-        let ret = super::frame_info::register(&self.compiled).map(Arc::new);
+        let ret = super::frame_info::register(self.compiled_module()).map(Arc::new);
         *info = Some(ret.clone());
         return ret;
     }
@@ -567,10 +574,10 @@ fn bincode_options() -> impl Options {
     bincode::DefaultOptions::new().with_varint_encoding()
 }
 
-fn compiler_fingerprint(config: &Config) -> u64 {
+fn compiler_fingerprint(engine: &Engine) -> u64 {
     use std::hash::Hasher;
     let mut hasher = std::collections::hash_map::DefaultHasher::new();
-    config.compiler_fingerprint(&mut hasher);
+    engine.compiler().hash(&mut hasher);
     hasher.finish()
 }
 
diff --git a/crates/wasmtime/src/runtime.rs b/crates/wasmtime/src/runtime.rs
index d17238eba..2697c3db0 100644
--- a/crates/wasmtime/src/runtime.rs
+++ b/crates/wasmtime/src/runtime.rs
@@ -12,7 +12,6 @@ use std::hash::{Hash, Hasher};
 use std::path::Path;
 use std::rc::{Rc, Weak};
 use std::sync::Arc;
-use target_lexicon::Triple;
 use wasmparser::WasmFeatures;
 #[cfg(feature = "cache")]
 use wasmtime_cache::CacheConfig;
@@ -257,6 +256,20 @@ impl Config {
         self
     }
 
+    /// Configures whether the WebAssembly module linking [proposal] will
+    /// be enabled for compilation.
+    ///
+    /// Note that development of this feature is still underway, so enabling
+    /// this is likely to be full of bugs.
+    ///
+    /// This is `false` by default.
+    ///
+    /// [proposal]: https://github.com/webassembly/module-linking
+    pub fn wasm_module_linking(&mut self, enable: bool) -> &mut Self {
+        self.features.module_linking = enable;
+        self
+    }
+
     /// Configures which compilation strategy will be used for wasm modules.
     ///
     /// This method can be used to configure which compiler is used for wasm
@@ -616,22 +629,6 @@ impl Config {
         let isa = self.target_isa();
         Compiler::new(isa, self.strategy, self.tunables.clone(), self.features)
     }
-
-    /// Hashes/fingerprints compiler setting to ensure that compatible
-    /// compilation artifacts are used.
-    pub(crate) fn compiler_fingerprint<H>(&self, state: &mut H)
-    where
-        H: Hasher,
-    {
-        self.flags.hash(state);
-        self.tunables.hash(state);
-
-        let triple = Triple::host();
-        triple.hash(state);
-
-        // Catch accidental bugs of reusing across wasmtime versions.
-        env!("CARGO_PKG_VERSION").hash(state);
-    }
 }
 
 fn round_up_to_pages(val: u64) -> u64 {
diff --git a/src/obj.rs b/src/obj.rs
index 48048e904..8e3ebc6b6 100644
--- a/src/obj.rs
+++ b/src/obj.rs
@@ -67,6 +67,7 @@ pub fn compile_to_obj(
     let mut translation = environ
         .translate(wasm)
         .context("failed to translate module")?;
-    let compilation = compiler.compile(&mut translation)?;
+    assert_eq!(translation.len(), 1);
+    let compilation = compiler.compile(&mut translation[0])?;
     Ok(compilation.obj)
 }


Test patch:
diff --git a/tests/all/iloop.rs b/tests/all/iloop.rs
index 23e6f85aa..dd41eec23 100644
--- a/tests/all/iloop.rs
+++ b/tests/all/iloop.rs
@@ -82,6 +82,7 @@ fn loop_interrupt_from_afar() -> anyhow::Result<()> {
         while HITS.load(SeqCst) <= 100_000 {
             // continue ...
         }
+        println!("interrupting");
         handle.interrupt();
     });
 
diff --git a/tests/all/main.rs b/tests/all/main.rs
index ff4c45229..414708144 100644
--- a/tests/all/main.rs
+++ b/tests/all/main.rs
@@ -12,6 +12,7 @@ mod instance;
 mod invoke_func_via_table;
 mod linker;
 mod memory_creator;
+mod module_linking;
 mod module_serialize;
 mod name;
 mod stack_overflow;
diff --git a/tests/all/module_linking.rs b/tests/all/module_linking.rs
new file mode 100644
index 000000000..61949c576
--- /dev/null
+++ b/tests/all/module_linking.rs
@@ -0,0 +1,46 @@
+use anyhow::Result;
+use wasmtime::*;
+
+fn engine() -> Engine {
+    let mut config = Config::new();
+    config.wasm_module_linking(true);
+    Engine::new(&config)
+}
+
+#[test]
+fn compile() -> Result<()> {
+    let engine = engine();
+    Module::new(&engine, "(module (module))")?;
+    Module::new(&engine, "(module (module) (module))")?;
+    Module::new(&engine, "(module (module (module)))")?;
+    Module::new(
+        &engine,
+        "
+            (module
+                (func)
+                (module (func))
+                (module (func))
+            )
+        ",
+    )?;
+    let m = Module::new(
+        &engine,
+        "
+            (module
+                (global i32 (i32.const 0))
+                (func)
+                (module (memory 1) (func))
+                (module (memory 2) (func))
+                (module (table 2 funcref) (func))
+                (module (global i64 (i64.const 0)) (func))
+            )
+        ",
+    )?;
+    assert_eq!(m.imports().len(), 0);
+    assert_eq!(m.exports().len(), 0);
+    let bytes = m.serialize()?;
+    Module::deserialize(&engine, &bytes)?;
+    assert_eq!(m.imports().len(), 0);
+    assert_eq!(m.exports().len(), 0);
+    Ok(())
+}