* Move `CompiledFunction` into wasmtime-cranelift This commit moves the `wasmtime_environ::CompiledFunction` type into the `wasmtime-cranelift` crate. This type has lots of Cranelift-specific pieces of compilation and doesn't need to be generated by all Wasmtime compilers. This replaces the usage in the `Compiler` trait with a `Box<Any>` type that each compiler can select. Each compiler must still produce a `FunctionInfo`, however, which is shared information we'll deserialize for each module. The `wasmtime-debug` crate is also folded into the `wasmtime-cranelift` crate as a result of this commit. One possibility was to move the `CompiledFunction` commit into its own crate and have `wasmtime-debug` depend on that, but since `wasmtime-debug` is Cranelift-specific at this time it didn't seem like it was too too necessary to keep it separate. If `wasmtime-debug` supports other backends in the future we can recreate a new crate, perhaps with it refactored to not depend on Cranelift. * Move wasmtime_environ::reference_type This now belongs in wasmtime-cranelift and nowhere else * Remove `Type` reexport in wasmtime-environ One less dependency on `cranelift-codegen`! * Remove `types` reexport from `wasmtime-environ` Less cranelift! * Remove `SourceLoc` from wasmtime-environ Change the `srcloc`, `start_srcloc`, and `end_srcloc` fields to a custom `FilePos` type instead of `ir::SourceLoc`. These are only used in a few places so there's not much to lose from an extra abstraction for these leaf use cases outside of cranelift. * Remove wasmtime-environ's dep on cranelift's `StackMap` This commit "clones" the `StackMap` data structure in to `wasmtime-environ` to have an independent representation that that chosen by Cranelift. This allows Wasmtime to decouple this runtime dependency of stack map information and let the two evolve independently, if necessary. An alternative would be to refactor cranelift's implementation into a separate crate and have wasmtime depend on that but it seemed a bit like overkill to do so and easier to clone just a few lines for this. * Define code offsets in wasmtime-environ with `u32` Don't use Cranelift's `binemit::CodeOffset` alias to define this field type since the `wasmtime-environ` crate will be losing the `cranelift-codegen` dependency soon. * Commit to using `cranelift-entity` in Wasmtime This commit removes the reexport of `cranelift-entity` from the `wasmtime-environ` crate and instead directly depends on the `cranelift-entity` crate in all referencing crates. The original reason for the reexport was to make cranelift version bumps easier since it's less versions to change, but nowadays we have a script to do that. Otherwise this encourages crates to use whatever they want from `cranelift-entity` since we'll always depend on the whole crate. It's expected that the `cranelift-entity` crate will continue to be a lean crate in dependencies and suitable for use at both runtime and compile time. Consequently there's no need to avoid its usage in Wasmtime at runtime, since "remove Cranelift at compile time" is primarily about the `cranelift-codegen` crate. * Remove most uses of `cranelift-codegen` in `wasmtime-environ` There's only one final use remaining, which is the reexport of `TrapCode`, which will get handled later. * Limit the glob-reexport of `cranelift_wasm` This commit removes the glob reexport of `cranelift-wasm` from the `wasmtime-environ` crate. This is intended to explicitly define what we're reexporting and is a transitionary step to curtail the amount of dependencies taken on `cranelift-wasm` throughout the codebase. For example some functions used by debuginfo mapping are better imported directly from the crate since they're Cranelift-specific. Note that this is intended to be a temporary state affairs, soon this reexport will be gone entirely. Additionally this commit reduces imports from `cranelift_wasm` and also primarily imports from `crate::wasm` within `wasmtime-environ` to get a better sense of what's imported from where and what will need to be shared. * Extract types from cranelift-wasm to cranelift-wasm-types This commit creates a new crate called `cranelift-wasm-types` and extracts type definitions from the `cranelift-wasm` crate into this new crate. The purpose of this crate is to be a shared definition of wasm types that can be shared both by compilers (like Cranelift) as well as wasm runtimes (e.g. Wasmtime). This new `cranelift-wasm-types` crate doesn't depend on `cranelift-codegen` and is the final step in severing the unconditional dependency from Wasmtime to `cranelift-codegen`. The final refactoring in this commit is to then reexport this crate from `wasmtime-environ`, delete the `cranelift-codegen` dependency, and then update all `use` paths to point to these new types. The main change of substance here is that the `TrapCode` enum is mirrored from Cranelift into this `cranelift-wasm-types` crate. While this unfortunately results in three definitions (one more which is non-exhaustive in Wasmtime itself) it's hopefully not too onerous and ideally something we can patch up in the future. * Get lightbeam compiling * Remove unnecessary dependency * Fix compile with uffd * Update publish script * Fix more uffd tests * Rename cranelift-wasm-types to wasmtime-types This reflects the purpose a bit more where it's types specifically intended for Wasmtime and its support. * Fix publish script
107 lines
3.0 KiB
Rust
107 lines
3.0 KiB
Rust
use crate::vmcontext::{
|
|
VMCallerCheckedAnyfunc, VMContext, VMGlobalDefinition, VMMemoryDefinition, VMTableDefinition,
|
|
};
|
|
use std::ptr::NonNull;
|
|
use wasmtime_environ::{Global, MemoryPlan, TablePlan};
|
|
|
|
/// The value of an export passed from one instance to another.
|
|
pub enum Export {
|
|
/// A function export value.
|
|
Function(ExportFunction),
|
|
|
|
/// A table export value.
|
|
Table(ExportTable),
|
|
|
|
/// A memory export value.
|
|
Memory(ExportMemory),
|
|
|
|
/// A global export value.
|
|
Global(ExportGlobal),
|
|
}
|
|
|
|
/// A function export value.
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct ExportFunction {
|
|
/// The `VMCallerCheckedAnyfunc` for this exported function.
|
|
///
|
|
/// Note that exported functions cannot be a null funcref, so this is a
|
|
/// non-null pointer.
|
|
pub anyfunc: NonNull<VMCallerCheckedAnyfunc>,
|
|
}
|
|
|
|
// It's part of the contract of using `ExportFunction` that synchronization
|
|
// properties are upheld, so declare that despite the raw pointers inside this
|
|
// is send/sync.
|
|
unsafe impl Send for ExportFunction {}
|
|
unsafe impl Sync for ExportFunction {}
|
|
|
|
impl From<ExportFunction> for Export {
|
|
fn from(func: ExportFunction) -> Export {
|
|
Export::Function(func)
|
|
}
|
|
}
|
|
|
|
/// A table export value.
|
|
#[derive(Debug, Clone)]
|
|
pub struct ExportTable {
|
|
/// The address of the table descriptor.
|
|
pub definition: *mut VMTableDefinition,
|
|
/// Pointer to the containing `VMContext`.
|
|
pub vmctx: *mut VMContext,
|
|
/// The table declaration, used for compatibilty checking.
|
|
pub table: TablePlan,
|
|
}
|
|
|
|
// See docs on send/sync for `ExportFunction` above.
|
|
unsafe impl Send for ExportTable {}
|
|
unsafe impl Sync for ExportTable {}
|
|
|
|
impl From<ExportTable> for Export {
|
|
fn from(func: ExportTable) -> Export {
|
|
Export::Table(func)
|
|
}
|
|
}
|
|
|
|
/// A memory export value.
|
|
#[derive(Debug, Clone)]
|
|
pub struct ExportMemory {
|
|
/// The address of the memory descriptor.
|
|
pub definition: *mut VMMemoryDefinition,
|
|
/// Pointer to the containing `VMContext`.
|
|
pub vmctx: *mut VMContext,
|
|
/// The memory declaration, used for compatibilty checking.
|
|
pub memory: MemoryPlan,
|
|
}
|
|
|
|
// See docs on send/sync for `ExportFunction` above.
|
|
unsafe impl Send for ExportMemory {}
|
|
unsafe impl Sync for ExportMemory {}
|
|
|
|
impl From<ExportMemory> for Export {
|
|
fn from(func: ExportMemory) -> Export {
|
|
Export::Memory(func)
|
|
}
|
|
}
|
|
|
|
/// A global export value.
|
|
#[derive(Debug, Clone)]
|
|
pub struct ExportGlobal {
|
|
/// The address of the global storage.
|
|
pub definition: *mut VMGlobalDefinition,
|
|
/// Pointer to a `VMContext` which has a lifetime at least as long as the
|
|
/// global. This may not be the `VMContext` which defines the global.
|
|
pub vmctx: *mut VMContext,
|
|
/// The global declaration, used for compatibilty checking.
|
|
pub global: Global,
|
|
}
|
|
|
|
// See docs on send/sync for `ExportFunction` above.
|
|
unsafe impl Send for ExportGlobal {}
|
|
unsafe impl Sync for ExportGlobal {}
|
|
|
|
impl From<ExportGlobal> for Export {
|
|
fn from(func: ExportGlobal) -> Export {
|
|
Export::Global(func)
|
|
}
|
|
}
|