Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Improve compile option for disabling the continuation linearity check. (
Browse files Browse the repository at this point in the history
#47)

* Improve compile option for disabling the continuation linearity check.

This patch improves upon #42. In addition it renames the flag, so to build a compiler & runtime without linearity checking one has to supply the following:

```shell
$ cargo build --features=default,unsafe_disable_continuation_linearity_check
```
  • Loading branch information
dhil authored Jul 13, 2023
1 parent 3cb2dda commit ea8b1a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ winch = ["wasmtime/winch"]
# may otherwise run out of memory.
# Note that enabling this is highly unsafe, as it makes it impossible to detect
# at runtime when an already taken continuation is used again.
use_contobj_as_contref = []
unsafe_disable_continuation_linearity_check = [
"wasmtime-cranelift/unsafe_disable_continuation_linearity_check",
"wasmtime-runtime/unsafe_disable_continuation_linearity_check"
]

[[test]]
name = "host_segfault"
Expand Down
1 change: 1 addition & 0 deletions crates/cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ thiserror = { workspace = true }
all-arch = ["cranelift-codegen/all-arch"]
component-model = ["wasmtime-environ/component-model"]
incremental-cache = ["cranelift-codegen/incremental-cache"]
unsafe_disable_continuation_linearity_check = []
4 changes: 2 additions & 2 deletions crates/cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
builder: &mut FunctionBuilder,
contref: ir::Value,
) -> ir::Value {
if cfg!(feature = "use_contobj_as_contref") {
if cfg!(feature = "unsafe_disable_continuation_linearity_check") {
// The "contref" is a contobj already
return contref;
} else {
Expand Down Expand Up @@ -2550,7 +2550,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
builder: &mut FunctionBuilder,
contobj_addr: ir::Value,
) -> ir::Value {
if cfg!(feature = "use_contobj_as_contref") {
if cfg!(feature = "unsafe_disable_continuation_linearity_check") {
return contobj_addr;
} else {
let (_vmctx, contref) =
Expand Down
2 changes: 2 additions & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ component-model = [
"wasmtime-environ/component-model",
"dep:encoding_rs",
]

unsafe_disable_continuation_linearity_check = []
8 changes: 6 additions & 2 deletions crates/runtime/src/continuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ pub fn cont_ref_get_cont_obj(
//FIXME rename to indicate that this invalidates the cont ref

// If this is enabled, we should never call this function.
assert!(!cfg!(feature = "use_contobj_as_contref"));
assert!(!cfg!(
feature = "unsafe_disable_continuation_linearity_check"
));

let contopt = unsafe { contref.as_mut().unwrap().0 };
match contopt {
Expand Down Expand Up @@ -186,7 +188,9 @@ pub fn cont_obj_has_state_invoked(obj: *mut ContinuationObject) -> bool {
#[inline(always)]
pub fn new_cont_ref(contobj: *mut ContinuationObject) -> *mut ContinuationReference {
// If this is enabled, we should never call this function.
assert!(!cfg!(feature = "use_contobj_as_contref"));
assert!(!cfg!(
feature = "unsafe_disable_continuation_linearity_check"
));

let contref = Box::new(ContinuationReference(Some(contobj)));
Box::into_raw(contref)
Expand Down

0 comments on commit ea8b1a7

Please sign in to comment.