Skip to content

Commit

Permalink
Update Cranelift to 0.52.0 (#710)
Browse files Browse the repository at this point in the history
* Add unimplemented stubs for Cranelift interfaces

Cranelift changes to FuncEnvironment, TargetEnvironment, and GlobalInit (see bytecodealliance/cranelift#1073) require these changes to compile wasmtime.

* Upgrade Cranelift to 0.52.0
  • Loading branch information
abrown authored and yurydelendik committed Dec 31, 2019
1 parent 681445b commit 69683e8
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 39 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/environ/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ readme = "README.md"
edition = "2018"

[dependencies]
cranelift-codegen = { version = "0.50.0", features = ["enable-serde"] }
cranelift-entity = { version = "0.50.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.50.0", features = ["enable-serde"] }
cranelift-codegen = { version = "0.52.0", features = ["enable-serde"] }
cranelift-entity = { version = "0.52.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.52.0", features = ["enable-serde"] }
wasmparser = "0.45.0"
lightbeam = { path = "../lightbeam", optional = true }
indexmap = "1.0.2"
Expand Down Expand Up @@ -45,7 +45,7 @@ tempfile = "3"
target-lexicon = { version = "0.9.0", default-features = false }
pretty_env_logger = "0.3.0"
rand = { version = "0.7.0", default-features = false, features = ["small_rng"] }
cranelift-codegen = { version = "0.50.0", features = ["enable-serde", "all-arch"] }
cranelift-codegen = { version = "0.52.0", features = ["enable-serde", "all-arch"] }
filetime = "0.2.7"

[badges]
Expand Down
87 changes: 85 additions & 2 deletions crates/environ/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_entity::EntityRef;
use cranelift_wasm::{
self, FuncIndex, GlobalIndex, GlobalVariable, MemoryIndex, SignatureIndex, TableIndex,
WasmResult,
TargetEnvironment, WasmError, WasmResult,
};
#[cfg(feature = "lightbeam")]
use cranelift_wasm::{DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex};
Expand Down Expand Up @@ -355,11 +355,13 @@ impl lightbeam::ModuleContext for FuncEnvironment<'_> {
// TODO: type of a global
}

impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'module_environment> {
impl<'module_environment> TargetEnvironment for FuncEnvironment<'module_environment> {
fn target_config(&self) -> TargetFrontendConfig {
self.target_config
}
}

impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'module_environment> {
fn make_table(&mut self, func: &mut ir::Function, index: TableIndex) -> WasmResult<ir::Table> {
let pointer_type = self.pointer_type();

Expand Down Expand Up @@ -702,4 +704,85 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
.call_indirect(func_sig, func_addr, &[vmctx, memory_index]);
Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap())
}

