Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtime-core) Support closures with a captured environment as host functions #925

Merged
merged 34 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
177c507
feat(runtime-core) Introduce `vm::FuncCtx`.
Hywan Oct 31, 2019
e002c37
feat(runtime-core) `vm::ImportedFunc` and `vm::FuncCtx` have `NonNull…
Hywan Nov 4, 2019
6035bd2
feat(runtime-core,clif-backend,llvm-backend) Rename an `ImportFunc` o…
Hywan Nov 4, 2019
0e27f2f
test(runtime-core) Test more host functions as closures.
Hywan Nov 4, 2019
2a041f8
!temp
Hywan Nov 4, 2019
3b34a91
chore(runtime-core) Remove `dbg!`.
Hywan Nov 4, 2019
a52b4b2
test(runtime-core) Test closures with a captured environment.
Hywan Nov 4, 2019
3435ce4
test(runtime-core) Extract `assert` as tests.
Hywan Nov 4, 2019
81326ce
doc(runtime-core) Write more documentation.
Hywan Nov 4, 2019
0f82cd3
doc(runtime-core) Write more documentation.
Hywan Nov 4, 2019
293b71a
doc(runtime-core) Write more documentation.
Hywan Nov 4, 2019
a9e0e9b
test(runtime-core) Write more documentation.
Hywan Nov 4, 2019
215e445
Merge branch 'master' into feat-runtime-core-clos-host-function
Hywan Nov 4, 2019
a4ba429
feat(singlepass-backend) Inject `FuncCtx` to the function pointer of …
Hywan Nov 5, 2019
c4c88f8
fix(runtime-core) Remove undefined behavior with `mem::transmute`.
Hywan Nov 6, 2019
5ccaf12
doc(runtime-core) Fix inline documentations.
Hywan Nov 6, 2019
6f84a6f
test(runtime-core) Remove a warning in tests.
Hywan Nov 6, 2019
cf74b68
Merge branch 'master' into feat-runtime-core-clos-host-function
Hywan Nov 6, 2019
ac8aece
doc(changelog) Add #915, #917 and #925.
Hywan Nov 6, 2019
dfaad35
fix(spectests) Remove a warning.
Hywan Nov 7, 2019
2e05104
fix(runtime-core) Introduce `Context::ExternalWithEnv`.
Hywan Nov 7, 2019
ba87af5
feat(runtime-core) Ability for an export function to get a func env.
Hywan Nov 7, 2019
98e4ef0
feat(runtime-core) Feed imported functions with `vm::Ctx` again.
Hywan Nov 11, 2019
11f34a9
feat(clif-backend,singlepass-backend) Feed imported functions with `F…
Hywan Nov 11, 2019
06c6b3c
feat(runtime-core) More ABI compatible definition of `Func` and `Func…
Hywan Nov 11, 2019
bb81614
feat(llvm-backend) Update `ImportedFunc` structure.
Hywan Nov 11, 2019
9570616
Merge branch 'master' into feat-runtime-core-clos-host-function
Hywan Nov 11, 2019
f002f03
chore(changelog) Fix CS.
Hywan Nov 11, 2019
cf33bf8
Merge branch 'master' into feat-runtime-core-clos-host-function
Hywan Nov 11, 2019
22abd8e
doc(runtime-core) Add missing doc on `vm::FuncCtx`.
Hywan Nov 12, 2019
0de7f4f
test(runtime-core) `offset_of!` fails with a struct containing `NonNu…
Hywan Nov 12, 2019
89859a9
Merge branch 'master' into feat-runtime-core-clos-host-function
Hywan Nov 12, 2019
5d6c74b
doc(changelog) Fix last release number, and fix CS.
Hywan Nov 12, 2019
a1e8a8f
fix(runtime-core) Same bug with `field-offset` as before.
Hywan Nov 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## **[Unreleased]**

- [#925](https://github.com/wasmerio/wasmer/pull/925) Host functions can be closures with a captured environment.
- [#917](https://github.com/wasmerio/wasmer/pull/917) Host functions (aka imported functions) may not have `&mut vm::Ctx` as first argument, i.e. the presence of the `&mut vm::Ctx` argument is optional.
- [#915](https://github.com/wasmerio/wasmer/pull/915) All backends share the same definition of `Trampoline` (defined in `wasmer-runtime-core`).
- [#921](https://github.com/wasmerio/wasmer/pull/921) In LLVM backend, annotate all memory accesses with TBAA metadata.
- [#883](https://github.com/wasmerio/wasmer/pull/883) Allow floating point operations to have arbitrary inputs, even including SNaNs.
- [#856](https://github.com/wasmerio/wasmer/pull/856) Expose methods in the runtime C API to get a WASI import object
Expand Down
18 changes: 10 additions & 8 deletions lib/clif-backend/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,20 +763,22 @@ impl FuncEnvironment for FunctionEnvironment {
readonly: true,
});

let imported_vmctx_addr = pos.func.create_global_value(ir::GlobalValueData::Load {
base: imported_func_struct_addr,
offset: (vm::ImportedFunc::offset_vmctx() as i32).into(),
global_type: ptr_type,
readonly: true,
});
let imported_func_ctx_addr =
pos.func.create_global_value(ir::GlobalValueData::Load {
base: imported_func_struct_addr,
offset: (vm::ImportedFunc::offset_func_ctx() as i32).into(),
global_type: ptr_type,
readonly: true,
});

let imported_func_addr = pos.ins().global_value(ptr_type, imported_func_addr);
let imported_vmctx_addr = pos.ins().global_value(ptr_type, imported_vmctx_addr);
let imported_func_ctx_addr =
pos.ins().global_value(ptr_type, imported_func_ctx_addr);

let sig_ref = pos.func.dfg.ext_funcs[callee].signature;

let mut args = Vec::with_capacity(call_args.len() + 1);
args.push(imported_vmctx_addr);
args.push(imported_func_ctx_addr);
args.extend(call_args.iter().cloned());

Ok(pos
Expand Down
2 changes: 1 addition & 1 deletion lib/llvm-backend/src/stackmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl StackmapEntry {
ValueSemantic::ImportedFuncCtx(idx) => MachineValue::VmctxDeref(vec![
Ctx::offset_imported_funcs() as usize,
vm::ImportedFunc::size() as usize * idx
+ vm::ImportedFunc::offset_vmctx() as usize,
+ vm::ImportedFunc::offset_func_ctx() as usize,
0,
]),
ValueSemantic::DynamicSigindice(idx) => {
Expand Down
Loading