From ccfa86dd755afdf30b494a1a2da70febb13937d5 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 5 Jul 2022 16:28:30 +0300 Subject: [PATCH] Rename UniversalArtifact to Artifact --- CHANGELOG.md | 1 + docs/migration_to_3.0.0.md | 2 +- lib/api/src/sys/mod.rs | 2 +- lib/api/src/sys/module.rs | 8 ++-- lib/cli-compiler/src/commands/compile.rs | 8 ++-- lib/cli/src/commands/compile.rs | 2 +- lib/cli/src/commands/run.rs | 4 +- lib/compiler/src/engine/universal/artifact.rs | 38 +++++++++---------- lib/compiler/src/engine/universal/engine.rs | 17 ++++----- lib/compiler/src/engine/universal/mod.rs | 2 +- .../src/universal_artifact/artifact.rs | 16 ++++---- .../{engine.rs => builder.rs} | 0 lib/compiler/src/universal_artifact/mod.rs | 6 +-- lib/types/src/serialize.rs | 3 +- 14 files changed, 54 insertions(+), 55 deletions(-) rename lib/compiler/src/universal_artifact/{engine.rs => builder.rs} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ab9fe35c1e..4803f5678db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C - [#2946](https://github.com/wasmerio/wasmer/pull/2946) Remove dylib,staticlib engines in favor of a single Universal engine - [#2949](https://github.com/wasmerio/wasmer/pull/2949) Switch back to using custom LLVM builds on CI - #2892 Renamed `get_native_function` to `get_typed_function`, marked former as deprecated. +- [#2869](https://github.com/wasmerio/wasmer/pull/2869) Removed Artifact, Engine traits. Renamed UniversalArtifact to Artifact, and UniversalEngine to Engine. ### Fixed - [#2963](https://github.com/wasmerio/wasmer/pull/2963) Remove accidental dependency on libwayland and libxcb in ClI diff --git a/docs/migration_to_3.0.0.md b/docs/migration_to_3.0.0.md index fc4f2511530..f469d015755 100644 --- a/docs/migration_to_3.0.0.md +++ b/docs/migration_to_3.0.0.md @@ -138,7 +138,7 @@ let wasm_bytes = wat2wasm( let compiler_config = Cranelift::default(); let mut store = Store::new(&compiler_config); let module = Module::new(&store, wasm_bytes)?; -let instance = Instance::new(&module, &imports! {})?; +let instance = Instance::new(&mut store, &module, &imports! {})?; ``` [examples]: https://docs.wasmer.io/integrations/examples diff --git a/lib/api/src/sys/mod.rs b/lib/api/src/sys/mod.rs index c8a142c5674..2fc5d15006c 100644 --- a/lib/api/src/sys/mod.rs +++ b/lib/api/src/sys/mod.rs @@ -94,7 +94,7 @@ pub use wasmer_compiler_cranelift::{Cranelift, CraneliftOptLevel}; pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM}; #[cfg(feature = "universal")] -pub use wasmer_compiler::{Engine, Universal, UniversalArtifact}; +pub use wasmer_compiler::{Artifact, Engine, Universal}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/api/src/sys/module.rs b/lib/api/src/sys/module.rs index 3e9843e3afd..78556a7d01f 100644 --- a/lib/api/src/sys/module.rs +++ b/lib/api/src/sys/module.rs @@ -6,8 +6,8 @@ use std::io; use std::path::Path; use std::sync::Arc; use thiserror::Error; +use wasmer_compiler::Artifact; use wasmer_compiler::ArtifactCreate; -use wasmer_compiler::UniversalArtifact; #[cfg(feature = "wat")] use wasmer_types::WasmError; use wasmer_types::{ @@ -50,7 +50,7 @@ pub struct Module { // // In the future, this code should be refactored to properly describe the // ownership of the code and its metadata. - artifact: Arc, + artifact: Arc, module_info: Arc, } @@ -281,7 +281,7 @@ impl Module { Ok(Self::from_artifact(artifact)) } - fn from_artifact(artifact: Arc) -> Self { + fn from_artifact(artifact: Arc) -> Self { Self { module_info: Arc::new(artifact.create_module_info()), artifact, @@ -456,7 +456,7 @@ impl Module { /// this functionality is required for some core functionality though, like /// the object file engine. #[doc(hidden)] - pub fn artifact(&self) -> &Arc { + pub fn artifact(&self) -> &Arc { &self.artifact } } diff --git a/lib/cli-compiler/src/commands/compile.rs b/lib/cli-compiler/src/commands/compile.rs index 7f190c5763d..b5553d3c27b 100644 --- a/lib/cli-compiler/src/commands/compile.rs +++ b/lib/cli-compiler/src/commands/compile.rs @@ -4,7 +4,7 @@ use anyhow::{Context, Result}; use std::path::{Path, PathBuf}; use structopt::StructOpt; use wasmer_compiler::ModuleEnvironment; -use wasmer_compiler::{ArtifactCreate, UniversalArtifactBuild}; +use wasmer_compiler::{ArtifactBuild, ArtifactCreate}; use wasmer_types::entity::PrimaryMap; use wasmer_types::{ CompileError, CpuFeature, MemoryIndex, MemoryStyle, TableIndex, TableStyle, Target, Triple, @@ -40,7 +40,9 @@ impl Compile { } pub(crate) fn get_recommend_extension(target_triple: &Triple) -> Result<&'static str> { - Ok(wasmer_compiler::UniversalArtifactBuild::get_default_extension(target_triple)) + Ok(wasmer_compiler::ArtifactBuild::get_default_extension( + target_triple, + )) } fn inner_execute(&self) -> Result<()> { @@ -97,7 +99,7 @@ impl Compile { .values() .map(|table_type| tunables.table_style(table_type)) .collect(); - let artifact = UniversalArtifactBuild::new( + let artifact = ArtifactBuild::new( &mut engine, &wasm_bytes, &target, diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index f3bc3b9fafb..832346e9f2d 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -57,7 +57,7 @@ impl Compile { .map(|osstr| osstr.to_string_lossy().to_string()) .unwrap_or_default(); let recommended_extension = - wasmer_compiler::UniversalArtifact::get_default_extension(target.triple()); + wasmer_compiler::Artifact::get_default_extension(target.triple()); match self.output.extension() { Some(ext) => { if ext != recommended_extension { diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index d6f4de250a0..b27f36cfc2f 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -235,7 +235,7 @@ impl Run { fn get_store_module(&self) -> Result<(Store, Module)> { let contents = std::fs::read(self.path.clone())?; - if wasmer_compiler::UniversalArtifact::is_deserializable(&contents) { + if wasmer_compiler::Artifact::is_deserializable(&contents) { let engine = wasmer_compiler::Universal::headless().engine(); let store = Store::new_with_engine(&engine); let module = unsafe { Module::deserialize_from_file(&store, &self.path)? }; @@ -309,7 +309,7 @@ impl Run { let mut cache = FileSystemCache::new(cache_dir_root)?; let extension = - wasmer_compiler::UniversalArtifact::get_default_extension(&Triple::host()).to_string(); + wasmer_compiler::Artifact::get_default_extension(&Triple::host()).to_string(); cache.set_cache_extension(Some(extension)); Ok(cache) } diff --git a/lib/compiler/src/engine/universal/artifact.rs b/lib/compiler/src/engine/universal/artifact.rs index 5dc2faf8f97..de65af86213 100644 --- a/lib/compiler/src/engine/universal/artifact.rs +++ b/lib/compiler/src/engine/universal/artifact.rs @@ -1,13 +1,13 @@ -//! Define `UniversalArtifact`, based on `UniversalArtifactBuild` +//! Define `Artifact`, based on `ArtifactBuild` //! to allow compiling and instantiating to be done as separate steps. use super::engine::{Engine, EngineInner}; use crate::engine::universal::link::link_module; +use crate::ArtifactBuild; use crate::ArtifactCreate; use crate::Features; #[cfg(feature = "universal_engine")] use crate::ModuleEnvironment; -use crate::UniversalArtifactBuild; use crate::{ register_frame_info, resolve_imports, FunctionExtent, GlobalFrameInfoRegistration, InstantiationError, MetadataHeader, RuntimeError, Tunables, @@ -25,8 +25,8 @@ use wasmer_vm::{FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex use wasmer_vm::{InstanceAllocator, InstanceHandle, StoreObjects, TrapHandlerFn, VMExtern}; /// A compiled wasm module, ready to be instantiated. -pub struct UniversalArtifact { - artifact: UniversalArtifactBuild, +pub struct Artifact { + artifact: ArtifactBuild, finished_functions: BoxedSlice, finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, @@ -35,8 +35,8 @@ pub struct UniversalArtifact { finished_function_lengths: BoxedSlice, } -impl UniversalArtifact { - /// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated. +impl Artifact { + /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. #[cfg(feature = "universal_engine")] pub fn new( engine: &Engine, @@ -58,7 +58,7 @@ impl UniversalArtifact { .map(|table_type| tunables.table_style(table_type)) .collect(); - let artifact = UniversalArtifactBuild::new( + let artifact = ArtifactBuild::new( inner_engine.builder_mut(), data, engine.target(), @@ -69,7 +69,7 @@ impl UniversalArtifact { Self::from_parts(&mut inner_engine, artifact) } - /// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated. + /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. #[cfg(not(feature = "universal_engine"))] pub fn new(_engine: &Engine, _data: &[u8]) -> Result { Err(CompileError::Codegen( @@ -77,30 +77,30 @@ impl UniversalArtifact { )) } - /// Deserialize a UniversalArtifactBuild + /// Deserialize a ArtifactBuild /// /// # Safety /// This function is unsafe because rkyv reads directly without validating /// the data. pub unsafe fn deserialize(engine: &Engine, bytes: &[u8]) -> Result { - if !UniversalArtifactBuild::is_deserializable(bytes) { + if !ArtifactBuild::is_deserializable(bytes) { return Err(DeserializeError::Incompatible( "The provided bytes are not wasmer-universal".to_string(), )); } - let bytes = &bytes[UniversalArtifactBuild::MAGIC_HEADER.len()..]; + let bytes = &bytes[ArtifactBuild::MAGIC_HEADER.len()..]; let metadata_len = MetadataHeader::parse(bytes)?; let metadata_slice: &[u8] = &bytes[MetadataHeader::LEN..][..metadata_len]; let serializable = SerializableModule::deserialize(metadata_slice)?; - let artifact = UniversalArtifactBuild::from_serializable(serializable); + let artifact = ArtifactBuild::from_serializable(serializable); let mut inner_engine = engine.inner_mut(); Self::from_parts(&mut inner_engine, artifact).map_err(DeserializeError::Compiler) } - /// Construct a `UniversalArtifactBuild` from component parts. + /// Construct a `ArtifactBuild` from component parts. pub fn from_parts( engine_inner: &mut EngineInner, - artifact: UniversalArtifactBuild, + artifact: ArtifactBuild, ) -> Result { let module_info = artifact.create_module_info(); let ( @@ -182,15 +182,15 @@ impl UniversalArtifact { } /// Get the default extension when serializing this artifact pub fn get_default_extension(triple: &Triple) -> &'static str { - UniversalArtifactBuild::get_default_extension(triple) + ArtifactBuild::get_default_extension(triple) } - /// Check if the provided bytes look like a serialized `UniversalArtifactBuild`. + /// Check if the provided bytes look like a serialized `ArtifactBuild`. pub fn is_deserializable(bytes: &[u8]) -> bool { - UniversalArtifactBuild::is_deserializable(bytes) + ArtifactBuild::is_deserializable(bytes) } } -impl ArtifactCreate for UniversalArtifact { +impl ArtifactCreate for Artifact { fn create_module_info(&self) -> ModuleInfo { self.artifact.create_module_info() } @@ -220,7 +220,7 @@ impl ArtifactCreate for UniversalArtifact { } } -impl UniversalArtifact { +impl Artifact { /// Register thie `Artifact` stack frame information into the global scope. /// /// This is required to ensure that any traps can be properly symbolicated. diff --git a/lib/compiler/src/engine/universal/engine.rs b/lib/compiler/src/engine/universal/engine.rs index 750321d05d1..a9a88845b08 100644 --- a/lib/compiler/src/engine/universal/engine.rs +++ b/lib/compiler/src/engine/universal/engine.rs @@ -3,7 +3,7 @@ #[cfg(feature = "universal_engine")] use crate::Compiler; use crate::EngineBuilder; -use crate::{CodeMemory, UniversalArtifact}; +use crate::{Artifact, CodeMemory}; use crate::{FunctionExtent, Tunables}; use memmap2::Mmap; use std::path::Path; @@ -106,8 +106,8 @@ impl Engine { &self, binary: &[u8], tunables: &dyn Tunables, - ) -> Result, CompileError> { - Ok(Arc::new(UniversalArtifact::new(self, binary, tunables)?)) + ) -> Result, CompileError> { + Ok(Arc::new(Artifact::new(self, binary, tunables)?)) } /// Compile a WebAssembly binary @@ -116,7 +116,7 @@ impl Engine { &self, _binary: &[u8], _tunables: &dyn Tunables, - ) -> Result, CompileError> { + ) -> Result, CompileError> { Err(CompileError::Codegen( "The Engine is operating in headless mode, so it can not compile Modules.".to_string(), )) @@ -127,11 +127,8 @@ impl Engine { /// # Safety /// /// The serialized content must represent a serialized WebAssembly module. - pub unsafe fn deserialize( - &self, - bytes: &[u8], - ) -> Result, DeserializeError> { - Ok(Arc::new(UniversalArtifact::deserialize(self, bytes)?)) + pub unsafe fn deserialize(&self, bytes: &[u8]) -> Result, DeserializeError> { + Ok(Arc::new(Artifact::deserialize(self, bytes)?)) } /// Deserializes a WebAssembly module from a path @@ -142,7 +139,7 @@ impl Engine { pub unsafe fn deserialize_from_file( &self, file_ref: &Path, - ) -> Result, DeserializeError> { + ) -> Result, DeserializeError> { let file = std::fs::File::open(file_ref)?; let mmap = Mmap::map(&file)?; self.deserialize(&mmap) diff --git a/lib/compiler/src/engine/universal/mod.rs b/lib/compiler/src/engine/universal/mod.rs index 80156e10257..976c35ba943 100644 --- a/lib/compiler/src/engine/universal/mod.rs +++ b/lib/compiler/src/engine/universal/mod.rs @@ -11,7 +11,7 @@ mod engine; mod link; mod unwind; -pub use self::artifact::UniversalArtifact; +pub use self::artifact::Artifact; pub use self::builder::Universal; pub use self::code_memory::CodeMemory; pub use self::engine::Engine; diff --git a/lib/compiler/src/universal_artifact/artifact.rs b/lib/compiler/src/universal_artifact/artifact.rs index d629ef2639b..1318e8824d4 100644 --- a/lib/compiler/src/universal_artifact/artifact.rs +++ b/lib/compiler/src/universal_artifact/artifact.rs @@ -1,4 +1,4 @@ -//! Define `UniversalArtifactBuild` to allow compiling and instantiating to be +//! Define `ArtifactBuild` to allow compiling and instantiating to be //! done as separate steps. #[cfg(feature = "universal_engine")] @@ -24,20 +24,20 @@ use wasmer_types::{ }; /// A compiled wasm module, ready to be instantiated. -pub struct UniversalArtifactBuild { +pub struct ArtifactBuild { serializable: SerializableModule, } -impl UniversalArtifactBuild { +impl ArtifactBuild { /// Header signature for wasmu binary pub const MAGIC_HEADER: &'static [u8; 16] = b"wasmer-universal"; - /// Check if the provided bytes look like a serialized `UniversalArtifactBuild`. + /// Check if the provided bytes look like a serialized `ArtifactBuild`. pub fn is_deserializable(bytes: &[u8]) -> bool { bytes.starts_with(Self::MAGIC_HEADER) } - /// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated. + /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. #[cfg(feature = "universal_engine")] pub fn new( inner_engine: &mut EngineBuilder, @@ -116,7 +116,7 @@ impl UniversalArtifactBuild { Ok(Self { serializable }) } - /// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated. + /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. #[cfg(not(feature = "universal_engine"))] pub fn new(_engine: &EngineBuilder, _data: &[u8]) -> Result { Err(CompileError::Codegen( @@ -124,7 +124,7 @@ impl UniversalArtifactBuild { )) } - /// Create a new UniversalArtifactBuild from a SerializableModule + /// Create a new ArtifactBuild from a SerializableModule pub fn from_serializable(serializable: SerializableModule) -> Self { Self { serializable } } @@ -187,7 +187,7 @@ impl UniversalArtifactBuild { } } -impl ArtifactCreate for UniversalArtifactBuild { +impl ArtifactCreate for ArtifactBuild { fn create_module_info(&self) -> ModuleInfo { self.serializable.compile_info.module.clone() } diff --git a/lib/compiler/src/universal_artifact/engine.rs b/lib/compiler/src/universal_artifact/builder.rs similarity index 100% rename from lib/compiler/src/universal_artifact/engine.rs rename to lib/compiler/src/universal_artifact/builder.rs diff --git a/lib/compiler/src/universal_artifact/mod.rs b/lib/compiler/src/universal_artifact/mod.rs index 4157d5a2ec3..a9af734a5d9 100644 --- a/lib/compiler/src/universal_artifact/mod.rs +++ b/lib/compiler/src/universal_artifact/mod.rs @@ -1,9 +1,9 @@ //! Generic Artifact abstraction for Wasmer Engines. mod artifact; -mod engine; +mod builder; mod trampoline; -pub use self::artifact::UniversalArtifactBuild; -pub use self::engine::EngineBuilder; +pub use self::artifact::ArtifactBuild; +pub use self::builder::EngineBuilder; pub use self::trampoline::*; diff --git a/lib/types/src/serialize.rs b/lib/types/src/serialize.rs index 81e3a14a438..e32cd0927de 100644 --- a/lib/types/src/serialize.rs +++ b/lib/types/src/serialize.rs @@ -34,8 +34,7 @@ pub struct SerializableCompilation { pub libcall_trampoline_len: u32, } -/// Serializable struct that is able to serialize from and to -/// a `UniversalArtifactInfo`. +/// Serializable struct that is able to serialize from and to a `ArtifactInfo`. #[derive(Archive, RkyvDeserialize, RkyvSerialize)] #[allow(missing_docs)] pub struct SerializableModule {