Remove wasmtime-environ's dependency on cranelift-codegen (#3199)
* 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
This commit is contained in:
@@ -368,10 +368,7 @@ impl Global {
|
||||
Global(store.store_data_mut().insert(wasmtime_export))
|
||||
}
|
||||
|
||||
pub(crate) fn wasmtime_ty<'a>(
|
||||
&self,
|
||||
data: &'a StoreData,
|
||||
) -> &'a wasmtime_environ::wasm::Global {
|
||||
pub(crate) fn wasmtime_ty<'a>(&self, data: &'a StoreData) -> &'a wasmtime_environ::Global {
|
||||
&data[self.0].global
|
||||
}
|
||||
|
||||
@@ -651,7 +648,7 @@ impl Table {
|
||||
Table(store.store_data_mut().insert(wasmtime_export))
|
||||
}
|
||||
|
||||
pub(crate) fn wasmtime_ty<'a>(&self, data: &'a StoreData) -> &'a wasmtime_environ::wasm::Table {
|
||||
pub(crate) fn wasmtime_ty<'a>(&self, data: &'a StoreData) -> &'a wasmtime_environ::Table {
|
||||
&data[self.0].table.table
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ use std::pin::Pin;
|
||||
use std::ptr::NonNull;
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::wasm::{EntityIndex, FuncIndex};
|
||||
use wasmtime_environ::{EntityIndex, FuncIndex};
|
||||
use wasmtime_runtime::{
|
||||
raise_user_trap, ExportFunction, InstanceAllocator, InstanceHandle, OnDemandInstanceAllocator,
|
||||
VMCallerCheckedAnyfunc, VMContext, VMFunctionBody, VMFunctionImport, VMSharedSignatureIndex,
|
||||
@@ -1135,7 +1135,7 @@ fn enter_wasm<T>(store: &mut StoreContextMut<'_, T>) -> Result<Option<usize>, Tr
|
||||
interrupts.stack_limit.store(usize::max_value(), Relaxed);
|
||||
return Err(Trap::new_wasm(
|
||||
None,
|
||||
wasmtime_environ::ir::TrapCode::Interrupt,
|
||||
wasmtime_environ::TrapCode::Interrupt,
|
||||
backtrace::Backtrace::new_unresolved(),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -9,12 +9,10 @@ use crate::{
|
||||
use anyhow::{anyhow, bail, Context, Error, Result};
|
||||
use std::mem;
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::entity::PrimaryMap;
|
||||
use wasmtime_environ::wasm::{
|
||||
EntityIndex, EntityType, FuncIndex, GlobalIndex, InstanceIndex, MemoryIndex, ModuleIndex,
|
||||
TableIndex,
|
||||
use wasmtime_environ::{
|
||||
EntityIndex, EntityType, FuncIndex, GlobalIndex, Initializer, InstanceIndex, MemoryIndex,
|
||||
ModuleIndex, PrimaryMap, TableIndex,
|
||||
};
|
||||
use wasmtime_environ::Initializer;
|
||||
use wasmtime_jit::TypeTables;
|
||||
use wasmtime_runtime::{
|
||||
Imports, InstanceAllocationRequest, InstantiationError, VMContext, VMFunctionBody,
|
||||
|
||||
@@ -480,10 +480,7 @@ impl Memory {
|
||||
Memory(store.store_data_mut().insert(wasmtime_export))
|
||||
}
|
||||
|
||||
pub(crate) fn wasmtime_ty<'a>(
|
||||
&self,
|
||||
store: &'a StoreData,
|
||||
) -> &'a wasmtime_environ::wasm::Memory {
|
||||
pub(crate) fn wasmtime_ty<'a>(&self, store: &'a StoreData) -> &'a wasmtime_environ::Memory {
|
||||
&store[self.0].memory.memory
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ use std::sync::Arc;
|
||||
use wasmparser::Validator;
|
||||
#[cfg(feature = "cache")]
|
||||
use wasmtime_cache::ModuleCacheEntry;
|
||||
use wasmtime_environ::entity::PrimaryMap;
|
||||
use wasmtime_environ::wasm::ModuleIndex;
|
||||
use wasmtime_environ::{ModuleIndex, PrimaryMap};
|
||||
use wasmtime_jit::{CompilationArtifacts, CompiledModule, TypeTables};
|
||||
|
||||
mod registry;
|
||||
|
||||
@@ -6,10 +6,7 @@ use std::{
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use wasmtime_environ::{
|
||||
entity::EntityRef,
|
||||
ir::{self, StackMap},
|
||||
wasm::DefinedFuncIndex,
|
||||
FunctionAddressMap, TrapInformation,
|
||||
DefinedFuncIndex, EntityRef, FilePos, FunctionAddressMap, StackMap, TrapInformation,
|
||||
};
|
||||
use wasmtime_jit::CompiledModule;
|
||||
use wasmtime_runtime::{ModuleInfo, VMCallerCheckedAnyfunc, VMTrampoline};
|
||||
@@ -339,10 +336,9 @@ impl GlobalRegisteredModule {
|
||||
// though so we can omit this check in release mode.
|
||||
debug_assert!(pos.is_some(), "failed to find instruction for {:x}", pc);
|
||||
|
||||
let instr = match pos {
|
||||
Some(pos) => info.address_map.instructions[pos].srcloc,
|
||||
None => info.address_map.start_srcloc,
|
||||
};
|
||||
let instr = pos
|
||||
.map(|i| info.address_map.instructions[i].srcloc)
|
||||
.unwrap_or(info.address_map.start_srcloc);
|
||||
|
||||
// Use our wasm-relative pc to symbolize this frame. If there's a
|
||||
// symbolication context (dwarf debug info) available then we can try to
|
||||
@@ -355,23 +351,25 @@ impl GlobalRegisteredModule {
|
||||
let mut symbols = Vec::new();
|
||||
|
||||
if let Some(s) = &self.module.symbolize_context().ok().and_then(|c| c) {
|
||||
let to_lookup = (instr.bits() as u64) - s.code_section_offset();
|
||||
if let Ok(mut frames) = s.addr2line().find_frames(to_lookup) {
|
||||
while let Ok(Some(frame)) = frames.next() {
|
||||
symbols.push(FrameSymbol {
|
||||
name: frame
|
||||
.function
|
||||
.as_ref()
|
||||
.and_then(|l| l.raw_name().ok())
|
||||
.map(|s| s.to_string()),
|
||||
file: frame
|
||||
.location
|
||||
.as_ref()
|
||||
.and_then(|l| l.file)
|
||||
.map(|s| s.to_string()),
|
||||
line: frame.location.as_ref().and_then(|l| l.line),
|
||||
column: frame.location.as_ref().and_then(|l| l.column),
|
||||
});
|
||||
if let Some(offset) = instr.file_offset() {
|
||||
let to_lookup = u64::from(offset) - s.code_section_offset();
|
||||
if let Ok(mut frames) = s.addr2line().find_frames(to_lookup) {
|
||||
while let Ok(Some(frame)) = frames.next() {
|
||||
symbols.push(FrameSymbol {
|
||||
name: frame
|
||||
.function
|
||||
.as_ref()
|
||||
.and_then(|l| l.raw_name().ok())
|
||||
.map(|s| s.to_string()),
|
||||
file: frame
|
||||
.location
|
||||
.as_ref()
|
||||
.and_then(|l| l.file)
|
||||
.map(|s| s.to_string()),
|
||||
line: frame.location.as_ref().and_then(|l| l.line),
|
||||
column: frame.location.as_ref().and_then(|l| l.column),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,8 +411,8 @@ pub struct FrameInfo {
|
||||
module_name: Option<String>,
|
||||
func_index: u32,
|
||||
func_name: Option<String>,
|
||||
func_start: ir::SourceLoc,
|
||||
instr: ir::SourceLoc,
|
||||
func_start: FilePos,
|
||||
instr: FilePos,
|
||||
symbols: Vec<FrameSymbol>,
|
||||
}
|
||||
|
||||
@@ -464,7 +462,7 @@ impl FrameInfo {
|
||||
/// The offset here is the offset from the beginning of the original wasm
|
||||
/// module to the instruction that this frame points to.
|
||||
pub fn module_offset(&self) -> usize {
|
||||
self.instr.bits() as usize
|
||||
self.instr.file_offset().unwrap_or(u32::MAX) as usize
|
||||
}
|
||||
|
||||
/// Returns the offset from the original wasm module's function to this
|
||||
@@ -474,7 +472,10 @@ impl FrameInfo {
|
||||
/// function of this frame (within the wasm module) to the instruction this
|
||||
/// frame points to.
|
||||
pub fn func_offset(&self) -> usize {
|
||||
(self.instr.bits() - self.func_start.bits()) as usize
|
||||
match self.instr.file_offset() {
|
||||
Some(i) => (i - self.func_start.file_offset().unwrap()) as usize,
|
||||
None => u32::MAX as usize,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the debug symbols found, if any, for this function frame.
|
||||
|
||||
@@ -6,8 +6,7 @@ use std::{
|
||||
sync::RwLock,
|
||||
};
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
use wasmtime_environ::entity::PrimaryMap;
|
||||
use wasmtime_environ::wasm::{SignatureIndex, WasmFuncType};
|
||||
use wasmtime_environ::{PrimaryMap, SignatureIndex, WasmFuncType};
|
||||
use wasmtime_runtime::{VMSharedSignatureIndex, VMTrampoline};
|
||||
|
||||
/// Represents a collection of shared signatures.
|
||||
|
||||
@@ -16,7 +16,9 @@ use crate::{GlobalType, MemoryType, TableType, Val};
|
||||
use anyhow::Result;
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::{entity::PrimaryMap, wasm, Module};
|
||||
use wasmtime_environ::{
|
||||
DefinedFuncIndex, EntityIndex, GlobalIndex, MemoryIndex, Module, PrimaryMap, TableIndex,
|
||||
};
|
||||
use wasmtime_runtime::{
|
||||
Imports, InstanceAllocationRequest, InstanceAllocator, OnDemandInstanceAllocator,
|
||||
VMFunctionBody, VMFunctionImport, VMSharedSignatureIndex,
|
||||
@@ -25,7 +27,7 @@ use wasmtime_runtime::{
|
||||
fn create_handle(
|
||||
module: Module,
|
||||
store: &mut StoreOpaque<'_>,
|
||||
finished_functions: PrimaryMap<wasm::DefinedFuncIndex, *mut [VMFunctionBody]>,
|
||||
finished_functions: PrimaryMap<DefinedFuncIndex, *mut [VMFunctionBody]>,
|
||||
host_state: Box<dyn Any + Send + Sync>,
|
||||
func_imports: &[VMFunctionImport],
|
||||
shared_signature_id: Option<VMSharedSignatureIndex>,
|
||||
@@ -59,7 +61,7 @@ pub fn generate_global_export(
|
||||
val: Val,
|
||||
) -> Result<wasmtime_runtime::ExportGlobal> {
|
||||
let instance = create_global(store, gt, val)?;
|
||||
let idx = wasm::EntityIndex::Global(wasm::GlobalIndex::from_u32(0));
|
||||
let idx = EntityIndex::Global(GlobalIndex::from_u32(0));
|
||||
match store.instance(instance).lookup_by_declaration(&idx) {
|
||||
wasmtime_runtime::Export::Global(g) => Ok(g),
|
||||
_ => unreachable!(),
|
||||
@@ -71,7 +73,7 @@ pub fn generate_memory_export(
|
||||
m: &MemoryType,
|
||||
) -> Result<wasmtime_runtime::ExportMemory> {
|
||||
let instance = create_memory(store, m)?;
|
||||
let idx = wasm::EntityIndex::Memory(wasm::MemoryIndex::from_u32(0));
|
||||
let idx = EntityIndex::Memory(MemoryIndex::from_u32(0));
|
||||
match store.instance(instance).lookup_by_declaration(&idx) {
|
||||
wasmtime_runtime::Export::Memory(m) => Ok(m),
|
||||
_ => unreachable!(),
|
||||
@@ -83,7 +85,7 @@ pub fn generate_table_export(
|
||||
t: &TableType,
|
||||
) -> Result<wasmtime_runtime::ExportTable> {
|
||||
let instance = create_table(store, t)?;
|
||||
let idx = wasm::EntityIndex::Table(wasm::TableIndex::from_u32(0));
|
||||
let idx = EntityIndex::Table(TableIndex::from_u32(0));
|
||||
match store.instance(instance).lookup_by_declaration(&idx) {
|
||||
wasmtime_runtime::Export::Table(t) => Ok(t),
|
||||
_ => unreachable!(),
|
||||
|
||||
@@ -5,9 +5,7 @@ use anyhow::Result;
|
||||
use std::any::Any;
|
||||
use std::panic::{self, AssertUnwindSafe};
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::entity::PrimaryMap;
|
||||
use wasmtime_environ::wasm::SignatureIndex;
|
||||
use wasmtime_environ::{wasm, Module, ModuleType};
|
||||
use wasmtime_environ::{EntityIndex, Module, ModuleType, PrimaryMap, SignatureIndex};
|
||||
use wasmtime_jit::CodeMemory;
|
||||
use wasmtime_runtime::{
|
||||
Imports, InstanceAllocationRequest, InstanceAllocator, InstanceHandle,
|
||||
@@ -123,7 +121,7 @@ pub unsafe fn create_raw_function(
|
||||
let func_id = module.functions.push(sig_id);
|
||||
module
|
||||
.exports
|
||||
.insert(String::new(), wasm::EntityIndex::Function(func_id));
|
||||
.insert(String::new(), EntityIndex::Function(func_id));
|
||||
finished_functions.push(func);
|
||||
|
||||
Ok(
|
||||
|
||||
@@ -2,10 +2,8 @@ use crate::store::{InstanceId, StoreOpaque};
|
||||
use crate::trampoline::create_handle;
|
||||
use crate::{GlobalType, Mutability, Val};
|
||||
use anyhow::Result;
|
||||
use wasmtime_environ::entity::PrimaryMap;
|
||||
use wasmtime_environ::{
|
||||
wasm::{self, SignatureIndex},
|
||||
Module, ModuleType,
|
||||
EntityIndex, Global, GlobalInit, Module, ModuleType, PrimaryMap, SignatureIndex,
|
||||
};
|
||||
use wasmtime_runtime::VMFunctionImport;
|
||||
|
||||
@@ -15,26 +13,26 @@ pub fn create_global(store: &mut StoreOpaque<'_>, gt: &GlobalType, val: Val) ->
|
||||
let mut externref_init = None;
|
||||
let mut shared_signature_id = None;
|
||||
|
||||
let global = wasm::Global {
|
||||
let global = Global {
|
||||
wasm_ty: gt.content().to_wasm_type(),
|
||||
mutability: match gt.mutability() {
|
||||
Mutability::Const => false,
|
||||
Mutability::Var => true,
|
||||
},
|
||||
initializer: match val {
|
||||
Val::I32(i) => wasm::GlobalInit::I32Const(i),
|
||||
Val::I64(i) => wasm::GlobalInit::I64Const(i),
|
||||
Val::F32(f) => wasm::GlobalInit::F32Const(f),
|
||||
Val::F64(f) => wasm::GlobalInit::F64Const(f),
|
||||
Val::V128(i) => wasm::GlobalInit::V128Const(i.into()),
|
||||
Val::ExternRef(None) | Val::FuncRef(None) => wasm::GlobalInit::RefNullConst,
|
||||
Val::I32(i) => GlobalInit::I32Const(i),
|
||||
Val::I64(i) => GlobalInit::I64Const(i),
|
||||
Val::F32(f) => GlobalInit::F32Const(f),
|
||||
Val::F64(f) => GlobalInit::F64Const(f),
|
||||
Val::V128(i) => GlobalInit::V128Const(i.into()),
|
||||
Val::ExternRef(None) | Val::FuncRef(None) => GlobalInit::RefNullConst,
|
||||
Val::ExternRef(Some(x)) => {
|
||||
// There is no `GlobalInit` variant for using an existing
|
||||
// `externref` that isn't an import (because Wasm can't create
|
||||
// an `externref` by itself). Therefore, initialize the global
|
||||
// as null, and then monkey patch it after instantiation below.
|
||||
externref_init = Some(x);
|
||||
wasm::GlobalInit::RefNullConst
|
||||
GlobalInit::RefNullConst
|
||||
}
|
||||
Val::FuncRef(Some(f)) => {
|
||||
// Add a function import to the stub module, and then initialize
|
||||
@@ -51,7 +49,7 @@ pub fn create_global(store: &mut StoreOpaque<'_>, gt: &GlobalType, val: Val) ->
|
||||
.push(wasmtime_environ::Initializer::Import {
|
||||
name: "".into(),
|
||||
field: None,
|
||||
index: wasm::EntityIndex::Function(func_index),
|
||||
index: EntityIndex::Function(func_index),
|
||||
});
|
||||
|
||||
func_imports.push(VMFunctionImport {
|
||||
@@ -59,7 +57,7 @@ pub fn create_global(store: &mut StoreOpaque<'_>, gt: &GlobalType, val: Val) ->
|
||||
vmctx: f.vmctx,
|
||||
});
|
||||
|
||||
wasm::GlobalInit::RefFunc(func_index)
|
||||
GlobalInit::RefFunc(func_index)
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -67,7 +65,7 @@ pub fn create_global(store: &mut StoreOpaque<'_>, gt: &GlobalType, val: Val) ->
|
||||
let global_id = module.globals.push(global);
|
||||
module
|
||||
.exports
|
||||
.insert(String::new(), wasm::EntityIndex::Global(global_id));
|
||||
.insert(String::new(), EntityIndex::Global(global_id));
|
||||
let id = create_handle(
|
||||
module,
|
||||
store,
|
||||
@@ -79,7 +77,7 @@ pub fn create_global(store: &mut StoreOpaque<'_>, gt: &GlobalType, val: Val) ->
|
||||
|
||||
if let Some(x) = externref_init {
|
||||
let instance = store.instance(id);
|
||||
match instance.lookup_by_declaration(&wasm::EntityIndex::Global(global_id)) {
|
||||
match instance.lookup_by_declaration(&EntityIndex::Global(global_id)) {
|
||||
wasmtime_runtime::Export::Global(g) => unsafe {
|
||||
*(*g.definition).as_externref_mut() = Some(x.inner);
|
||||
},
|
||||
|
||||
@@ -5,8 +5,7 @@ use crate::MemoryType;
|
||||
use anyhow::{anyhow, Result};
|
||||
use std::convert::TryFrom;
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::entity::PrimaryMap;
|
||||
use wasmtime_environ::{wasm, MemoryPlan, MemoryStyle, Module, WASM_PAGE_SIZE};
|
||||
use wasmtime_environ::{EntityIndex, MemoryPlan, MemoryStyle, Module, PrimaryMap, WASM_PAGE_SIZE};
|
||||
use wasmtime_runtime::{RuntimeLinearMemory, RuntimeMemoryCreator, VMMemoryDefinition};
|
||||
|
||||
pub fn create_memory(store: &mut StoreOpaque<'_>, memory: &MemoryType) -> Result<InstanceId> {
|
||||
@@ -19,7 +18,7 @@ pub fn create_memory(store: &mut StoreOpaque<'_>, memory: &MemoryType) -> Result
|
||||
let memory_id = module.memory_plans.push(memory_plan);
|
||||
module
|
||||
.exports
|
||||
.insert(String::new(), wasm::EntityIndex::Memory(memory_id));
|
||||
.insert(String::new(), EntityIndex::Memory(memory_id));
|
||||
|
||||
create_handle(module, store, PrimaryMap::new(), Box::new(()), &[], None)
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ use crate::store::{InstanceId, StoreOpaque};
|
||||
use crate::trampoline::create_handle;
|
||||
use crate::TableType;
|
||||
use anyhow::Result;
|
||||
use wasmtime_environ::entity::PrimaryMap;
|
||||
use wasmtime_environ::{wasm, Module};
|
||||
use wasmtime_environ::{EntityIndex, Module, PrimaryMap};
|
||||
|
||||
pub fn create_table(store: &mut StoreOpaque<'_>, table: &TableType) -> Result<InstanceId> {
|
||||
let mut module = Module::new();
|
||||
@@ -15,7 +14,7 @@ pub fn create_table(store: &mut StoreOpaque<'_>, table: &TableType) -> Result<In
|
||||
// TODO: can this `exports.insert` get removed?
|
||||
module
|
||||
.exports
|
||||
.insert(String::new(), wasm::EntityIndex::Table(table_id));
|
||||
.insert(String::new(), EntityIndex::Table(table_id));
|
||||
|
||||
create_handle(module, store, PrimaryMap::new(), Box::new(()), &[], None)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::FrameInfo;
|
||||
use backtrace::Backtrace;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::ir;
|
||||
use wasmtime_environ::TrapCode as EnvTrapCode;
|
||||
|
||||
/// A struct representing an aborted instruction execution, with a message
|
||||
/// indicating the cause.
|
||||
@@ -88,21 +88,20 @@ pub enum TrapCode {
|
||||
}
|
||||
|
||||
impl TrapCode {
|
||||
/// Panics if `code` is `ir::TrapCode::User`.
|
||||
fn from_non_user(code: ir::TrapCode) -> Self {
|
||||
/// Panics if `code` is `EnvTrapCode::User`.
|
||||
fn from_non_user(code: EnvTrapCode) -> Self {
|
||||
match code {
|
||||
ir::TrapCode::StackOverflow => TrapCode::StackOverflow,
|
||||
ir::TrapCode::HeapOutOfBounds => TrapCode::MemoryOutOfBounds,
|
||||
ir::TrapCode::HeapMisaligned => TrapCode::HeapMisaligned,
|
||||
ir::TrapCode::TableOutOfBounds => TrapCode::TableOutOfBounds,
|
||||
ir::TrapCode::IndirectCallToNull => TrapCode::IndirectCallToNull,
|
||||
ir::TrapCode::BadSignature => TrapCode::BadSignature,
|
||||
ir::TrapCode::IntegerOverflow => TrapCode::IntegerOverflow,
|
||||
ir::TrapCode::IntegerDivisionByZero => TrapCode::IntegerDivisionByZero,
|
||||
ir::TrapCode::BadConversionToInteger => TrapCode::BadConversionToInteger,
|
||||
ir::TrapCode::UnreachableCodeReached => TrapCode::UnreachableCodeReached,
|
||||
ir::TrapCode::Interrupt => TrapCode::Interrupt,
|
||||
ir::TrapCode::User(_) => panic!("Called `TrapCode::from_non_user` with user code"),
|
||||
EnvTrapCode::StackOverflow => TrapCode::StackOverflow,
|
||||
EnvTrapCode::HeapOutOfBounds => TrapCode::MemoryOutOfBounds,
|
||||
EnvTrapCode::HeapMisaligned => TrapCode::HeapMisaligned,
|
||||
EnvTrapCode::TableOutOfBounds => TrapCode::TableOutOfBounds,
|
||||
EnvTrapCode::IndirectCallToNull => TrapCode::IndirectCallToNull,
|
||||
EnvTrapCode::BadSignature => TrapCode::BadSignature,
|
||||
EnvTrapCode::IntegerOverflow => TrapCode::IntegerOverflow,
|
||||
EnvTrapCode::IntegerDivisionByZero => TrapCode::IntegerDivisionByZero,
|
||||
EnvTrapCode::BadConversionToInteger => TrapCode::BadConversionToInteger,
|
||||
EnvTrapCode::UnreachableCodeReached => TrapCode::UnreachableCodeReached,
|
||||
EnvTrapCode::Interrupt => TrapCode::Interrupt,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,10 +174,10 @@ impl Trap {
|
||||
modules
|
||||
.lookup_trap_info(pc)
|
||||
.map(|info| info.trap_code)
|
||||
.unwrap_or(ir::TrapCode::StackOverflow)
|
||||
.unwrap_or(EnvTrapCode::StackOverflow)
|
||||
});
|
||||
if maybe_interrupted && code == ir::TrapCode::StackOverflow {
|
||||
code = ir::TrapCode::Interrupt;
|
||||
if maybe_interrupted && code == EnvTrapCode::StackOverflow {
|
||||
code = EnvTrapCode::Interrupt;
|
||||
}
|
||||
Trap::new_wasm(Some(pc), code, backtrace)
|
||||
}
|
||||
@@ -196,7 +195,7 @@ impl Trap {
|
||||
#[cold] // see Trap::new
|
||||
pub(crate) fn new_wasm(
|
||||
trap_pc: Option<usize>,
|
||||
code: ir::TrapCode,
|
||||
code: EnvTrapCode,
|
||||
backtrace: Backtrace,
|
||||
) -> Self {
|
||||
let code = TrapCode::from_non_user(code);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::fmt;
|
||||
use wasmtime_environ::wasm;
|
||||
use wasmtime_environ::wasm::{EntityType, WasmFuncType};
|
||||
use wasmtime_environ::{EntityType, Global, Memory, Table, WasmFuncType, WasmType};
|
||||
use wasmtime_jit::TypeTables;
|
||||
|
||||
pub(crate) mod matching;
|
||||
@@ -71,28 +70,28 @@ impl ValType {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn to_wasm_type(&self) -> wasm::WasmType {
|
||||
pub(crate) fn to_wasm_type(&self) -> WasmType {
|
||||
match self {
|
||||
Self::I32 => wasm::WasmType::I32,
|
||||
Self::I64 => wasm::WasmType::I64,
|
||||
Self::F32 => wasm::WasmType::F32,
|
||||
Self::F64 => wasm::WasmType::F64,
|
||||
Self::V128 => wasm::WasmType::V128,
|
||||
Self::FuncRef => wasm::WasmType::FuncRef,
|
||||
Self::ExternRef => wasm::WasmType::ExternRef,
|
||||
Self::I32 => WasmType::I32,
|
||||
Self::I64 => WasmType::I64,
|
||||
Self::F32 => WasmType::F32,
|
||||
Self::F64 => WasmType::F64,
|
||||
Self::V128 => WasmType::V128,
|
||||
Self::FuncRef => WasmType::FuncRef,
|
||||
Self::ExternRef => WasmType::ExternRef,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_wasm_type(ty: &wasm::WasmType) -> Self {
|
||||
pub(crate) fn from_wasm_type(ty: &WasmType) -> Self {
|
||||
match ty {
|
||||
wasm::WasmType::I32 => Self::I32,
|
||||
wasm::WasmType::I64 => Self::I64,
|
||||
wasm::WasmType::F32 => Self::F32,
|
||||
wasm::WasmType::F64 => Self::F64,
|
||||
wasm::WasmType::V128 => Self::V128,
|
||||
wasm::WasmType::FuncRef => Self::FuncRef,
|
||||
wasm::WasmType::ExternRef => Self::ExternRef,
|
||||
wasm::WasmType::ExnRef => unimplemented!(),
|
||||
WasmType::I32 => Self::I32,
|
||||
WasmType::I64 => Self::I64,
|
||||
WasmType::F32 => Self::F32,
|
||||
WasmType::F64 => Self::F64,
|
||||
WasmType::V128 => Self::V128,
|
||||
WasmType::FuncRef => Self::FuncRef,
|
||||
WasmType::ExternRef => Self::ExternRef,
|
||||
WasmType::ExnRef => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,10 +153,7 @@ impl ExternType {
|
||||
(Instance(InstanceType) instance unwrap_instance)
|
||||
}
|
||||
|
||||
pub(crate) fn from_wasmtime(
|
||||
types: &TypeTables,
|
||||
ty: &wasmtime_environ::wasm::EntityType,
|
||||
) -> ExternType {
|
||||
pub(crate) fn from_wasmtime(types: &TypeTables, ty: &EntityType) -> ExternType {
|
||||
match ty {
|
||||
EntityType::Function(idx) => {
|
||||
FuncType::from_wasm_func_type(types.wasm_signatures[*idx].clone()).into()
|
||||
@@ -249,11 +245,11 @@ impl FuncType {
|
||||
self.sig.returns.iter().map(ValType::from_wasm_type)
|
||||
}
|
||||
|
||||
pub(crate) fn as_wasm_func_type(&self) -> &wasm::WasmFuncType {
|
||||
pub(crate) fn as_wasm_func_type(&self) -> &WasmFuncType {
|
||||
&self.sig
|
||||
}
|
||||
|
||||
pub(crate) fn from_wasm_func_type(sig: wasm::WasmFuncType) -> FuncType {
|
||||
pub(crate) fn from_wasm_func_type(sig: WasmFuncType) -> FuncType {
|
||||
Self { sig }
|
||||
}
|
||||
}
|
||||
@@ -293,7 +289,7 @@ impl GlobalType {
|
||||
|
||||
/// Returns `None` if the wasmtime global has a type that we can't
|
||||
/// represent, but that should only very rarely happen and indicate a bug.
|
||||
pub(crate) fn from_wasmtime_global(global: &wasm::Global) -> GlobalType {
|
||||
pub(crate) fn from_wasmtime_global(global: &Global) -> GlobalType {
|
||||
let ty = ValType::from_wasm_type(&global.wasm_ty);
|
||||
let mutability = if global.mutability {
|
||||
Mutability::Var
|
||||
@@ -313,7 +309,7 @@ impl GlobalType {
|
||||
/// which `call_indirect` can invoke other functions.
|
||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||
pub struct TableType {
|
||||
ty: wasm::Table,
|
||||
ty: Table,
|
||||
}
|
||||
|
||||
impl TableType {
|
||||
@@ -321,7 +317,7 @@ impl TableType {
|
||||
/// `element` and have the `limits` applied to its length.
|
||||
pub fn new(element: ValType, min: u32, max: Option<u32>) -> TableType {
|
||||
TableType {
|
||||
ty: wasm::Table {
|
||||
ty: Table {
|
||||
wasm_ty: element.to_wasm_type(),
|
||||
minimum: min,
|
||||
maximum: max,
|
||||
@@ -347,11 +343,11 @@ impl TableType {
|
||||
self.ty.maximum
|
||||
}
|
||||
|
||||
pub(crate) fn from_wasmtime_table(table: &wasm::Table) -> TableType {
|
||||
pub(crate) fn from_wasmtime_table(table: &Table) -> TableType {
|
||||
TableType { ty: table.clone() }
|
||||
}
|
||||
|
||||
pub(crate) fn wasmtime_table(&self) -> &wasm::Table {
|
||||
pub(crate) fn wasmtime_table(&self) -> &Table {
|
||||
&self.ty
|
||||
}
|
||||
}
|
||||
@@ -364,7 +360,7 @@ impl TableType {
|
||||
/// chunks of addressable memory.
|
||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||
pub struct MemoryType {
|
||||
ty: wasm::Memory,
|
||||
ty: Memory,
|
||||
}
|
||||
|
||||
impl MemoryType {
|
||||
@@ -375,7 +371,7 @@ impl MemoryType {
|
||||
/// WebAssembly pages, which are 64k.
|
||||
pub fn new(minimum: u32, maximum: Option<u32>) -> MemoryType {
|
||||
MemoryType {
|
||||
ty: wasm::Memory {
|
||||
ty: Memory {
|
||||
memory64: false,
|
||||
shared: false,
|
||||
minimum: minimum.into(),
|
||||
@@ -394,7 +390,7 @@ impl MemoryType {
|
||||
/// WebAssembly which is not standardized yet.
|
||||
pub fn new64(minimum: u64, maximum: Option<u64>) -> MemoryType {
|
||||
MemoryType {
|
||||
ty: wasm::Memory {
|
||||
ty: Memory {
|
||||
memory64: true,
|
||||
shared: false,
|
||||
minimum,
|
||||
@@ -430,11 +426,11 @@ impl MemoryType {
|
||||
self.ty.maximum
|
||||
}
|
||||
|
||||
pub(crate) fn from_wasmtime_memory(memory: &wasm::Memory) -> MemoryType {
|
||||
pub(crate) fn from_wasmtime_memory(memory: &Memory) -> MemoryType {
|
||||
MemoryType { ty: memory.clone() }
|
||||
}
|
||||
|
||||
pub(crate) fn wasmtime_memory(&self) -> &wasm::Memory {
|
||||
pub(crate) fn wasmtime_memory(&self) -> &Memory {
|
||||
&self.ty
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::linker::Definition;
|
||||
use crate::store::StoreInnermost;
|
||||
use crate::{signatures::SignatureCollection, Engine, Extern};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use wasmtime_environ::wasm::{
|
||||
use wasmtime_environ::{
|
||||
EntityType, Global, InstanceTypeIndex, Memory, ModuleTypeIndex, SignatureIndex, Table,
|
||||
};
|
||||
use wasmtime_jit::TypeTables;
|
||||
|
||||
Reference in New Issue
Block a user