Remove dependency on TargetIsa from Wasmtime crates (#3178)
This commit started off by deleting the `cranelift_codegen::settings` reexport in the `wasmtime-environ` crate and then basically played whack-a-mole until everything compiled again. The main result of this is that the `wasmtime-*` family of crates have generally less of a dependency on the `TargetIsa` trait and type from Cranelift. While the dependency isn't entirely severed yet this is at least a significant start. This commit is intended to be largely refactorings, no functional changes are intended here. The refactorings are: * A `CompilerBuilder` trait has been added to `wasmtime_environ` which server as an abstraction used to create compilers and configure them in a uniform fashion. The `wasmtime::Config` type now uses this instead of cranelift-specific settings. The `wasmtime-jit` crate exports the ability to create a compiler builder from a `CompilationStrategy`, which only works for Cranelift right now. In a cranelift-less build of Wasmtime this is expected to return a trait object that fails all requests to compile. * The `Compiler` trait in the `wasmtime_environ` crate has been souped up with a number of methods that Wasmtime and other crates needed. * The `wasmtime-debug` crate is now moved entirely behind the `wasmtime-cranelift` crate. * The `wasmtime-cranelift` crate is now only depended on by the `wasmtime-jit` crate. * Wasm types in `cranelift-wasm` no longer contain their IR type, instead they only contain the `WasmType`. This is required to get everything to align correctly but will also be required in a future refactoring where the types used by `cranelift-wasm` will be extracted to a separate crate. * I moved around a fair bit of code in `wasmtime-cranelift`. * Some gdb-specific jit-specific code has moved from `wasmtime-debug` to `wasmtime-jit`.
This commit is contained in:
@@ -8,7 +8,7 @@ use anyhow::{bail, Result};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::ops::Range;
|
||||
use std::ptr;
|
||||
use wasmtime_environ::wasm::TableElementType;
|
||||
use wasmtime_environ::wasm::WasmType;
|
||||
use wasmtime_environ::{ir, TablePlan};
|
||||
|
||||
/// An element going into or coming out of a table.
|
||||
@@ -22,6 +22,12 @@ pub enum TableElement {
|
||||
ExternRef(Option<VMExternRef>),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum TableElementType {
|
||||
Func,
|
||||
Extern,
|
||||
}
|
||||
|
||||
// The usage of `*mut VMCallerCheckedAnyfunc` is safe w.r.t. thread safety, this
|
||||
// just relies on thread-safety of `VMExternRef` itself.
|
||||
unsafe impl Send for TableElement where VMExternRef: Send {}
|
||||
@@ -38,7 +44,7 @@ impl TableElement {
|
||||
unsafe fn from_raw(ty: TableElementType, ptr: usize) -> Self {
|
||||
match ty {
|
||||
TableElementType::Func => Self::FuncRef(ptr as _),
|
||||
TableElementType::Val(_) => Self::ExternRef(if ptr == 0 {
|
||||
TableElementType::Extern => Self::ExternRef(if ptr == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(VMExternRef::from_raw(ptr as *mut u8))
|
||||
@@ -54,7 +60,7 @@ impl TableElement {
|
||||
unsafe fn clone_from_raw(ty: TableElementType, ptr: usize) -> Self {
|
||||
match ty {
|
||||
TableElementType::Func => Self::FuncRef(ptr as _),
|
||||
TableElementType::Val(_) => Self::ExternRef(if ptr == 0 {
|
||||
TableElementType::Extern => Self::ExternRef(if ptr == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(VMExternRef::clone_from_raw(ptr as *mut u8))
|
||||
@@ -122,6 +128,14 @@ pub enum Table {
|
||||
},
|
||||
}
|
||||
|
||||
fn wasm_to_table_type(ty: WasmType) -> Result<TableElementType> {
|
||||
match ty {
|
||||
WasmType::FuncRef => Ok(TableElementType::Func),
|
||||
WasmType::ExternRef => Ok(TableElementType::Extern),
|
||||
ty => bail!("invalid table element type {:?}", ty),
|
||||
}
|
||||
}
|
||||
|
||||
impl Table {
|
||||
/// Create a new dynamic (movable) table instance for the specified table plan.
|
||||
pub fn new_dynamic(
|
||||
@@ -130,7 +144,7 @@ impl Table {
|
||||
) -> Result<Self> {
|
||||
Self::limit_new(plan, limiter)?;
|
||||
let elements = vec![0; plan.table.minimum as usize];
|
||||
let ty = plan.table.ty.clone();
|
||||
let ty = wasm_to_table_type(plan.table.wasm_ty)?;
|
||||
let maximum = plan.table.maximum;
|
||||
|
||||
Ok(Table::Dynamic {
|
||||
@@ -148,7 +162,7 @@ impl Table {
|
||||
) -> Result<Self> {
|
||||
Self::limit_new(plan, limiter)?;
|
||||
let size = plan.table.minimum;
|
||||
let ty = plan.table.ty.clone();
|
||||
let ty = wasm_to_table_type(plan.table.wasm_ty)?;
|
||||
let data = match plan.table.maximum {
|
||||
Some(max) if (max as usize) < data.len() => &mut data[..max as usize],
|
||||
_ => data,
|
||||
@@ -403,7 +417,7 @@ impl Table {
|
||||
fn type_matches(&self, val: &TableElement) -> bool {
|
||||
match (&val, self.element_type()) {
|
||||
(TableElement::FuncRef(_), TableElementType::Func) => true,
|
||||
(TableElement::ExternRef(_), TableElementType::Val(_)) => true,
|
||||
(TableElement::ExternRef(_), TableElementType::Extern) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -449,7 +463,7 @@ impl Table {
|
||||
dst_table.elements_mut()[dst_range]
|
||||
.copy_from_slice(&src_table.elements()[src_range]);
|
||||
}
|
||||
TableElementType::Val(_) => {
|
||||
TableElementType::Extern => {
|
||||
// We need to clone each `externref`
|
||||
let dst = dst_table.elements_mut();
|
||||
let src = src_table.elements();
|
||||
@@ -469,7 +483,7 @@ impl Table {
|
||||
// `funcref` are `Copy`, so just do a memmove
|
||||
dst.copy_within(src_range, dst_range.start);
|
||||
}
|
||||
TableElementType::Val(_) => {
|
||||
TableElementType::Extern => {
|
||||
// We need to clone each `externref` while handling overlapping
|
||||
// ranges
|
||||
if dst_range.start <= src_range.start {
|
||||
|
||||
Reference in New Issue
Block a user