chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

2
vendor/wit-component/tests/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
!*.wasm
!*.wat

291
vendor/wit-component/tests/components.rs vendored Normal file
View File

@@ -0,0 +1,291 @@
use anyhow::{Context, Error, Result, bail};
use libtest_mimic::{Arguments, Trial};
use pretty_assertions::assert_eq;
use std::{borrow::Cow, fs, path::Path};
use wasm_encoder::{Encode, Section};
use wasm_metadata::{Metadata, Payload};
use wasmparser::{Parser, Validator, WasmFeatures};
use wit_component::{ComponentEncoder, DecodedWasm, Linker, StringEncoding, WitPrinter};
use wit_parser::{PackageId, Resolve, UnresolvedPackageGroup};
/// Tests the encoding of components.
///
/// This test looks in the `components/` directory for test cases.
///
/// The expected input files for a test case are:
///
/// * [required] `module.wat` *or* some combination of `lib-$name.wat` and
/// `dlopen-lib-$name.wat` - contains the core module definition(s) to be
/// encoded as a component. If one or more `lib-$name.wat` and/or
/// `dlopen-lib-$name.wat` files exist, they will be linked using `Linker`
/// such that the `lib-` ones are not `dlopen`-able but the `dlopen-lib-` ones
/// are.
/// * [required] `module.wit` *or* `lib-$name.wat` and `dlopen-lib-$name.wat`
/// corresponding to the WAT files above - WIT package(s) describing the
/// interfaces of the `module.wat` or `lib-$name.wat` and
/// `dlopen-lib-$name.wat` files. Must have a `default world`
/// * [optional] `adapt-$name.wat` - optional adapter for the module name
/// `$name`, can be specified for multiple `$name`s. Alternatively, if $name
/// doesn't work as part of a filename (e.g. contains forward slashes), it may
/// be specified on the first line of the file with the prefix `;; module name:
/// `, e.g. `;; module name: wasi:cli/environment@0.2.0`.
/// * [optional] `adapt-$name.wit` - required for each `*.wat` adapter to
/// describe imports/exports of the adapter.
/// * [optional] `stub-missing-functions` - if linking libraries and this file
/// exists, `Linker::stub_missing_functions` will be set to `true`. The
/// contents of the file are ignored.
/// * [optional] `use-built-in-libdl` - if linking libraries and this file
/// exists, `Linker::use_built_in_libdl` will be set to `true`. The contents
/// of the file are ignored.
///
/// And the output files are one of the following:
///
/// * `component.wat` - the expected encoded component in text format if the
/// encoding is expected to succeed.
/// * `component.wit` - if `component.wat` exists this is the inferred interface
/// of the component.
/// * `error.txt` - the expected error message if the encoding is expected to
/// fail.
///
/// The test encodes a component based on the input files. If the encoding
/// succeeds, it expects the output to match `component.wat`. If the encoding
/// fails, it expects the output to match `error.txt`.
///
/// Run the test with the environment variable `BLESS` set to update
/// either `component.wat` or `error.txt` depending on the outcome of the encoding.
fn main() -> Result<()> {
drop(env_logger::try_init());
let mut trials = Vec::new();
for entry in fs::read_dir("tests/components")? {
let path = entry?.path();
if !path.is_dir() {
continue;
}
trials.push(Trial::test(path.to_str().unwrap().to_string(), move || {
run_test(&path).map_err(|e| format!("{e:?}").into())
}));
}
let mut args = Arguments::from_args();
if cfg!(target_family = "wasm") && !cfg!(target_feature = "atomics") {
args.test_threads = Some(1);
}
libtest_mimic::run(&args, trials).exit();
}
fn run_test(path: &Path) -> Result<()> {
let test_case = path.file_stem().unwrap().to_str().unwrap();
let mut resolve = Resolve::default();
let (pkg_id, _) = resolve.push_dir(&path)?;
// If this test case contained multiple packages, create separate sub-directories for
// each.
let path = path.to_path_buf();
let module_path = path.join("module.wat");
let mut adapters = glob::glob(path.join("adapt-*.wat").to_str().unwrap())?;
let result = if module_path.is_file() {
let module = read_core_module(&module_path, &resolve, pkg_id)
.with_context(|| format!("failed to read core module at {module_path:?}"))?;
adapters
.try_fold(
ComponentEncoder::default()
.debug_names(true)
.module(&module)?,
|encoder, path| {
let (name, wasm) = read_name_and_module("adapt-", &path?, &resolve, pkg_id)?;
Ok::<_, Error>(encoder.adapter(&name, &wasm)?)
},
)?
.encode()
} else {
let mut libs = glob::glob(path.join("lib-*.wat").to_str().unwrap())?
.map(|path| Ok(("lib-", path?, false)))
.chain(
glob::glob(path.join("dlopen-lib-*.wat").to_str().unwrap())?
.map(|path| Ok(("dlopen-lib-", path?, true))),
)
.collect::<Result<Vec<_>>>()?;
// Sort list to ensure deterministic order, which determines priority in cases of duplicate symbols:
libs.sort_by(|(_, a, _), (_, b, _)| a.cmp(b));
let mut linker = Linker::default().validate(false).debug_names(true);
if path.join("stub-missing-functions").is_file() {
linker = linker.stub_missing_functions(true);
}
if path.join("use-built-in-libdl").is_file() {
linker = linker.use_built_in_libdl(true);
}
let linker = libs
.into_iter()
.try_fold(linker, |linker, (prefix, path, dl_openable)| {
let (name, wasm) = read_name_and_module(prefix, &path, &resolve, pkg_id)?;
Ok::<_, Error>(linker.library(&name, &wasm, dl_openable)?)
})?;
adapters
.try_fold(linker, |linker, path| {
let (name, wasm) = read_name_and_module("adapt-", &path?, &resolve, pkg_id)?;
Ok::<_, Error>(linker.adapter(&name, &wasm)?)
})?
.encode()
};
let component_path = path.join("component.wat");
let component_wit_path = path.join("component.wit.print");
let error_path = path.join("error.txt");
let bytes = match result {
Ok(bytes) => {
if test_case.starts_with("error-") {
bail!("expected an error but got success");
}
bytes
}
Err(err) => {
if !test_case.starts_with("error-") {
return Err(err);
}
assert_output(&format!("{err:#}"), &error_path)?;
return Ok(());
}
};
Validator::new_with_features(WasmFeatures::all())
.validate_all(&bytes)
.context("failed to validate component output")?;
let wat = wasmprinter::print_bytes(&bytes).context("failed to print bytes")?;
assert_output(&wat, &component_path)?;
let mut parser = Parser::new(0);
parser.set_features(WasmFeatures::all());
let (pkg, resolve) = match wit_component::decode_reader(bytes.as_slice())
.context("failed to decode resolve")?
{
DecodedWasm::WitPackage(..) => unreachable!(),
DecodedWasm::Component(resolve, world) => (resolve.worlds[world].package.unwrap(), resolve),
};
let mut printer = WitPrinter::default();
printer
.print(&resolve, pkg, &[])
.context("failed to print WIT")?;
let wit = printer.output.to_string();
assert_output(&wit, &component_wit_path)?;
UnresolvedPackageGroup::parse(&component_wit_path, &wit)
.context("failed to parse printed WIT")?;
// Check that the producer data got piped through properly
match Payload::from_binary(&bytes).unwrap() {
// Depends on the ComponentEncoder always putting the first module as the 0th child:
Payload::Component { children, .. } => match &children[0] {
Payload::Module(Metadata { producers, .. }) => {
let producers = producers.as_ref().expect("child module has producers");
let processed_by = producers
.get("processed-by")
.expect("child has processed-by section");
assert_eq!(
processed_by
.get("wit-component")
.expect("wit-component producer present"),
env!("CARGO_PKG_VERSION")
);
if module_path.is_file() {
assert_eq!(
processed_by
.get("my-fake-bindgen")
.expect("added bindgen field present"),
"123.45"
);
} else {
// Otherwise, we used `Linker`, which synthesizes the
// "main" module and thus won't have `my-fake-bindgen`
}
}
_ => panic!("expected child to be a module"),
},
_ => panic!("expected top level metadata of component"),
}
Ok(())
}
fn read_name_and_module(
prefix: &str,
path: &Path,
resolve: &Resolve,
pkg: PackageId,
) -> Result<(String, Vec<u8>)> {
let wasm = read_core_module(path, resolve, pkg)
.with_context(|| format!("failed to read core module at {path:?}"))?;
let stem = path.file_stem().unwrap().to_str().unwrap();
let name = if let Some(name) = fs::read_to_string(path)?
.lines()
.next()
.and_then(|line| line.strip_prefix(";; module name: "))
{
name.to_owned()
} else {
stem.trim_start_matches(prefix).to_owned()
};
Ok((name, wasm))
}
/// Parses the core wasm module at `path`, expected as a `*.wat` file.
///
/// The `resolve` and `pkg` are the parsed WIT package from this test's
/// directory and the `path`'s filename is used to find a WIT document of the
/// corresponding name which should have a world that `path` ascribes to.
fn read_core_module(path: &Path, resolve: &Resolve, pkg: PackageId) -> Result<Vec<u8>> {
let mut wasm = wat::parse_file(path)?;
let name = path.file_stem().and_then(|s| s.to_str()).unwrap();
let world = resolve
.select_world(&[pkg], Some(name))
.context("failed to select a world")?;
// Add this producer data to the wit-component metadata so we can make sure it gets through the
// translation:
let mut producers = wasm_metadata::Producers::empty();
producers.add("processed-by", "my-fake-bindgen", "123.45");
let encoded =
wit_component::metadata::encode(resolve, world, StringEncoding::UTF8, Some(&producers))?;
let section = wasm_encoder::CustomSection {
name: "component-type".into(),
data: Cow::Borrowed(&encoded),
};
wasm.push(section.id());
section.encode(&mut wasm);
Ok(wasm)
}
fn assert_output(contents: &str, path: &Path) -> Result<()> {
let contents = contents.replace("\r\n", "\n").replace(
concat!("\"", env!("CARGO_PKG_VERSION"), "\""),
"\"$CARGO_PKG_VERSION\"",
);
if std::env::var_os("BLESS").is_some() {
fs::write(path, contents)?;
} else {
match fs::read_to_string(path) {
Ok(expected) => {
assert_eq!(
expected.replace("\r\n", "\n").trim(),
contents.trim(),
"failed baseline comparison ({})",
path.display(),
);
}
Err(_) => {
panic!("expected {path:?} to contain\n{contents}");
}
}
}
Ok(())
}

