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

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 { }

View File

@@ -0,0 +1,74 @@
(component
(core module $main (;0;)
(type (;0;) (func))
(type (;1;) (func (param i32)))
(type (;2;) (func (param i32 i32 i32 i32) (result i32)))
(import "wasi:cli/environment@0.2.0" "get-environment" (func $get-environment (;0;) (type 1)))
(memory (;0;) 1)
(export "cabi_realloc" (func $realloc))
(export "memory" (memory 0))
(start $start)
(func $start (;1;) (type 0))
(func $realloc (;2;) (type 2) (param i32 i32 i32 i32) (result i32)
unreachable
)
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
(processed-by "my-fake-bindgen" "123.45")
)
)
(core module $wit-component:adapter:wasi:cli/environment@0.2.0 (;1;)
(type (;0;) (func (param i32)))
(export "get-environment" (func $get-environment))
(func $get-environment (;0;) (type 0) (param i32)
unreachable
)
)
(core module $wit-component-shim-module (;2;)
(type (;0;) (func (param i32)))
(table (;0;) 1 1 funcref)
(export "0" (func $adapt-wasi:cli/environment@0.2.0-get-environment))
(export "$imports" (table 0))
(func $adapt-wasi:cli/environment@0.2.0-get-environment (;0;) (type 0) (param i32)
local.get 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 (param 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-wasi:cli/environment@0.2.0-get-environment (;0;)))
(core instance $wasi:cli/environment@0.2.0 (;1;)
(export "get-environment" (func $adapt-wasi:cli/environment@0.2.0-get-environment))
)
(core instance $main (;2;) (instantiate $main
(with "wasi:cli/environment@0.2.0" (instance $wasi:cli/environment@0.2.0))
)
)
(alias core export $main "memory" (core memory $memory (;0;)))
(core instance $"#core-instance3 wasi:cli/environment@0.2.0" (@name "wasi:cli/environment@0.2.0") (;3;) (instantiate $wit-component:adapter:wasi:cli/environment@0.2.0))
(alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;)))
(alias core export $"#core-instance3 wasi:cli/environment@0.2.0" "get-environment" (core func $get-environment (;1;)))
(core instance $fixup-args (;4;)
(export "$imports" (table $"shim table"))
(export "0" (func $get-environment))
)
(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 {
}

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