Skip to content

Commit

Permalink
Try #2437:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Oct 29, 2021
2 parents e389ad0 + 5d25e27 commit bbcf903
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 199 deletions.
15 changes: 6 additions & 9 deletions lib/api/src/sys/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use std::sync::Arc;
use wasmer_engine::{Export, ExportFunction, ExportFunctionMetadata};
use wasmer_vm::{
raise_user_trap, resume_panic, wasmer_call_trampoline, ImportInitializerFuncPtr,
VMCallerCheckedAnyfunc, VMDynamicFunctionContext, VMFuncRef, VMFunction, VMFunctionBody,
VMFunctionEnvironment, VMFunctionKind, VMTrampoline,
VMDynamicFunctionContext, VMFuncRef, VMFunction, VMFunctionBody, VMFunctionEnvironment,
VMFunctionKind, VMTrampoline,
};

/// A WebAssembly `function` instance.
Expand Down Expand Up @@ -551,15 +551,12 @@ impl Function {
}
}

pub(crate) fn vm_funcref(&self) -> VMFuncRef {
/*pub(crate) fn vm_funcref(&self) -> VMFuncRef {
let engine = self.store.engine();
let vmsignature = engine.register_signature(&self.exported.vm_function.signature);
engine.register_function_metadata(VMCallerCheckedAnyfunc {
func_ptr: self.exported.vm_function.address,
type_index: vmsignature,
vmctx: self.exported.vm_function.vmctx,
})
}
// with the new changes this method is no longer possible... it should be though
// so TODO: figure out how to make this work
}*/

/// Transform this WebAssembly function into a function with the
/// native ABI. See [`NativeFunc`] to learn more.
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/sys/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ValFuncRef for Val {
}
Ok(match self {
Self::FuncRef(None) => VMFuncRef::null(),
Self::FuncRef(Some(f)) => f.vm_funcref(),
Self::FuncRef(Some(_)) => VMFuncRef::null(), //f.vm_funcref(),
_ => return Err(RuntimeError::new("val is not func ref")),
})
}
Expand Down Expand Up @@ -100,7 +100,7 @@ impl ValFuncRef for Val {
wasmer_vm::TableElement::ExternRef(extern_ref.clone().into())
}
Self::FuncRef(None) => wasmer_vm::TableElement::FuncRef(VMFuncRef::null()),
Self::FuncRef(Some(f)) => wasmer_vm::TableElement::FuncRef(f.vm_funcref()),
Self::FuncRef(Some(f)) => wasmer_vm::TableElement::FuncRef(VMFuncRef::null()), //wasmer_vm::TableElement::FuncRef(f.vm_funcref()),
_ => return Err(RuntimeError::new("val is not reference")),
})
}
Expand Down
10 changes: 1 addition & 9 deletions lib/engine-dylib/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ use wasmer_types::{
SignatureIndex, TableIndex,
};
use wasmer_vm::{
FuncDataRegistry, FunctionBodyPtr, MemoryStyle, TableStyle, VMFunctionBody,
VMSharedSignatureIndex, VMTrampoline,
FunctionBodyPtr, MemoryStyle, TableStyle, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline,
};

/// A compiled Wasm module, ready to be instantiated.
Expand All @@ -55,7 +54,6 @@ pub struct DylibArtifact {
#[loupe(skip)]
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, FunctionBodyPtr>,
func_data_registry: Arc<FuncDataRegistry>,
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
frame_info_registration: Mutex<Option<GlobalFrameInfoRegistration>>,
}
Expand Down Expand Up @@ -440,7 +438,6 @@ impl DylibArtifact {
.into_boxed_slice(),
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
.into_boxed_slice(),
func_data_registry: Arc::new(FuncDataRegistry::new()),
signatures: signatures.into_boxed_slice(),
frame_info_registration: Mutex::new(None),
})
Expand Down Expand Up @@ -546,7 +543,6 @@ impl DylibArtifact {
.into_boxed_slice(),
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
.into_boxed_slice(),
func_data_registry: engine_inner.func_data().clone(),
signatures: signatures.into_boxed_slice(),
frame_info_registration: Mutex::new(None),
})
Expand Down Expand Up @@ -828,10 +824,6 @@ impl Artifact for DylibArtifact {
&self.signatures
}

fn func_data_registry(&self) -> &FuncDataRegistry {
&self.func_data_registry
}

fn preinstantiate(&self) -> Result<(), InstantiationError> {
Ok(())
}
Expand Down
21 changes: 1 addition & 20 deletions lib/engine-dylib/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables};
#[cfg(feature = "compiler")]
use wasmer_types::Features;
use wasmer_types::FunctionType;
use wasmer_vm::{
FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex,
};
use wasmer_vm::{SignatureRegistry, VMSharedSignatureIndex};