View File

@@ -0,0 +1,3 @@
(module
(func (export "thunk"))
)

View File

@@ -0,0 +1,5 @@
world adapt-old {
import new: interface {
thunk-that-is-not-called: func();
}
}

View File

@@ -0,0 +1,60 @@
(component
(core module $main (;0;)
(type (;0;) (func))
(import "old" "thunk" (func (;0;) (type 0)))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func))
(export "thunk" (func 0))
(func (;0;) (type 0))
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func))
(table (;0;) 1 1 funcref)
(export "0" (func $adapt-old-thunk))
(export "$imports" (table 0))
(func $adapt-old-thunk (;0;) (type 0)
i32.const 0
call_indirect (type 0)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func))
(import "" "0" (func (;0;) (type 0)))
(import "" "$imports" (table (;0;) 1 1 funcref))
(elem (;0;) (i32.const 0) func 0)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-thunk (;0;)))
(core instance $old (;1;)
(export "thunk" (func $adapt-old-thunk))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(core instance $"#core-instance3 old" (@name "old") (;3;) (instantiate $wit-component:adapter:old))
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance3 old" "thunk" (core func $thunk (;1;)))
(core instance $fixup-args (;4;)
(export "$imports" (table $"shim table"))
(export "0" (func $thunk))
)
(core instance $fixup (;5;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,4 @@
package root:component;
world root {
}

View File

@@ -0,0 +1,3 @@
(module
(import "old" "thunk" (func))
)

View File

@@ -0,0 +1,2 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,4 @@
(module
(import "__main_module__" "the_entrypoint" (func $entry))
(export "entrypoint" (func $entry))
)

View File

@@ -0,0 +1,3 @@
world adapt-old {
export entrypoint: func();
}

View File

@@ -0,0 +1,32 @@
(component
(core module $main (;0;)
(type (;0;) (func))
(export "the_entrypoint" (func 0))
(func (;0;) (type 0))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func))
(import "__main_module__" "the_entrypoint" (func $entry (;0;) (type 0)))
(export "entrypoint" (func $entry))
)
(core instance $main (;0;) (instantiate $main))
(alias core export $main "the_entrypoint" (core func $the_entrypoint (;0;)))
(core instance $__main_module__ (;1;)
(export "the_entrypoint" (func $the_entrypoint))
)
(core instance $old (;2;) (instantiate $wit-component:adapter:old
(with "__main_module__" (instance $__main_module__))
)
)
(type (;0;) (func))
(alias core export $old "entrypoint" (core func $entrypoint (;1;)))
(func $entrypoint (;0;) (type 0) (canon lift (core func $entrypoint)))
(export $"#func1 entrypoint" (@name "entrypoint") (;1;) "entrypoint" (func $entrypoint))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,5 @@
package root:component;
world root {
export entrypoint: func();
}

View File

@@ -0,0 +1,3 @@
(module
(func (export "the_entrypoint"))
)

View File

@@ -0,0 +1,2 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,4 @@
(module
(import "__main_module__" "the_entrypoint" (func $entry))
(export "foo:foo/new#entrypoint" (func $entry))
)

View File

@@ -0,0 +1,7 @@
interface new {
entrypoint: func();
}
world adapt-old {
export new;
}

View File

@@ -0,0 +1,42 @@
(component
(core module $main (;0;)
(type (;0;) (func))
(export "the_entrypoint" (func 0))
(func (;0;) (type 0))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func))
(import "__main_module__" "the_entrypoint" (func $entry (;0;) (type 0)))
(export "foo:foo/new#entrypoint" (func $entry))
)
(core instance $main (;0;) (instantiate $main))
(alias core export $main "the_entrypoint" (core func $the_entrypoint (;0;)))
(core instance $__main_module__ (;1;)
(export "the_entrypoint" (func $the_entrypoint))
)
(core instance $old (;2;) (instantiate $wit-component:adapter:old
(with "__main_module__" (instance $__main_module__))
)
)
(type (;0;) (func))
(alias core export $old "foo:foo/new#entrypoint" (core func $foo:foo/new#entrypoint (;1;)))
(func $entrypoint (;0;) (type 0) (canon lift (core func $foo:foo/new#entrypoint)))
(component $foo:foo/new-shim-component (;0;)
(type (;0;) (func))
(import "import-func-entrypoint" (func (;0;) (type 0)))
(type (;1;) (func))
(export (;1;) "entrypoint" (func 0) (func (type 1)))
)
(instance $foo:foo/new-shim-instance (;0;) (instantiate $foo:foo/new-shim-component
(with "import-func-entrypoint" (func $entrypoint))
)
)
(export $foo:foo/new (;1;) "foo:foo/new" (instance $foo:foo/new-shim-instance))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,5 @@
package root:component;
world root {
export foo:foo/new;
}

View File

@@ -0,0 +1,3 @@
(module
(func (export "the_entrypoint"))
)

View File

@@ -0,0 +1,3 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,47 @@
(module
(import "__main_module__" "main" (func $main (param i32 i32)))
(import "new" "read" (func $read (param i32 i32)))
(global $sp (mut i32) (i32.const 0))
(func $start
(global.set $sp
(i32.mul
(memory.grow (i32.const 1))
(i32.const 65536)))
)
(func (export "entrypoint") (param i32 i32)
unreachable
)
(func (export "cabi_export_realloc") (param i32 i32 i32 i32) (result i32)
unreachable
)
(func (export "read") (param $ptr i32) (param $len i32)
(local $fp i32)
(global.set $sp
(local.tee $fp
(i32.sub
(global.get $sp)
(i32.const 8)
)
)
)
(call $read (local.get $len) (local.get $fp))
(global.set $sp
(i32.add
(local.get $fp)
(i32.const 8)
)
)
)
(func (export "cabi_import_realloc") (param i32 i32 i32 i32) (result i32)
unreachable
)
)

View File

@@ -0,0 +1,6 @@
world adapt-old {
import new: interface {
read: func(amt: u32) -> list<u8>;
}
export entrypoint: func(args: list<string>);
}

View File

@@ -0,0 +1,131 @@
(component
(type $ty-new (;0;)
(instance
(type (;0;) (list u8))
(type (;1;) (func (param "amt" u32) (result 0)))
(export (;0;) "read" (func (type 1)))
)
)
(import "new" (instance $new (;0;) (type $ty-new)))
(core module $main (;0;)
(type (;0;) (func (param i32 i32)))
(import "old" "read" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "main" (func 1))
(export "memory" (memory 0))
(func (;1;) (type 0) (param $args i32) (param $argv i32))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(import "new" "read" (func $read (;0;) (type 0)))
(global $sp (;0;) (mut i32) i32.const 0)
(export "entrypoint" (func 1))
(export "cabi_export_realloc" (func 2))
(export "read" (func 3))
(export "cabi_import_realloc" (func 4))
(func (;1;) (type 0) (param i32 i32)
unreachable
)
(func (;2;) (type 1) (param i32 i32 i32 i32) (result i32)
unreachable
)
(func (;3;) (type 0) (param i32 i32)
(local i32)
global.get $sp
i32.const 8
i32.sub
local.tee 2
global.set $sp
local.get 1
local.get 2
call $read
local.get 2
i32.const 8
i32.add
global.set $sp
)
(func (;4;) (type 1) (param i32 i32 i32 i32) (result i32)
unreachable
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32 i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-old-read))
(export "1" (func $indirect-new-read))
(export "$imports" (table 0))
(func $adapt-old-read (;0;) (type 0) (param i32 i32)
local.get 0
local.get 1
i32.const 0
call_indirect (type 0)
)
(func $indirect-new-read (;1;) (type 1) (param i32 i32)
local.get 0
local.get 1
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32 i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-read (;0;)))
(core instance $old (;1;)
(export "read" (func $adapt-old-read))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(alias core export $wit-component-shim-instance "1" (core func $indirect-new-read (;1;)))
(core instance $new (;3;)
(export "read" (func $indirect-new-read))
)
(core instance $"#core-instance4 old" (@name "old") (;4;) (instantiate $wit-component:adapter:old
(with "new" (instance $new))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance4 old" "read" (core func $read (;2;)))
(alias export $new "read" (func $read (;0;)))
(alias core export $"#core-instance4 old" "cabi_import_realloc" (core func $realloc (;3;)))
(core func $"#core-func4 indirect-new-read" (@name "indirect-new-read") (;4;) (canon lower (func $read) (memory $memory) (realloc $realloc)))
(core instance $fixup-args (;5;)
(export "$imports" (table $"shim table"))
(export "0" (func $read))
(export "1" (func $"#core-func4 indirect-new-read"))
)
(core instance $fixup (;6;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(type (;1;) (list string))
(type (;2;) (func (param "args" 1)))
(alias core export $"#core-instance4 old" "entrypoint" (core func $entrypoint (;5;)))
(alias core export $"#core-instance4 old" "cabi_export_realloc" (core func $cabi_export_realloc (;6;)))
(func $entrypoint (;1;) (type 2) (canon lift (core func $entrypoint) (memory $memory) (realloc $cabi_export_realloc) string-encoding=utf8))
(export $"#func2 entrypoint" (@name "entrypoint") (;2;) "entrypoint" (func $entrypoint))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,9 @@
package root:component;
world root {
import new: interface {
read: func(amt: u32) -> list<u8>;
}
export entrypoint: func(args: list<string>);
}

View File

@@ -0,0 +1,8 @@
(module
(import "old" "read" (func (param i32 i32)))
(func (export "main") (param $args i32) (param $argv i32)
;; ...
)
(memory (export "memory") 1)
)

View File

@@ -0,0 +1,3 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,13 @@
(module
(import "__main_module__" "the_entrypoint" (func $entry))
(global $nargs (mut i32) (i32.const 0))
(func (export "entrypoint") (param $nargs i32)
(global.set $nargs (local.get $nargs))
call $entry
)
(func (export "nargs") (result i32)
global.get $nargs)
)

View File

@@ -0,0 +1,3 @@
world adapt-old {
export entrypoint: func(nargs: u32);
}

View File

@@ -0,0 +1,86 @@
(component
(core module $main (;0;)
(type (;0;) (func (result i32)))
(type (;1;) (func))
(import "old" "nargs" (func (;0;) (type 0)))
(export "the_entrypoint" (func 1))
(func (;1;) (type 1))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func))
(type (;1;) (func (param i32)))
(type (;2;) (func (result i32)))
(import "__main_module__" "the_entrypoint" (func $entry (;0;) (type 0)))
(global $nargs (;0;) (mut i32) i32.const 0)
(export "entrypoint" (func 1))
(export "nargs" (func 2))
(func (;1;) (type 1) (param i32)
local.get 0
global.set $nargs
call $entry
)
(func (;2;) (type 2) (result i32)
global.get $nargs
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (result i32)))
(table (;0;) 1 1 funcref)
(export "0" (func $adapt-old-nargs))
(export "$imports" (table 0))
(func $adapt-old-nargs (;0;) (type 0) (result i32)
i32.const 0
call_indirect (type 0)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (result i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "$imports" (table (;0;) 1 1 funcref))
(elem (;0;) (i32.const 0) func 0)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-nargs (;0;)))
(core instance $old (;1;)
(export "nargs" (func $adapt-old-nargs))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "the_entrypoint" (core func $the_entrypoint (;1;)))
(core instance $__main_module__ (;3;)
(export "the_entrypoint" (func $the_entrypoint))
)
(core instance $"#core-instance4 old" (@name "old") (;4;) (instantiate $wit-component:adapter:old
(with "__main_module__" (instance $__main_module__))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance4 old" "nargs" (core func $nargs (;2;)))
(core instance $fixup-args (;5;)
(export "$imports" (table $"shim table"))
(export "0" (func $nargs))
)
(core instance $fixup (;6;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(type (;0;) (func (param "nargs" u32)))
(alias core export $"#core-instance4 old" "entrypoint" (core func $entrypoint (;3;)))
(func $entrypoint (;0;) (type 0) (canon lift (core func $entrypoint)))
(export $"#func1 entrypoint" (@name "entrypoint") (;1;) "entrypoint" (func $entrypoint))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,5 @@
package root:component;
world root {
export entrypoint: func(nargs: u32);
}

View File

@@ -0,0 +1,4 @@
(module
(import "old" "nargs" (func (result i32)))
(func (export "the_entrypoint"))
)

View File

@@ -0,0 +1,2 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,33 @@
;; This example represents adapting modules which use an early version of the
;; canonical ABI, back when `cabi_realloc` was named `canonical_abi_realloc` and
;; had a friend named `canonical_abi_free`. Such modules are pretty easy to
;; adapt since the adapter can use the main module's allocator for both lowering
;; and post-return functions.
;;
;; See https://github.com/fermyon/spin-componentize for a real-world example.
(module
(import "__main_module__" "canonical_abi_realloc" (func $realloc (param i32 i32 i32 i32) (result i32)))
(import "__main_module__" "canonical_abi_free" (func $free (param i32 i32 i32)))
(import "env" "memory" (memory 0))
(global $__stack_pointer (mut i32) i32.const 0)
(global $allocation_state (mut i32) i32.const 0)
(func (export "foo:foo/new#foo") (result i32)
;; This is a dummy, non-working implementation, just to make gc.rs do what
;; we want, which is to treat this adapter as if it uses the main module's
;; allocator to allocate and free memory.
global.get $__stack_pointer
global.get $allocation_state
(call $realloc (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0))
unreachable
)
(func (export "cabi_post_foo:foo/new#foo") (param i32)
;; another dummy implementation
(call $free (i32.const 0) (i32.const 0) (i32.const 0))
unreachable
)
)

View File

@@ -0,0 +1,7 @@
interface new {
foo: func() -> string;
}
world adapt-old {
export new;
}

View File

@@ -0,0 +1,101 @@
(component
(core module $main (;0;)
(type (;0;) (func (param i32 i32 i32 i32) (result i32)))
(type (;1;) (func (param i32 i32 i32)))
(memory (;0;) 1)
(export "canonical_abi_realloc" (func 0))
(export "canonical_abi_free" (func 1))
(export "memory" (memory 0))
(func (;0;) (type 0) (param i32 i32 i32 i32) (result i32)
unreachable
)
(func (;1;) (type 1) (param i32 i32 i32)
unreachable
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32 i32 i32 i32) (result i32)))
(type (;1;) (func (param i32 i32 i32)))
(type (;2;) (func (result i32)))
(type (;3;) (func (param i32)))
(type (;4;) (func))
(import "__main_module__" "canonical_abi_realloc" (func $realloc (;0;) (type 0)))
(import "__main_module__" "canonical_abi_free" (func $free (;1;) (type 1)))
(global $__stack_pointer (;0;) (mut i32) i32.const 0)
(global $allocation_state (;1;) (mut i32) i32.const 0)
(export "foo:foo/new#foo" (func 2))
(export "cabi_post_foo:foo/new#foo" (func 3))
(func (;2;) (type 2) (result i32)
call $allocate_stack
global.get $__stack_pointer
global.get $allocation_state
i32.const 0
i32.const 0
i32.const 0
i32.const 0
call $realloc
unreachable
)
(func (;3;) (type 3) (param i32)
call $allocate_stack
i32.const 0
i32.const 0
i32.const 0
call $free
unreachable
)
(func $allocate_stack (;4;) (type 4)
global.get $allocation_state
i32.const 0
i32.eq
if ;; label = @1
i32.const 1
global.set $allocation_state
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $realloc
i32.const 65536
i32.add
global.set $__stack_pointer
i32.const 2
global.set $allocation_state
end
)
)
(core instance $main (;0;) (instantiate $main))
(alias core export $main "memory" (core memory $memory (;0;)))
(alias core export $main "canonical_abi_realloc" (core func $canonical_abi_realloc (;0;)))
(alias core export $main "canonical_abi_free" (core func $canonical_abi_free (;1;)))
(core instance $__main_module__ (;1;)
(export "canonical_abi_realloc" (func $canonical_abi_realloc))
(export "canonical_abi_free" (func $canonical_abi_free))
)
(core instance $old (;2;) (instantiate $wit-component:adapter:old
(with "__main_module__" (instance $__main_module__))
)
)
(type (;0;) (func (result string)))
(alias core export $old "foo:foo/new#foo" (core func $foo:foo/new#foo (;2;)))
(alias core export $old "cabi_post_foo:foo/new#foo" (core func $cabi_post_foo:foo/new#foo (;3;)))
(func $foo (;0;) (type 0) (canon lift (core func $foo:foo/new#foo) (memory $memory) string-encoding=utf8 (post-return $cabi_post_foo:foo/new#foo)))
(component $foo:foo/new-shim-component (;0;)
(type (;0;) (func (result string)))
(import "import-func-foo" (func (;0;) (type 0)))
(type (;1;) (func (result string)))
(export (;1;) "foo" (func 0) (func (type 1)))
)
(instance $foo:foo/new-shim-instance (;0;) (instantiate $foo:foo/new-shim-component
(with "import-func-foo" (func $foo))
)
)
(export $foo:foo/new (;1;) "foo:foo/new" (instance $foo:foo/new-shim-instance))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,5 @@
package root:component;
world root {
export foo:foo/new;
}

View File

@@ -0,0 +1,9 @@
(module
(func (export "canonical_abi_realloc") (param i32 i32 i32 i32) (result i32)
unreachable
)
(func (export "canonical_abi_free") (param i32 i32 i32)
unreachable
)
(memory (export "memory") 1)
)

View File

@@ -0,0 +1,3 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,7 @@
(module
(import "foo:foo/adapter-imports" "foo" (func $foo (param i32 i32)))
(func (export "adapter-bar") (param i32 i32)
(call $foo (i32.const 0) (i32.const 0))
)
(func (export "cabi_export_realloc") (param i32 i32 i32 i32) (result i32) unreachable)
)

View File

@@ -0,0 +1,9 @@
interface adapter-imports {
foo: func(x: string);
}
world adapt-unused {
import adapter-imports;
export adapter-bar: func(x: string);
}

View File

@@ -0,0 +1,115 @@
(component
(type $ty-foo:foo/adapter-imports (;0;)
(instance
(type (;0;) (func (param "x" string)))
(export (;0;) "foo" (func (type 0)))
)
)
(import "foo:foo/adapter-imports" (instance $foo:foo/adapter-imports (;0;) (type $ty-foo:foo/adapter-imports)))
(type (;1;) (func (param "x" string)))
(import "foo" (func $foo (;0;) (type 1)))
(core module $main (;0;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func))
(import "$root" "foo" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "bar" (func 1))
(export "memory" (memory 0))
(func (;1;) (type 1)
unreachable
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:unused (;1;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(import "foo:foo/adapter-imports" "foo" (func $foo (;0;) (type 0)))
(export "adapter-bar" (func 1))
(export "cabi_export_realloc" (func 2))
(func (;1;) (type 0) (param i32 i32)
i32.const 0
i32.const 0
call $foo
)
(func (;2;) (type 1) (param i32 i32 i32 i32) (result i32)
unreachable
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (param i32 i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $indirect-$root-foo))
(export "1" (func $indirect-foo:foo/adapter-imports-foo))
(export "$imports" (table 0))
(func $indirect-$root-foo (;0;) (type 0) (param i32 i32)
local.get 0
local.get 1
i32.const 0
call_indirect (type 0)
)
(func $indirect-foo:foo/adapter-imports-foo (;1;) (type 0) (param i32 i32)
local.get 0
local.get 1
i32.const 1
call_indirect (type 0)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (param i32 i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 0)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $indirect-$root-foo (;0;)))
(core instance $$root (;1;)
(export "foo" (func $indirect-$root-foo))
)
(core instance $main (;2;) (instantiate $main
(with "$root" (instance $$root))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(alias core export $wit-component-shim-instance "1" (core func $indirect-foo:foo/adapter-imports-foo (;1;)))
(core instance $foo:foo/adapter-imports (;3;)
(export "foo" (func $indirect-foo:foo/adapter-imports-foo))
)
(core instance $unused (;4;) (instantiate $wit-component:adapter:unused
(with "foo:foo/adapter-imports" (instance $foo:foo/adapter-imports))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(core func $"#core-func2 indirect-$root-foo" (@name "indirect-$root-foo") (;2;) (canon lower (func $foo) (memory $memory) string-encoding=utf8))
(alias export $foo:foo/adapter-imports "foo" (func $"#func1 foo" (@name "foo") (;1;)))
(core func $"#core-func3 indirect-foo:foo/adapter-imports-foo" (@name "indirect-foo:foo/adapter-imports-foo") (;3;) (canon lower (func $"#func1 foo") (memory $memory) string-encoding=utf8))
(core instance $fixup-args (;5;)
(export "$imports" (table $"shim table"))
(export "0" (func $"#core-func2 indirect-$root-foo"))
(export "1" (func $"#core-func3 indirect-foo:foo/adapter-imports-foo"))
)
(core instance $fixup (;6;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(type (;2;) (func))
(alias core export $main "bar" (core func $bar (;4;)))
(func $bar (;2;) (type 2) (canon lift (core func $bar)))
(export $"#func3 bar" (@name "bar") (;3;) "bar" (func $bar))
(alias core export $unused "adapter-bar" (core func $adapter-bar (;5;)))
(alias core export $unused "cabi_export_realloc" (core func $cabi_export_realloc (;6;)))
(func $adapter-bar (;4;) (type 1) (canon lift (core func $adapter-bar) (memory $memory) (realloc $cabi_export_realloc) string-encoding=utf8))
(export $"#func5 adapter-bar" (@name "adapter-bar") (;5;) "adapter-bar" (func $adapter-bar))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,9 @@
package root:component;
world root {
import foo:foo/adapter-imports;
import foo: func(x: string);
export bar: func();
export adapter-bar: func(x: string);
}

View File

@@ -0,0 +1,5 @@
(module
(import "$root" "foo" (func (param i32 i32)))
(func (export "bar") unreachable)
(memory (export "memory") 1)
)

View File

@@ -0,0 +1,6 @@
package foo:foo;
world module {
import foo: func(x: string);
export bar: func();
}

View File

@@ -0,0 +1,76 @@
(module
(import "new" "get-two" (func $get_two (param i32)))
(import "__main_module__" "cabi_realloc" (func $cabi_realloc (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 0))
(global $__stack_pointer (mut i32) i32.const 0)
(global $some_other_mutable_global (mut i32) i32.const 0)
;; `wit-component` should use this to track the status of a lazy stack
;; allocation:
(global $allocation_state (mut i32) i32.const 0)
;; This is a sample adapter which is adapting between ABI. This exact function
;; signature is imported by `module.wat` and we're implementing it here with a
;; canonical-abi function that returns two integers. The canonical ABI for
;; returning two integers is different than the ABI of this function, hence
;; the adapter here.
;;
;; The purpose of this test case is to exercise the `$__stack_pointer` global.
;; The stack pointer here needs to be initialized to something valid for
;; this adapter module which is done with an injected `start` function into
;; this adapter module when it's bundled into a component.
(func (export "get_sum") (result i32)
(local i32 i32)
;; `wit-component` should have injected a call to a function that allocates
;; the stack and sets $allocation_state to 2
(if (i32.ne (global.get $allocation_state) (i32.const 2)) (then (unreachable)))
;; First, allocate a page using $cabi_realloc and write to it. This tests
;; that we can use the main module's allocator if present (or else a
;; substitute synthesized by `wit-component`).
(local.set 0
(call $cabi_realloc
(i32.const 0)
(i32.const 0)
(i32.const 8)
(i32.const 65536)))
(i32.store (local.get 0) (i32.const 42))
(i32.store offset=65532 (local.get 0) (i32.const 42))
;; Allocate 8 bytes of stack space for the two u32 return values. The
;; original stack pointer is saved in local 0 and the stack frame for this
;; function is saved in local 1.
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
;; Call the imported function which will return two u32 values into the
;; return pointer specified here, our stack frame.
local.get 1
call $get_two
;; Compute the result of this function by adding together the two return
;; values.
(i32.add
(i32.load (local.get 1))
(i32.load offset=4 (local.get 1)))
;; Test that if there is another mutable global in this module that it
;; doesn't affect the detection of the stack pointer. This extra mutable
;; global should not be initialized or tampered with as part of the
;; initialize-the-stack-pointer injected function
(global.set $some_other_mutable_global (global.get $some_other_mutable_global))
;; Restore the stack pointer to the value it was at prior to entering this
;; function.
local.get 0
global.set $__stack_pointer
)
)

View File

@@ -0,0 +1,5 @@
world adapt-old {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,174 @@
(component
(type $ty-new (;0;)
(instance
(type (;0;) (tuple u32 u32))
(type (;1;) (func (result 0)))
(export (;0;) "get-two" (func (type 1)))
)
)
(import "new" (instance $new (;0;) (type $ty-new)))
(core module $main (;0;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(import "old" "get_sum" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "memory" (memory 0))
(export "cabi_realloc" (func $cabi_realloc))
(export "cabi_realloc_adapter" (func $cabi_realloc_adapter))
(func $cabi_realloc (;1;) (type 1) (param i32 i32 i32 i32) (result i32)
i32.const 123456789
)
(func $cabi_realloc_adapter (;2;) (type 1) (param i32 i32 i32 i32) (result i32)
i32.const 987654321
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(type (;2;) (func (result i32)))
(type (;3;) (func))
(import "env" "memory" (memory (;0;) 0))
(import "new" "get-two" (func $get_two (;0;) (type 0)))
(import "__main_module__" "cabi_realloc_adapter" (func $cabi_realloc (;1;) (type 1)))
(global $__stack_pointer (;0;) (mut i32) i32.const 0)
(global $some_other_mutable_global (;1;) (mut i32) i32.const 0)
(global $allocation_state (;2;) (mut i32) i32.const 0)
(export "get_sum" (func 2))
(func (;2;) (type 2) (result i32)
(local i32 i32)
call $allocate_stack
global.get $allocation_state
i32.const 2
i32.ne
if ;; label = @1
unreachable
end
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $cabi_realloc
local.set 0
local.get 0
i32.const 42
i32.store
local.get 0
i32.const 42
i32.store offset=65532
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
local.get 1
call $get_two
local.get 1
i32.load
local.get 1
i32.load offset=4
i32.add
global.get $some_other_mutable_global
global.set $some_other_mutable_global
local.get 0
global.set $__stack_pointer
)
(func $allocate_stack (;3;) (type 3)
global.get $allocation_state
i32.const 0
i32.eq
if ;; label = @1
i32.const 1
global.set $allocation_state
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $cabi_realloc
i32.const 65536
i32.add
global.set $__stack_pointer
i32.const 2
global.set $allocation_state
end
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-old-get_sum))
(export "1" (func $indirect-new-get-two))
(export "$imports" (table 0))
(func $adapt-old-get_sum (;0;) (type 0) (result i32)
i32.const 0
call_indirect (type 0)
)
(func $indirect-new-get-two (;1;) (type 1) (param i32)
local.get 0
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-get_sum (;0;)))
(core instance $old (;1;)
(export "get_sum" (func $adapt-old-get_sum))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(core instance $env (;3;)
(export "memory" (memory $memory))
)
(alias core export $wit-component-shim-instance "1" (core func $indirect-new-get-two (;1;)))
(core instance $new (;4;)
(export "get-two" (func $indirect-new-get-two))
)
(alias core export $main "cabi_realloc_adapter" (core func $cabi_realloc_adapter (;2;)))
(core instance $__main_module__ (;5;)
(export "cabi_realloc_adapter" (func $cabi_realloc_adapter))
)
(core instance $"#core-instance6 old" (@name "old") (;6;) (instantiate $wit-component:adapter:old
(with "env" (instance $env))
(with "new" (instance $new))
(with "__main_module__" (instance $__main_module__))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance6 old" "get_sum" (core func $get_sum (;3;)))
(alias export $new "get-two" (func $get-two (;0;)))
(core func $"#core-func4 indirect-new-get-two" (@name "indirect-new-get-two") (;4;) (canon lower (func $get-two) (memory $memory)))
(core instance $fixup-args (;7;)
(export "$imports" (table $"shim table"))
(export "0" (func $get_sum))
(export "1" (func $"#core-func4 indirect-new-get-two"))
)
(core instance $fixup (;8;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,7 @@
package root:component;
world root {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,12 @@
(module
(import "old" "get_sum" (func (result i32)))
(func $cabi_realloc (param i32 i32 i32 i32) (result i32)
(i32.const 123456789)
)
(func $cabi_realloc_adapter (param i32 i32 i32 i32) (result i32)
(i32.const 987654321)
)
(memory (export "memory") 1)
(export "cabi_realloc" (func $cabi_realloc))
(export "cabi_realloc_adapter" (func $cabi_realloc_adapter))
)

View File

@@ -0,0 +1,2 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,68 @@
(module
(import "new" "get-two" (func $get_two (param i32)))
(import "__main_module__" "cabi_realloc" (func $cabi_realloc (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 0))
(global $__stack_pointer (mut i32) i32.const 0)
(global $some_other_mutable_global (mut i32) i32.const 0)
;; This is a sample adapter which is adapting between ABI. This exact function
;; signature is imported by `module.wat` and we're implementing it here with a
;; canonical-abi function that returns two integers. The canonical ABI for
;; returning two integers is different than the ABI of this function, hence
;; the adapter here.
;;
;; The purpose of this test case is to exercise the `$__stack_pointer` global.
;; The stack pointer here needs to be initialized to something valid for
;; this adapter module which is done with an injected `start` function into
;; this adapter module when it's bundled into a component.
(func (export "get_sum") (result i32)
(local i32 i32)
;; First, allocate a page using $cabi_realloc and write to it. This tests
;; that we can use the main module's allocator if present (or else a
;; substitute synthesized by `wit-component`).
(local.set 0
(call $cabi_realloc
(i32.const 0)
(i32.const 0)
(i32.const 8)
(i32.const 65536)))
(i32.store (local.get 0) (i32.const 42))
(i32.store offset=65532 (local.get 0) (i32.const 42))
;; Allocate 8 bytes of stack space for the two u32 return values. The
;; original stack pointer is saved in local 0 and the stack frame for this
;; function is saved in local 1.
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
;; Call the imported function which will return two u32 values into the
;; return pointer specified here, our stack frame.
local.get 1
call $get_two
;; Compute the result of this function by adding together the two return
;; values.
(i32.add
(i32.load (local.get 1))
(i32.load offset=4 (local.get 1)))
;; Test that if there is another mutable global in this module that it
;; doesn't affect the detection of the stack pointer. This extra mutable
;; global should not be initialized or tampered with as part of the
;; initialize-the-stack-pointer injected function
(global.set $some_other_mutable_global (global.get $some_other_mutable_global))
;; Restore the stack pointer to the value it was at prior to entering this
;; function.
local.get 0
global.set $__stack_pointer
)
)

View File

@@ -0,0 +1,5 @@
world adapt-old {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,216 @@
(component
(type $ty-new (;0;)
(instance
(type (;0;) (tuple u32 u32))
(type (;1;) (func (result 0)))
(export (;0;) "get-two" (func (type 1)))
)
)
(import "new" (instance $new (;0;) (type $ty-new)))
(core module $main (;0;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(import "old" "get_sum" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "memory" (memory 0))
(export "cabi_realloc" (func $cabi_realloc))
(func $cabi_realloc (;1;) (type 1) (param i32 i32 i32 i32) (result i32)
(local i32)
i32.const 0
local.get 0
i32.ne
if ;; label = @1
unreachable
end
i32.const 0
local.get 1
i32.ne
if ;; label = @1
unreachable
end
i32.const 65536
local.get 3
i32.ne
if ;; label = @1
unreachable
end
i32.const 1
memory.grow
local.tee 4
i32.const -1
i32.eq
if ;; label = @1
unreachable
end
local.get 4
i32.const 16
i32.shl
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(type (;2;) (func (result i32)))
(type (;3;) (func (param i32 i32 i32 i32) (result i32)))
(type (;4;) (func))
(import "env" "memory" (memory (;0;) 0))
(import "new" "get-two" (func $get_two (;0;) (type 0)))
(import "__main_module__" "cabi_realloc" (func $cabi_realloc (;1;) (type 1)))
(global $__stack_pointer (;0;) (mut i32) i32.const 0)
(global $some_other_mutable_global (;1;) (mut i32) i32.const 0)
(export "get_sum" (func 2))
(start $allocate_stack)
(func (;2;) (type 2) (result i32)
(local i32 i32)
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $cabi_realloc
local.set 0
local.get 0
i32.const 42
i32.store
local.get 0
i32.const 42
i32.store offset=65532
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
local.get 1
call $get_two
local.get 1
i32.load
local.get 1
i32.load offset=4
i32.add
global.get $some_other_mutable_global
global.set $some_other_mutable_global
local.get 0
global.set $__stack_pointer
)
(func $realloc_via_memory_grow (;3;) (type 3) (param i32 i32 i32 i32) (result i32)
(local i32)
i32.const 0
local.get 0
i32.ne
if ;; label = @1
unreachable
end
i32.const 0
local.get 1
i32.ne
if ;; label = @1
unreachable
end
i32.const 65536
local.get 3
i32.ne
if ;; label = @1
unreachable
end
i32.const 1
memory.grow
local.tee 4
i32.const -1
i32.eq
if ;; label = @1
unreachable
end
local.get 4
i32.const 16
i32.shl
)
(func $allocate_stack (;4;) (type 4)
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $realloc_via_memory_grow
i32.const 65536
i32.add
global.set $__stack_pointer
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-old-get_sum))
(export "1" (func $indirect-new-get-two))
(export "$imports" (table 0))
(func $adapt-old-get_sum (;0;) (type 0) (result i32)
i32.const 0
call_indirect (type 0)
)
(func $indirect-new-get-two (;1;) (type 1) (param i32)
local.get 0
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-get_sum (;0;)))
(core instance $old (;1;)
(export "get_sum" (func $adapt-old-get_sum))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(core instance $env (;3;)
(export "memory" (memory $memory))
)
(alias core export $wit-component-shim-instance "1" (core func $indirect-new-get-two (;1;)))
(core instance $new (;4;)
(export "get-two" (func $indirect-new-get-two))
)
(alias core export $main "cabi_realloc" (core func $cabi_realloc (;2;)))
(core instance $__main_module__ (;5;)
(export "cabi_realloc" (func $cabi_realloc))
)
(core instance $"#core-instance6 old" (@name "old") (;6;) (instantiate $wit-component:adapter:old
(with "env" (instance $env))
(with "new" (instance $new))
(with "__main_module__" (instance $__main_module__))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance6 old" "get_sum" (core func $get_sum (;3;)))
(alias export $new "get-two" (func $get-two (;0;)))
(core func $"#core-func4 indirect-new-get-two" (@name "indirect-new-get-two") (;4;) (canon lower (func $get-two) (memory $memory)))
(core instance $fixup-args (;7;)
(export "$imports" (table $"shim table"))
(export "0" (func $get_sum))
(export "1" (func $"#core-func4 indirect-new-get-two"))
)
(core instance $fixup (;8;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,7 @@
package root:component;
world root {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,38 @@
(module
(import "old" "get_sum" (func (result i32)))
;; Minimal realloc which only accepts new, page-sized allocations:
(func $cabi_realloc (param i32 i32 i32 i32) (result i32)
(local i32)
i32.const 0
local.get 0
i32.ne
if
unreachable
end
i32.const 0
local.get 1
i32.ne
if
unreachable
end
i32.const 65536
local.get 3
i32.ne
if
unreachable
end
i32.const 1
memory.grow
local.tee 4
i32.const -1
i32.eq
if
unreachable
end
local.get 4
i32.const 16
i32.shl
)
(memory (export "memory") 1)
(export "cabi_realloc" (func $cabi_realloc))
)

View File

@@ -0,0 +1,3 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,76 @@
(module
(import "new" "get-two" (func $get_two (param i32)))
(import "__main_module__" "cabi_realloc" (func $cabi_realloc (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 0))
(global $__stack_pointer (mut i32) i32.const 0)
(global $some_other_mutable_global (mut i32) i32.const 0)
;; `wit-component` should use this to track the status of a lazy stack
;; allocation:
(global $allocation_state (mut i32) i32.const 0)
;; This is a sample adapter which is adapting between ABI. This exact function
;; signature is imported by `module.wat` and we're implementing it here with a
;; canonical-abi function that returns two integers. The canonical ABI for
;; returning two integers is different than the ABI of this function, hence
;; the adapter here.
;;
;; The purpose of this test case is to exercise the `$__stack_pointer` global.
;; The stack pointer here needs to be initialized to something valid for
;; this adapter module which is done with an injected `start` function into
;; this adapter module when it's bundled into a component.
(func (export "get_sum") (result i32)
(local i32 i32)
;; `wit-component` should have injected a call to a function that allocates
;; the stack and sets $allocation_state to 2
(if (i32.ne (global.get $allocation_state) (i32.const 2)) (then (unreachable)))
;; First, allocate a page using $cabi_realloc and write to it. This tests
;; that we can use the main module's allocator if present (or else a
;; substitute synthesized by `wit-component`).
(local.set 0
(call $cabi_realloc
(i32.const 0)
(i32.const 0)
(i32.const 8)
(i32.const 65536)))
(i32.store (local.get 0) (i32.const 42))
(i32.store offset=65532 (local.get 0) (i32.const 42))
;; Allocate 8 bytes of stack space for the two u32 return values. The
;; original stack pointer is saved in local 0 and the stack frame for this
;; function is saved in local 1.
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
;; Call the imported function which will return two u32 values into the
;; return pointer specified here, our stack frame.
local.get 1
call $get_two
;; Compute the result of this function by adding together the two return
;; values.
(i32.add
(i32.load (local.get 1))
(i32.load offset=4 (local.get 1)))
;; Test that if there is another mutable global in this module that it
;; doesn't affect the detection of the stack pointer. This extra mutable
;; global should not be initialized or tampered with as part of the
;; initialize-the-stack-pointer injected function
(global.set $some_other_mutable_global (global.get $some_other_mutable_global))
;; Restore the stack pointer to the value it was at prior to entering this
;; function.
local.get 0
global.set $__stack_pointer
)
)

View File

@@ -0,0 +1,5 @@
world adapt-old {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,199 @@
(component
(type $ty-new (;0;)
(instance
(type (;0;) (tuple u32 u32))
(type (;1;) (func (result 0)))
(export (;0;) "get-two" (func (type 1)))
)
)
(import "new" (instance $new (;0;) (type $ty-new)))
(core module $main (;0;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(import "old" "get_sum" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "memory" (memory 0))
(export "cabi_realloc" (func $cabi_realloc))
(func $cabi_realloc (;1;) (type 1) (param i32 i32 i32 i32) (result i32)
(local i32)
i32.const 0
local.get 0
i32.ne
if ;; label = @1
unreachable
end
i32.const 0
local.get 1
i32.ne
if ;; label = @1
unreachable
end
i32.const 65536
local.get 3
i32.ne
if ;; label = @1
unreachable
end
i32.const 1
memory.grow
local.tee 4
i32.const -1
i32.eq
if ;; label = @1
unreachable
end
local.get 4
i32.const 16
i32.shl
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(type (;2;) (func (result i32)))
(type (;3;) (func))
(import "env" "memory" (memory (;0;) 0))
(import "new" "get-two" (func $get_two (;0;) (type 0)))
(import "__main_module__" "cabi_realloc" (func $cabi_realloc (;1;) (type 1)))
(global $__stack_pointer (;0;) (mut i32) i32.const 0)
(global $some_other_mutable_global (;1;) (mut i32) i32.const 0)
(global $allocation_state (;2;) (mut i32) i32.const 0)
(export "get_sum" (func 2))
(func (;2;) (type 2) (result i32)
(local i32 i32)
call $allocate_stack
global.get $allocation_state
i32.const 2
i32.ne
if ;; label = @1
unreachable
end
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $cabi_realloc
local.set 0
local.get 0
i32.const 42
i32.store
local.get 0
i32.const 42
i32.store offset=65532
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
local.get 1
call $get_two
local.get 1
i32.load
local.get 1
i32.load offset=4
i32.add
global.get $some_other_mutable_global
global.set $some_other_mutable_global
local.get 0
global.set $__stack_pointer
)
(func $allocate_stack (;3;) (type 3)
global.get $allocation_state
i32.const 0
i32.eq
if ;; label = @1
i32.const 1
global.set $allocation_state
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $cabi_realloc
i32.const 65536
i32.add
global.set $__stack_pointer
i32.const 2
global.set $allocation_state
end
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-old-get_sum))
(export "1" (func $indirect-new-get-two))
(export "$imports" (table 0))
(func $adapt-old-get_sum (;0;) (type 0) (result i32)
i32.const 0
call_indirect (type 0)
)
(func $indirect-new-get-two (;1;) (type 1) (param i32)
local.get 0
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-get_sum (;0;)))
(core instance $old (;1;)
(export "get_sum" (func $adapt-old-get_sum))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(core instance $env (;3;)
(export "memory" (memory $memory))
)
(alias core export $wit-component-shim-instance "1" (core func $indirect-new-get-two (;1;)))
(core instance $new (;4;)
(export "get-two" (func $indirect-new-get-two))
)
(alias core export $main "cabi_realloc" (core func $cabi_realloc (;2;)))
(core instance $__main_module__ (;5;)
(export "cabi_realloc" (func $cabi_realloc))
)
(core instance $"#core-instance6 old" (@name "old") (;6;) (instantiate $wit-component:adapter:old
(with "env" (instance $env))
(with "new" (instance $new))
(with "__main_module__" (instance $__main_module__))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance6 old" "get_sum" (core func $get_sum (;3;)))
(alias export $new "get-two" (func $get-two (;0;)))
(core func $"#core-func4 indirect-new-get-two" (@name "indirect-new-get-two") (;4;) (canon lower (func $get-two) (memory $memory)))
(core instance $fixup-args (;7;)
(export "$imports" (table $"shim table"))
(export "0" (func $get_sum))
(export "1" (func $"#core-func4 indirect-new-get-two"))
)
(core instance $fixup (;8;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,7 @@
package root:component;
world root {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,38 @@
(module
(import "old" "get_sum" (func (result i32)))
;; Minimal realloc which only accepts new, page-sized allocations:
(func $cabi_realloc (param i32 i32 i32 i32) (result i32)
(local i32)
i32.const 0
local.get 0
i32.ne
if
unreachable
end
i32.const 0
local.get 1
i32.ne
if
unreachable
end
i32.const 65536
local.get 3
i32.ne
if
unreachable
end
i32.const 1
memory.grow
local.tee 4
i32.const -1
i32.eq
if
unreachable
end
local.get 4
i32.const 16
i32.shl
)
(memory (export "memory") 1)
(export "cabi_realloc" (func $cabi_realloc))
)

View File

@@ -0,0 +1,3 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,62 @@
(module
(import "new" "get-two" (func $get_two (param i32)))
(import "env" "memory" (memory 0))
(global $__stack_pointer (mut i32) i32.const 0)
(global $some_other_mutable_global (mut i32) i32.const 0)
;; `wit-component` should use this to track the status of a lazy stack
;; allocation:
(global $allocation_state (mut i32) i32.const 0)
;; This is a sample adapter which is adapting between ABI. This exact function
;; signature is imported by `module.wat` and we're implementing it here with a
;; canonical-abi function that returns two integers. The canonical ABI for
;; returning two integers is different than the ABI of this function, hence
;; the adapter here.
;;
;; The purpose of this test case is to exercise the `$__stack_pointer` global.
;; The stack pointer here needs to be initialized to something valid for
;; this adapter module which is done with an injected `start` function into
;; this adapter module when it's bundled into a component.
(func (export "get_sum") (result i32)
(local i32 i32)
;; `wit-component` should have injected a call to a function that allocates
;; the stack and sets $allocation_state to 2
(if (i32.ne (global.get $allocation_state) (i32.const 2)) (then (unreachable)))
;; Allocate 8 bytes of stack space for the two u32 return values. The
;; original stack pointer is saved in local 0 and the stack frame for this
;; function is saved in local 1.
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
;; Call the imported function which will return two u32 values into the
;; return pointer specified here, our stack frame.
local.get 1
call $get_two
;; Compute the result of this function by adding together the two return
;; values.
(i32.add
(i32.load (local.get 1))
(i32.load offset=4 (local.get 1)))
;; Test that if there is another mutable global in this module that it
;; doesn't affect the detection of the stack pointer. This extra mutable
;; global should not be initialized or tampered with as part of the
;; initialize-the-stack-pointer injected function
(global.set $some_other_mutable_global (global.get $some_other_mutable_global))
;; Restore the stack pointer to the value it was at prior to entering this
;; function.
local.get 0
global.set $__stack_pointer
)
)

View File

@@ -0,0 +1,5 @@
world adapt-old {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,187 @@
(component
(type $ty-new (;0;)
(instance
(type (;0;) (tuple u32 u32))
(type (;1;) (func (result 0)))
(export (;0;) "get-two" (func (type 1)))
)
)
(import "new" (instance $new (;0;) (type $ty-new)))
(core module $main (;0;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(import "old" "get_sum" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "memory" (memory 0))
(export "cabi_realloc" (func $cabi_realloc))
(func $cabi_realloc (;1;) (type 1) (param i32 i32 i32 i32) (result i32)
(local i32)
i32.const 0
local.get 0
i32.ne
if ;; label = @1
unreachable
end
i32.const 0
local.get 1
i32.ne
if ;; label = @1
unreachable
end
i32.const 65536
local.get 3
i32.ne
if ;; label = @1
unreachable
end
i32.const 1
memory.grow
local.tee 4
i32.const -1
i32.eq
if ;; label = @1
unreachable
end
local.get 4
i32.const 16
i32.shl
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32)))
(type (;1;) (func (result i32)))
(type (;2;) (func (param i32 i32 i32 i32) (result i32)))
(type (;3;) (func))
(import "env" "memory" (memory (;0;) 0))
(import "new" "get-two" (func $get_two (;0;) (type 0)))
(import "__main_module__" "cabi_realloc" (func $cabi_realloc (;1;) (type 2)))
(global $__stack_pointer (;0;) (mut i32) i32.const 0)
(global $some_other_mutable_global (;1;) (mut i32) i32.const 0)
(global $allocation_state (;2;) (mut i32) i32.const 0)
(export "get_sum" (func 2))
(func (;2;) (type 1) (result i32)
(local i32 i32)
call $allocate_stack
global.get $allocation_state
i32.const 2
i32.ne
if ;; label = @1
unreachable
end
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
local.get 1
call $get_two
local.get 1
i32.load
local.get 1
i32.load offset=4
i32.add
global.get $some_other_mutable_global
global.set $some_other_mutable_global
local.get 0
global.set $__stack_pointer
)
(func $allocate_stack (;3;) (type 3)
global.get $allocation_state
i32.const 0
i32.eq
if ;; label = @1
i32.const 1
global.set $allocation_state
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $cabi_realloc
i32.const 65536
i32.add
global.set $__stack_pointer
i32.const 2
global.set $allocation_state
end
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-old-get_sum))
(export "1" (func $indirect-new-get-two))
(export "$imports" (table 0))
(func $adapt-old-get_sum (;0;) (type 0) (result i32)
i32.const 0
call_indirect (type 0)
)
(func $indirect-new-get-two (;1;) (type 1) (param i32)
local.get 0
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-get_sum (;0;)))
(core instance $old (;1;)
(export "get_sum" (func $adapt-old-get_sum))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(core instance $env (;3;)
(export "memory" (memory $memory))
)
(alias core export $wit-component-shim-instance "1" (core func $indirect-new-get-two (;1;)))
(core instance $new (;4;)
(export "get-two" (func $indirect-new-get-two))
)
(alias core export $main "cabi_realloc" (core func $cabi_realloc (;2;)))
(core instance $__main_module__ (;5;)
(export "cabi_realloc" (func $cabi_realloc))
)
(core instance $"#core-instance6 old" (@name "old") (;6;) (instantiate $wit-component:adapter:old
(with "env" (instance $env))
(with "new" (instance $new))
(with "__main_module__" (instance $__main_module__))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance6 old" "get_sum" (core func $get_sum (;3;)))
(alias export $new "get-two" (func $get-two (;0;)))
(core func $"#core-func4 indirect-new-get-two" (@name "indirect-new-get-two") (;4;) (canon lower (func $get-two) (memory $memory)))
(core instance $fixup-args (;7;)
(export "$imports" (table $"shim table"))
(export "0" (func $get_sum))
(export "1" (func $"#core-func4 indirect-new-get-two"))
)
(core instance $fixup (;8;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,7 @@
package root:component;
world root {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,38 @@
(module
(import "old" "get_sum" (func (result i32)))
;; Minimal realloc which only accepts new, page-sized allocations:
(func $cabi_realloc (param i32 i32 i32 i32) (result i32)
(local i32)
i32.const 0
local.get 0
i32.ne
if
unreachable
end
i32.const 0
local.get 1
i32.ne
if
unreachable
end
i32.const 65536
local.get 3
i32.ne
if
unreachable
end
i32.const 1
memory.grow
local.tee 4
i32.const -1
i32.eq
if
unreachable
end
local.get 4
i32.const 16
i32.shl
)
(memory (export "memory") 1)
(export "cabi_realloc" (func $cabi_realloc))
)

View File

@@ -0,0 +1,2 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,54 @@
(module
(import "new" "get-two" (func $get_two (param i32)))
(import "env" "memory" (memory 0))
(global $__stack_pointer (mut i32) i32.const 0)
(global $some_other_mutable_global (mut i32) i32.const 0)
;; This is a sample adapter which is adapting between ABI. This exact function
;; signature is imported by `module.wat` and we're implementing it here with a
;; canonical-abi function that returns two integers. The canonical ABI for
;; returning two integers is different than the ABI of this function, hence
;; the adapter here.
;;
;; The purpose of this test case is to exercise the `$__stack_pointer` global.
;; The stack pointer here needs to be initialized to something valid for
;; this adapter module which is done with an injected `start` function into
;; this adapter module when it's bundled into a component.
(func (export "get_sum") (result i32)
(local i32 i32)
;; Allocate 8 bytes of stack space for the two u32 return values. The
;; original stack pointer is saved in local 0 and the stack frame for this
;; function is saved in local 1.
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
;; Call the imported function which will return two u32 values into the
;; return pointer specified here, our stack frame.
local.get 1
call $get_two
;; Compute the result of this function by adding together the two return
;; values.
(i32.add
(i32.load (local.get 1))
(i32.load offset=4 (local.get 1)))
;; Test that if there is another mutable global in this module that it
;; doesn't affect the detection of the stack pointer. This extra mutable
;; global should not be initialized or tampered with as part of the
;; initialize-the-stack-pointer injected function
(global.set $some_other_mutable_global (global.get $some_other_mutable_global))
;; Restore the stack pointer to the value it was at prior to entering this
;; function.
local.get 0
global.set $__stack_pointer
)
)

View File

@@ -0,0 +1,5 @@
world adapt-old {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,163 @@
(component
(type $ty-new (;0;)
(instance
(type (;0;) (tuple u32 u32))
(type (;1;) (func (result 0)))
(export (;0;) "get-two" (func (type 1)))
)
)
(import "new" (instance $new (;0;) (type $ty-new)))
(core module $main (;0;)
(type (;0;) (func (result i32)))
(import "old" "get_sum" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "memory" (memory 0))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32)))
(type (;1;) (func (result i32)))
(type (;2;) (func (param i32 i32 i32 i32) (result i32)))
(type (;3;) (func))
(import "env" "memory" (memory (;0;) 0))
(import "new" "get-two" (func $get_two (;0;) (type 0)))
(global $__stack_pointer (;0;) (mut i32) i32.const 0)
(global $some_other_mutable_global (;1;) (mut i32) i32.const 0)
(export "get_sum" (func 1))
(start $allocate_stack)
(func (;1;) (type 1) (result i32)
(local i32 i32)
global.get $__stack_pointer
local.tee 0
i32.const 8
i32.sub
local.tee 1
global.set $__stack_pointer
local.get 1
call $get_two
local.get 1
i32.load
local.get 1
i32.load offset=4
i32.add
global.get $some_other_mutable_global
global.set $some_other_mutable_global
local.get 0
global.set $__stack_pointer
)
(func $realloc_via_memory_grow (;2;) (type 2) (param i32 i32 i32 i32) (result i32)
(local i32)
i32.const 0
local.get 0
i32.ne
if ;; label = @1
unreachable
end
i32.const 0
local.get 1
i32.ne
if ;; label = @1
unreachable
end
i32.const 65536
local.get 3
i32.ne
if ;; label = @1
unreachable
end
i32.const 1
memory.grow
local.tee 4
i32.const -1
i32.eq
if ;; label = @1
unreachable
end
local.get 4
i32.const 16
i32.shl
)
(func $allocate_stack (;3;) (type 3)
i32.const 0
i32.const 0
i32.const 8
i32.const 65536
call $realloc_via_memory_grow
i32.const 65536
i32.add
global.set $__stack_pointer
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-old-get_sum))
(export "1" (func $indirect-new-get-two))
(export "$imports" (table 0))
(func $adapt-old-get_sum (;0;) (type 0) (result i32)
i32.const 0
call_indirect (type 0)
)
(func $indirect-new-get-two (;1;) (type 1) (param i32)
local.get 0
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-get_sum (;0;)))
(core instance $old (;1;)
(export "get_sum" (func $adapt-old-get_sum))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(core instance $env (;3;)
(export "memory" (memory $memory))
)
(alias core export $wit-component-shim-instance "1" (core func $indirect-new-get-two (;1;)))
(core instance $new (;4;)
(export "get-two" (func $indirect-new-get-two))
)
(core instance $"#core-instance5 old" (@name "old") (;5;) (instantiate $wit-component:adapter:old
(with "env" (instance $env))
(with "new" (instance $new))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance5 old" "get_sum" (core func $get_sum (;2;)))
(alias export $new "get-two" (func $get-two (;0;)))
(core func $"#core-func3 indirect-new-get-two" (@name "indirect-new-get-two") (;3;) (canon lower (func $get-two) (memory $memory)))
(core instance $fixup-args (;6;)
(export "$imports" (table $"shim table"))
(export "0" (func $get_sum))
(export "1" (func $"#core-func3 indirect-new-get-two"))
)
(core instance $fixup (;7;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,7 @@
package root:component;
world root {
import new: interface {
get-two: func() -> tuple<u32, u32>;
}
}

View File

@@ -0,0 +1,4 @@
(module
(import "old" "get_sum" (func (result i32)))
(memory (export "memory") 1)
)

View File

@@ -0,0 +1,2 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,14 @@
(module
(import "new" "read" (func $read (param i32)))
(import "env" "memory" (memory 0))
(func (export "read") (param i32 i32)
i32.const 8
call $read
unreachable
)
(func (export "cabi_import_realloc") (param i32 i32 i32 i32) (result i32)
unreachable
)
)

View File

@@ -0,0 +1,5 @@
world adapt-old {
import new: interface {
read: func() -> list<u8>;
}
}

View File

@@ -0,0 +1,104 @@
(component
(type $ty-new (;0;)
(instance
(type (;0;) (list u8))
(type (;1;) (func (result 0)))
(export (;0;) "read" (func (type 1)))
)
)
(import "new" (instance $new (;0;) (type $ty-new)))
(core module $main (;0;)
(type (;0;) (func (param i32 i32)))
(import "old" "read" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "memory" (memory 0))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32)))
(type (;2;) (func (param i32 i32 i32 i32) (result i32)))
(import "new" "read" (func $read (;0;) (type 0)))
(export "read" (func 1))
(export "cabi_import_realloc" (func 2))
(func (;1;) (type 1) (param i32 i32)
i32.const 8
call $read
unreachable
)
(func (;2;) (type 2) (param i32 i32 i32 i32) (result i32)
unreachable
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-old-read))
(export "1" (func $indirect-new-read))
(export "$imports" (table 0))
(func $adapt-old-read (;0;) (type 0) (param i32 i32)
local.get 0
local.get 1
i32.const 0
call_indirect (type 0)
)
(func $indirect-new-read (;1;) (type 1) (param i32)
local.get 0
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-read (;0;)))
(core instance $old (;1;)
(export "read" (func $adapt-old-read))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(alias core export $wit-component-shim-instance "1" (core func $indirect-new-read (;1;)))
(core instance $new (;3;)
(export "read" (func $indirect-new-read))
)
(core instance $"#core-instance4 old" (@name "old") (;4;) (instantiate $wit-component:adapter:old
(with "new" (instance $new))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance4 old" "read" (core func $read (;2;)))
(alias export $new "read" (func $read (;0;)))
(alias core export $"#core-instance4 old" "cabi_import_realloc" (core func $realloc (;3;)))
(core func $"#core-func4 indirect-new-read" (@name "indirect-new-read") (;4;) (canon lower (func $read) (memory $memory) (realloc $realloc)))
(core instance $fixup-args (;5;)
(export "$imports" (table $"shim table"))
(export "0" (func $read))
(export "1" (func $"#core-func4 indirect-new-read"))
)
(core instance $fixup (;6;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,7 @@
package root:component;
world root {
import new: interface {
read: func() -> list<u8>;
}
}

View File

@@ -0,0 +1,4 @@
(module
(import "old" "read" (func (param i32 i32)))
(memory (export "memory") 1)
)

View File

@@ -0,0 +1,3 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,4 @@
(module
(import "new" "log" (func $log (param i32 i32)))
(export "log" (func $log))
)

View File

@@ -0,0 +1,5 @@
world adapt-old {
import new: interface {
log: func(s: string);
}
}

View File

@@ -0,0 +1,92 @@
(component
(type $ty-new (;0;)
(instance
(type (;0;) (func (param "s" string)))
(export (;0;) "log" (func (type 0)))
)
)
(import "new" (instance $new (;0;) (type $ty-new)))
(core module $main (;0;)
(type (;0;) (func (param i32 i32)))
(import "old" "log" (func (;0;) (type 0)))
(memory (;0;) 1)
(export "memory" (memory 0))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:old (;1;)
(type (;0;) (func (param i32 i32)))
(import "new" "log" (func $log (;0;) (type 0)))
(export "log" (func $log))
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32 i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-old-log))
(export "1" (func $indirect-new-log))
(export "$imports" (table 0))
(func $adapt-old-log (;0;) (type 0) (param i32 i32)
local.get 0
local.get 1
i32.const 0
call_indirect (type 0)
)
(func $indirect-new-log (;1;) (type 1) (param i32 i32)
local.get 0
local.get 1
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32 i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-old-log (;0;)))
(core instance $old (;1;)
(export "log" (func $adapt-old-log))
)
(core instance $main (;2;) (instantiate $main
(with "old" (instance $old))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(alias core export $wit-component-shim-instance "1" (core func $indirect-new-log (;1;)))
(core instance $new (;3;)
(export "log" (func $indirect-new-log))
)
(core instance $"#core-instance4 old" (@name "old") (;4;) (instantiate $wit-component:adapter:old
(with "new" (instance $new))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance4 old" "log" (core func $log (;2;)))
(alias export $new "log" (func $log (;0;)))
(core func $"#core-func3 indirect-new-log" (@name "indirect-new-log") (;3;) (canon lower (func $log) (memory $memory) string-encoding=utf8))
(core instance $fixup-args (;5;)
(export "$imports" (table $"shim table"))
(export "0" (func $log))
(export "1" (func $"#core-func3 indirect-new-log"))
)
(core instance $fixup (;6;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,7 @@
package root:component;
world root {
import new: interface {
log: func(s: string);
}
}

View File

@@ -0,0 +1,4 @@
(module
(import "old" "log" (func (param i32 i32)))
(memory (export "memory") 1)
)

View File

@@ -0,0 +1,2 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,10 @@
;; this is a polyfill module that translates from wasi-preview1 to a different
;; interface
(module
(import "other1" "foo" (func $foo))
(import "other2" "bar" (func $bar))
(func (export "foo") call $foo)
(func (export "bar") call $bar)
)

View File

@@ -0,0 +1,8 @@
world adapt-foo {
import other1: interface {
foo: func();
}
import other2: interface {
bar: func();
}
}

View File

@@ -0,0 +1,107 @@
(component
(type $ty-other1 (;0;)
(instance
(type (;0;) (func))
(export (;0;) "foo" (func (type 0)))
)
)
(import "other1" (instance $other1 (;0;) (type $ty-other1)))
(type $ty-other2 (;1;)
(instance
(type (;0;) (func))
(export (;0;) "bar" (func (type 0)))
)
)
(import "other2" (instance $other2 (;1;) (type $ty-other2)))
(core module $main (;0;)
(type (;0;) (func))
(import "foo" "foo" (func (;0;) (type 0)))
(import "foo" "bar" (func (;1;) (type 0)))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:foo (;1;)
(type (;0;) (func))
(import "other1" "foo" (func $foo (;0;) (type 0)))
(import "other2" "bar" (func $bar (;1;) (type 0)))
(export "foo" (func 2))
(export "bar" (func 3))
(func (;2;) (type 0)
call $foo
)
(func (;3;) (type 0)
call $bar
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-foo-foo))
(export "1" (func $adapt-foo-bar))
(export "$imports" (table 0))
(func $adapt-foo-foo (;0;) (type 0)
i32.const 0
call_indirect (type 0)
)
(func $adapt-foo-bar (;1;) (type 0)
i32.const 1
call_indirect (type 0)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 0)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias core export $wit-component-shim-instance "0" (core func $adapt-foo-foo (;0;)))
(alias core export $wit-component-shim-instance "1" (core func $adapt-foo-bar (;1;)))
(core instance $foo (;1;)
(export "foo" (func $adapt-foo-foo))
(export "bar" (func $adapt-foo-bar))
)
(core instance $main (;2;) (instantiate $main
(with "foo" (instance $foo))
)
)
(alias export $other1 "foo" (func $foo (;0;)))
(core func $foo (;2;) (canon lower (func $foo)))
(core instance $other1 (;3;)
(export "foo" (func $foo))
)
(alias export $other2 "bar" (func $bar (;1;)))
(core func $bar (;3;) (canon lower (func $bar)))
(core instance $other2 (;4;)
(export "bar" (func $bar))
)
(core instance $"#core-instance5 foo" (@name "foo") (;5;) (instantiate $wit-component:adapter:foo
(with "other1" (instance $other1))
(with "other2" (instance $other2))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance5 foo" "foo" (core func $"#core-func4 foo" (@name "foo") (;4;)))
(alias core export $"#core-instance5 foo" "bar" (core func $"#core-func5 bar" (@name "bar") (;5;)))
(core instance $fixup-args (;6;)
(export "$imports" (table $"shim table"))
(export "0" (func $"#core-func4 foo"))
(export "1" (func $"#core-func5 bar"))
)
(core instance $fixup (;7;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,10 @@
package root:component;
world root {
import other1: interface {
foo: func();
}
import other2: interface {
bar: func();
}
}

View File

@@ -0,0 +1,4 @@
(module
(import "foo" "foo" (func))
(import "foo" "bar" (func))
)

View File

@@ -0,0 +1,2 @@
package foo:foo;
world module {}

View File

@@ -0,0 +1,13 @@
;; this is a polyfill module that translates from wasi-preview1 to a different
;; interface
(module
(import "foo:foo/my-wasi" "proc-exit" (func $proc_exit (param i32)))
(func (export "proc_exit") (param i32)
local.get 0
call $proc_exit
)
(func (export "random_get") (param i32 i32) (result i32)
i32.const 0)
(func (export "something_else"))
)

View File

@@ -0,0 +1,12 @@
/// This is the interface imported by the `adapt-*.wat` file which is used
/// to implement the `wasi_snapshot_preview1` interface.
interface my-wasi {
random-get: func(size: u32) -> list<u8>;
proc-exit: func(code: u32);
something-not-used: func();
}
world adapt-wasi-snapshot-preview1 {
import my-wasi;
}

View File

@@ -0,0 +1,119 @@
(component
(type $ty-foo (;0;)
(instance
(type (;0;) (func))
(export (;0;) "foo" (func (type 0)))
)
)
(import "foo" (instance $foo (;0;) (type $ty-foo)))
(type $ty-foo:foo/my-wasi (;1;)
(instance
(type (;0;) (func (param "code" u32)))
(export (;0;) "proc-exit" (func (type 0)))
)
)
(import "foo:foo/my-wasi" (instance $foo:foo/my-wasi (;1;) (type $ty-foo:foo/my-wasi)))
(core module $main (;0;)
(type (;0;) (func))
(type (;1;) (func (param i32)))
(type (;2;) (func (param i32 i32) (result i32)))
(import "foo" "foo" (func (;0;) (type 0)))
(import "wasi-snapshot-preview1" "proc_exit" (func (;1;) (type 1)))
(import "wasi-snapshot-preview1" "random_get" (func (;2;) (type 2)))
(memory (;0;) 1)
(export "memory" (memory 0))
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:wasi-snapshot-preview1 (;1;)
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32) (result i32)))
(import "foo:foo/my-wasi" "proc-exit" (func $proc_exit (;0;) (type 0)))
(export "proc_exit" (func 1))
(export "random_get" (func 2))
(func (;1;) (type 0) (param i32)
local.get 0
call $proc_exit
)
(func (;2;) (type 1) (param i32 i32) (result i32)
i32.const 0
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32) (result i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $adapt-wasi-snapshot-preview1-proc_exit))
(export "1" (func $adapt-wasi-snapshot-preview1-random_get))
(export "$imports" (table 0))
(func $adapt-wasi-snapshot-preview1-proc_exit (;0;) (type 0) (param i32)
local.get 0
i32.const 0
call_indirect (type 0)
)
(func $adapt-wasi-snapshot-preview1-random_get (;1;) (type 1) (param i32 i32) (result i32)
local.get 0
local.get 1
i32.const 1
call_indirect (type 1)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core module $wit-component-fixup (;3;)
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32) (result i32)))
(import "" "0" (func (;0;) (type 0)))
(import "" "1" (func (;1;) (type 1)))
(import "" "$imports" (table (;0;) 2 2 funcref))
(elem (;0;) (i32.const 0) func 0 1)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
(core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module))
(alias export $foo "foo" (func $foo (;0;)))
(core func $foo (;0;) (canon lower (func $foo)))
(core instance $foo (;1;)
(export "foo" (func $foo))
)
(alias core export $wit-component-shim-instance "0" (core func $adapt-wasi-snapshot-preview1-proc_exit (;1;)))
(alias core export $wit-component-shim-instance "1" (core func $adapt-wasi-snapshot-preview1-random_get (;2;)))
(core instance $wasi-snapshot-preview1 (;2;)
(export "proc_exit" (func $adapt-wasi-snapshot-preview1-proc_exit))
(export "random_get" (func $adapt-wasi-snapshot-preview1-random_get))
)
(core instance $main (;3;) (instantiate $main
(with "foo" (instance $foo))
(with "wasi-snapshot-preview1" (instance $wasi-snapshot-preview1))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(alias export $foo:foo/my-wasi "proc-exit" (func $proc-exit (;1;)))
(core func $proc-exit (;3;) (canon lower (func $proc-exit)))
(core instance $foo:foo/my-wasi (;4;)
(export "proc-exit" (func $proc-exit))
)
(core instance $"#core-instance5 wasi-snapshot-preview1" (@name "wasi-snapshot-preview1") (;5;) (instantiate $wit-component:adapter:wasi-snapshot-preview1
(with "foo:foo/my-wasi" (instance $foo:foo/my-wasi))
)
)
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance5 wasi-snapshot-preview1" "proc_exit" (core func $proc_exit (;4;)))
(alias core export $"#core-instance5 wasi-snapshot-preview1" "random_get" (core func $random_get (;5;)))
(core instance $fixup-args (;6;)
(export "$imports" (table $"shim table"))
(export "0" (func $proc_exit))
(export "1" (func $random_get))
)
(core instance $fixup (;7;) (instantiate $wit-component-fixup
(with "" (instance $fixup-args))
)
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)

View File

@@ -0,0 +1,8 @@
package root:component;
world root {
import foo: interface {
foo: func();
}
import foo:foo/my-wasi;
}

View File

@@ -0,0 +1,11 @@
(module
;; import something from an external interface
(import "foo" "foo" (func))
;; import some wasi functions
(import "wasi-snapshot-preview1" "proc_exit" (func (param i32)))
(import "wasi-snapshot-preview1" "random_get" (func (param i32 i32) (result i32)))
;; required by wasi
(memory (export "memory") 1)
)

View File

@@ -0,0 +1,7 @@
package foo:foo;
world module {
import foo: interface {
foo: func();
}
}

View File

@@ -0,0 +1,8 @@
;; module name: wasi:cli/environment@0.2.0
(module
(type (func (param i32)))
(func $get-environment (type 0)
unreachable
)
(export "get-environment" (func $get-environment))
)

View File

@@ -0,0 +1 @@
world adapt-wasip2 { }

Some files were not shown because too many files have changed in this diff Show More