fn translate_memory_copy(
&mut self,
_pos: FuncCursor,
_index: MemoryIndex,
_heap: ir::Heap,
_dst: ir::Value,
_src: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_memory_fill(
&mut self,
_pos: FuncCursor,
_index: MemoryIndex,
_heap: ir::Heap,
_dst: ir::Value,
_val: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_memory_init(
&mut self,
_pos: FuncCursor,
_index: MemoryIndex,
_heap: ir::Heap,
_seg_index: u32,
_dst: ir::Value,
_src: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_data_drop(&mut self, _pos: FuncCursor, _seg_index: u32) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_table_size(
&mut self,
_pos: FuncCursor,
_index: TableIndex,
_table: ir::Table,
) -> WasmResult<ir::Value> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_table_copy(
&mut self,
_pos: FuncCursor,
_dst_table_index: TableIndex,
_dst_table: ir::Table,
_src_table_index: TableIndex,
_src_table: ir::Table,
_dst: ir::Value,
_src: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_table_init(
&mut self,
_pos: FuncCursor,
_seg_index: u32,
_table_index: TableIndex,
_table: ir::Table,
_dst: ir::Value,
_src: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_elem_drop(&mut self, _pos: FuncCursor, _seg_index: u32) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}
}
10 changes: 6 additions & 4 deletions crates/environ/src/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_entity::PrimaryMap;
use cranelift_wasm::{
self, translate_module, DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex,
ModuleTranslationState, SignatureIndex, Table, TableIndex, WasmResult,
ModuleTranslationState, SignatureIndex, Table, TableIndex, TargetEnvironment, WasmResult,
};
use std::convert::TryFrom;

Expand Down Expand Up @@ -86,13 +86,15 @@ impl<'data> ModuleEnvironment<'data> {
}
}

/// This trait is useful for `translate_module` because it tells how to translate
/// environment-dependent wasm instructions. These functions should not be called by the user.
impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data> {
impl<'data> TargetEnvironment for ModuleEnvironment<'data> {
fn target_config(&self) -> TargetFrontendConfig {
self.result.target_config
}
}

/// This trait is useful for `translate_module` because it tells how to translate
/// environment-dependent wasm instructions. These functions should not be called by the user.
impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data> {
fn reserve_signatures(&mut self, num: u32) -> WasmResult<()> {
self.result
.module
Expand Down
10 changes: 5 additions & 5 deletions crates/jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ readme = "README.md"
edition = "2018"

[dependencies]
cranelift-codegen = { version = "0.50.0", features = ["enable-serde"] }
cranelift-entity = { version = "0.50.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.50.0", features = ["enable-serde"] }
cranelift-native = "0.50.0"
cranelift-frontend = "0.50.0"
cranelift-codegen = { version = "0.52.0", features = ["enable-serde"] }
cranelift-entity = { version = "0.52.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.52.0", features = ["enable-serde"] }
cranelift-native = "0.52.0"
cranelift-frontend = "0.52.0"
wasmtime-environ = { path = "../environ" }
wasmtime-runtime = { path = "../runtime" }
wasmtime-debug = { path = "../debug" }
Expand Down
2 changes: 1 addition & 1 deletion crates/lightbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ memoffset = "0.5.3"
itertools = "0.8.2"
capstone = "0.6.0"
thiserror = "1.0.9"
cranelift-codegen = "0.50.0"
cranelift-codegen = "0.52.0"
multi_mut = "0.1"
either = "1.5"
typemap = "0.3"
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ fn initialize_globals(instance: &mut Instance) {
unsafe { *to = *from };
}
GlobalInit::Import => panic!("locally-defined global initialized as import"),
GlobalInit::RefNullConst => unimplemented!(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/wasi-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ edition = "2018"
wasmtime-runtime = { path = "../runtime" }
wasmtime-environ = { path = "../environ" }
wasmtime-jit = { path = "../jit" }
cranelift-codegen = { version = "0.50.0", features = ["enable-serde"] }
cranelift-entity = { version = "0.50.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.50.0", features = ["enable-serde"] }
cranelift-codegen = { version = "0.52.0", features = ["enable-serde"] }
cranelift-entity = { version = "0.52.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.52.0", features = ["enable-serde"] }
target-lexicon = "0.9.0"
log = { version = "0.4.8", default-features = false }
libc = "0.2.60"
Expand Down
6 changes: 3 additions & 3 deletions crates/wasi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ wasmtime-runtime = { path = "../runtime" }
wasmtime-environ = { path = "../environ" }
wasmtime-jit = { path = "../jit" }
wasi-common = { path = "../wasi-common" }
cranelift-codegen = { version = "0.50.0", features = ["enable-serde"] }
cranelift-entity = { version = "0.50.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.50.0", features = ["enable-serde"] }
cranelift-codegen = { version = "0.52.0", features = ["enable-serde"] }
cranelift-entity = { version = "0.52.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.52.0", features = ["enable-serde"] }
target-lexicon = "0.9.0"
log = { version = "0.4.8", default-features = false }
wig = { path = "../wasi-common/wig" }
Expand Down

0 comments on commit 69683e8

Please sign in to comment.