/// A WebAssembly `Dylib` Engine.
#[derive(Clone, MemoryUsage)]
Expand All @@ -37,7 +35,6 @@ impl DylibEngine {
inner: Arc::new(Mutex::new(DylibEngineInner {
compiler: Some(compiler),
signatures: SignatureRegistry::new(),
func_data: Arc::new(FuncDataRegistry::new()),
prefixer: None,
features,
is_cross_compiling,
Expand Down Expand Up @@ -70,7 +67,6 @@ impl DylibEngine {
#[cfg(feature = "compiler")]
features: Features::default(),
signatures: SignatureRegistry::new(),
func_data: Arc::new(FuncDataRegistry::new()),
prefixer: None,
is_cross_compiling: false,
linker: Linker::None,
Expand Down Expand Up @@ -120,11 +116,6 @@ impl Engine for DylibEngine {
compiler.signatures().register(func_type)
}

fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef {
let compiler = self.inner();
compiler.func_data().register(func_data)
}

/// Lookup a signature
fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> {
let compiler = self.inner();
Expand Down Expand Up @@ -243,11 +234,6 @@ pub struct DylibEngineInner {
/// performantly.
signatures: SignatureRegistry,

/// The backing storage of `VMFuncRef`s. This centralized store ensures that 2
/// functions with the same `VMCallerCheckedAnyfunc` will have the same `VMFuncRef`.
/// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped.
func_data: Arc<FuncDataRegistry>,

/// The prefixer returns the a String to prefix each of
/// the functions in the shared object generated by the `DylibEngine`,
/// so we can assure no collisions.
Expand Down Expand Up @@ -311,11 +297,6 @@ impl DylibEngineInner {
&self.signatures
}

/// Shared func metadata registry.
pub(crate) fn func_data(&self) -> &Arc<FuncDataRegistry> {
&self.func_data
}

pub(crate) fn is_cross_compiling(&self) -> bool {
self.is_cross_compiling
}
Expand Down
13 changes: 1 addition & 12 deletions lib/engine-staticlib/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ use wasmer_types::{
FunctionIndex, LocalFunctionIndex, MemoryIndex, ModuleInfo, OwnedDataInitializer,
SignatureIndex, TableIndex,
};
use wasmer_vm::{
FuncDataRegistry, FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex,
VMTrampoline,
};
use wasmer_vm::{FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex, VMTrampoline};

/// A compiled wasm module, ready to be instantiated.
#[derive(MemoryUsage)]
Expand All @@ -42,7 +39,6 @@ pub struct StaticlibArtifact {
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, FunctionBodyPtr>,
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
func_data_registry: Arc<FuncDataRegistry>,
/// Length of the serialized metadata
metadata_length: usize,
symbol_registry: ModuleMetadataSymbolRegistry,
Expand Down Expand Up @@ -292,7 +288,6 @@ impl StaticlibArtifact {
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
.into_boxed_slice(),
signatures: signatures.into_boxed_slice(),
func_data_registry: engine_inner.func_data().clone(),
metadata_length,
symbol_registry,
})
Expand Down Expand Up @@ -332,7 +327,6 @@ impl StaticlibArtifact {

let engine_inner = engine.inner();
let signature_registry = engine_inner.signatures();
let func_data_registry = engine_inner.func_data().clone();
let mut sig_map: BTreeMap<SignatureIndex, VMSharedSignatureIndex> = BTreeMap::new();

let num_imported_functions = metadata.compile_info.module.num_imported_functions;
Expand Down Expand Up @@ -412,7 +406,6 @@ impl StaticlibArtifact {
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
.into_boxed_slice(),
signatures: signatures.into_boxed_slice(),
func_data_registry,
metadata_length: 0,
symbol_registry,
})
Expand Down Expand Up @@ -478,10 +471,6 @@ impl Artifact for StaticlibArtifact {
&self.signatures
}

fn func_data_registry(&self) -> &FuncDataRegistry {
&self.func_data_registry
}

fn preinstantiate(&self) -> Result<(), InstantiationError> {
Ok(())
}
Expand Down
21 changes: 1 addition & 20 deletions lib/engine-staticlib/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables};
#[cfg(feature = "compiler")]
use wasmer_types::Features;
use wasmer_types::FunctionType;
use wasmer_vm::{
FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex,
};
use wasmer_vm::{SignatureRegistry, VMSharedSignatureIndex};

/// A WebAssembly `Staticlib` Engine.
#[derive(Clone, MemoryUsage)]
Expand All @@ -31,7 +29,6 @@ impl StaticlibEngine {
inner: Arc::new(Mutex::new(StaticlibEngineInner {
compiler: Some(compiler),
signatures: SignatureRegistry::new(),
func_data: Arc::new(FuncDataRegistry::new()),
prefixer: None,
features,
})),
Expand Down Expand Up @@ -61,7 +58,6 @@ impl StaticlibEngine {
#[cfg(feature = "compiler")]
features: Features::default(),
signatures: SignatureRegistry::new(),
func_data: Arc::new(FuncDataRegistry::new()),
prefixer: None,
})),
target: Arc::new(Target::default()),
Expand Down Expand Up @@ -109,11 +105,6 @@ impl Engine for StaticlibEngine {
compiler.signatures().register(func_type)
}

fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef {
let compiler = self.inner();
compiler.func_data().register(func_data)
}

/// Lookup a signature
fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> {
let compiler = self.inner();
Expand Down Expand Up @@ -192,11 +183,6 @@ pub struct StaticlibEngineInner {
/// performantly.
signatures: SignatureRegistry,

/// The backing storage of `VMFuncRef`s. This centralized store ensures that 2
/// functions with the same `VMCallerCheckedAnyfunc` will have the same `VMFuncRef`.
/// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped.
func_data: Arc<FuncDataRegistry>,

/// The prefixer returns the a String to prefix each of the
/// functions in the static object generated by the
/// `StaticlibEngine`, so we can assure no collisions.
Expand Down Expand Up @@ -249,9 +235,4 @@ impl StaticlibEngineInner {
pub fn signatures(&self) -> &SignatureRegistry {
&self.signatures
}

/// Shared func metadata registry.
pub(crate) fn func_data(&self) -> &Arc<FuncDataRegistry> {
&self.func_data
}
}
11 changes: 1 addition & 10 deletions lib/engine-universal/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ use wasmer_types::{
FunctionIndex, LocalFunctionIndex, MemoryIndex, ModuleInfo, OwnedDataInitializer,
SignatureIndex, TableIndex,
};
use wasmer_vm::{
FuncDataRegistry, FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex,
VMTrampoline,
};
use wasmer_vm::{FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex, VMTrampoline};

const SERIALIZED_METADATA_LENGTH_OFFSET: usize = 22;
const SERIALIZED_METADATA_CONTENT_OFFSET: usize = 32;
Expand All @@ -39,7 +36,6 @@ pub struct UniversalArtifact {
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, FunctionBodyPtr>,
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
func_data_registry: Arc<FuncDataRegistry>,
frame_info_registration: Mutex<Option<GlobalFrameInfoRegistration>>,
finished_function_lengths: BoxedSlice<LocalFunctionIndex, usize>,
}
Expand Down Expand Up @@ -244,7 +240,6 @@ impl UniversalArtifact {
let finished_dynamic_function_trampolines =
finished_dynamic_function_trampolines.into_boxed_slice();
let signatures = signatures.into_boxed_slice();
let func_data_registry = inner_engine.func_data().clone();

Ok(Self {
serializable,
Expand All @@ -254,7 +249,6 @@ impl UniversalArtifact {
signatures,
frame_info_registration: Mutex::new(None),
finished_function_lengths,
func_data_registry,
})
}

Expand Down Expand Up @@ -335,9 +329,6 @@ impl Artifact for UniversalArtifact {
&self.signatures
}

fn func_data_registry(&self) -> &FuncDataRegistry {
&self.func_data_registry
}
fn serialize(&self) -> Result<Vec<u8>, SerializeError> {
// Prepend the header.
let mut serialized = Self::MAGIC_HEADER.to_vec();
Expand Down
20 changes: 2 additions & 18 deletions lib/engine-universal/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use wasmer_types::{
Features, FunctionIndex, FunctionType, LocalFunctionIndex, ModuleInfo, SignatureIndex,
};
use wasmer_vm::{
FuncDataRegistry, FunctionBodyPtr, SectionBodyPtr, SignatureRegistry, VMCallerCheckedAnyfunc,
VMFuncRef, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline,
FunctionBodyPtr, SectionBodyPtr, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex,
VMTrampoline,
};

/// A WebAssembly `Universal` Engine.
Expand All @@ -36,7 +36,6 @@ impl UniversalEngine {
compiler: Some(compiler),
code_memory: vec![],
signatures: SignatureRegistry::new(),
func_data: Arc::new(FuncDataRegistry::new()),
features,
})),
target: Arc::new(target),
Expand Down Expand Up @@ -64,7 +63,6 @@ impl UniversalEngine {
compiler: None,
code_memory: vec![],
signatures: SignatureRegistry::new(),
func_data: Arc::new(FuncDataRegistry::new()),
features: Features::default(),
})),
target: Arc::new(Target::default()),
Expand Down Expand Up @@ -93,11 +91,6 @@ impl Engine for UniversalEngine {
compiler.signatures().register(func_type)
}

fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef {
let compiler = self.inner();
compiler.func_data().register(func_data)
}

/// Lookup a signature
fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> {
let compiler = self.inner();
Expand Down Expand Up @@ -160,10 +153,6 @@ pub struct UniversalEngineInner {
/// The signature registry is used mainly to operate with trampolines
/// performantly.
signatures: SignatureRegistry,
/// The backing storage of `VMFuncRef`s. This centralized store ensures that 2
/// functions with the same `VMCallerCheckedAnyfunc` will have the same `VMFuncRef`.
/// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped.
func_data: Arc<FuncDataRegistry>,
}

impl UniversalEngineInner {
Expand Down Expand Up @@ -311,9 +300,4 @@ impl UniversalEngineInner {
pub fn signatures(&self) -> &SignatureRegistry {
&self.signatures
}

/// Shared func metadata registry.
pub(crate) fn func_data(&self) -> &Arc<FuncDataRegistry> {
&self.func_data
}
}
Loading

0 comments on commit bbcf903

Please sign in to comment.