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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(runtime-core,clif-backend,llvm-backend) Rename an ImportFunc o…
…ffset.

`ImportedFunc::offset_vmctx` becomes `ImportedFunc::offset_func_ctx`.
  • Loading branch information
Hywan committed Nov 6, 2019
commit 6035bd2d9be80c51b169954af206bb3ab4d5887f
18 changes: 10 additions & 8 deletions lib/clif-backend/src/code.rs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/llvm-backend/src/stackmap.rs
Original file line number Diff line number Diff line change
@@ -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) => {
10 changes: 6 additions & 4 deletions lib/runtime-core/src/vm.rs
Original file line number Diff line number Diff line change
@@ -524,7 +524,9 @@ pub struct ImportedFunc {
pub func_ctx: NonNull<FuncCtx>,
}

// manually implemented because ImportedFunc contains raw pointers directly; `Func` is marked Send (But `Ctx` actually isn't! (TODO: review this, shouldn't `Ctx` be Send?))
// manually implemented because ImportedFunc contains raw pointers
// directly; `Func` is marked Send (But `Ctx` actually isn't! (TODO:
// review this, shouldn't `Ctx` be Send?))
unsafe impl Send for ImportedFunc {}

impl ImportedFunc {
@@ -533,7 +535,7 @@ impl ImportedFunc {
0 * (mem::size_of::<usize>() as u8)
}

pub fn offset_vmctx() -> u8 {
pub fn offset_func_ctx() -> u8 {
1 * (mem::size_of::<usize>() as u8)
}

@@ -756,8 +758,8 @@ mod vm_offset_tests {
);

assert_eq!(
ImportedFunc::offset_vmctx() as usize,
offset_of!(ImportedFunc => vmctx).get_byte_offset(),
ImportedFunc::offset_func_ctx() as usize,
offset_of!(ImportedFunc => func_ctx).get_byte_offset(),
);
}