-
Notifications
You must be signed in to change notification settings - Fork 925
Progress reporting for module loading and compilation #5883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 13 commits
706d650
9d8e664
43027f2
17ae0ce
3aab1ac
965e038
a861985
5fe730d
a9a070b
9b1f8a9
26507da
327b3b9
4571262
4aadf39
c44c3b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,8 @@ use bytes::Bytes; | |
| use rusty_jsc::{JSObject, JSValue}; | ||
| use tracing::warn; | ||
| use wasmer_types::{ | ||
| CompileError, DeserializeError, ExportType, ExportsIterator, ImportType, ImportsIterator, | ||
| ModuleInfo, SerializeError, | ||
| CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator, | ||
| ImportType, ImportsIterator, ModuleInfo, SerializeError, | ||
| }; | ||
|
|
||
| use crate::{ | ||
|
|
@@ -43,6 +43,14 @@ impl Module { | |
| unsafe { Self::from_binary_unchecked(_engine, binary) } | ||
| } | ||
|
|
||
| pub(crate) fn from_binary_with_progress( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should only be needed on the sys crate. Remove this |
||
| engine: &impl AsEngineRef, | ||
| binary: &[u8], | ||
| _callback: CompilationProgressCallback, | ||
| ) -> Result<Self, CompileError> { | ||
| Self::from_binary(engine, binary) | ||
| } | ||
|
|
||
| pub(crate) unsafe fn from_binary_unchecked( | ||
| engine: &impl AsEngineRef, | ||
| binary: &[u8], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,9 @@ use crate::{ | |
|
|
||
| use bytes::Bytes; | ||
| use wasmer_types::{ | ||
| CompileError, DeserializeError, ExportType, ExportsIterator, ExternType, FunctionType, | ||
| GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, Mutability, Pages, | ||
| SerializeError, TableType, Type, | ||
| CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator, | ||
| ExternType, FunctionType, GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, | ||
| Mutability, Pages, SerializeError, TableType, Type, | ||
| }; | ||
|
|
||
| #[derive(Debug)] | ||
|
|
@@ -152,6 +152,14 @@ impl Module { | |
| unsafe { Self::from_binary_unchecked(engine, binary) } | ||
| } | ||
|
|
||
| pub(crate) fn from_binary_with_progress( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should only be needed on the sys crate. Remove this |
||
| engine: &impl AsEngineRef, | ||
| binary: &[u8], | ||
| _callback: CompilationProgressCallback, | ||
| ) -> Result<Self, CompileError> { | ||
| Self::from_binary(engine, binary) | ||
| } | ||
|
|
||
| #[allow(clippy::arc_with_non_send_sync)] | ||
| #[tracing::instrument(skip(engine, binary))] | ||
| pub(crate) unsafe fn from_binary_unchecked( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,9 @@ use crate::{AsEngineRef, BackendModule, IntoBytes, backend::wamr::bindings::*}; | |
|
|
||
| use bytes::Bytes; | ||
| use wasmer_types::{ | ||
| CompileError, DeserializeError, ExportType, ExportsIterator, ExternType, FunctionType, | ||
| GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, Mutability, Pages, | ||
| SerializeError, TableType, Type, | ||
| CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator, | ||
| ExternType, FunctionType, GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, | ||
| Mutability, Pages, SerializeError, TableType, Type, | ||
| }; | ||
| pub(crate) struct ModuleHandle { | ||
| pub(crate) inner: *mut wasm_module_t, | ||
|
|
@@ -75,6 +75,14 @@ impl Module { | |
| unsafe { Self::from_binary_unchecked(_engine, binary) } | ||
| } | ||
|
|
||
| pub(crate) fn from_binary_with_progress( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should only be needed on the sys crate. Remove this |
||
| engine: &impl AsEngineRef, | ||
| binary: &[u8], | ||
| _callback: CompilationProgressCallback, | ||
| ) -> Result<Self, CompileError> { | ||
| Self::from_binary(engine, binary) | ||
| } | ||
|
|
||
| pub(crate) unsafe fn from_binary_unchecked( | ||
| engine: &impl AsEngineRef, | ||
| binary: &[u8], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,9 @@ use crate::{ | |
|
|
||
| use bytes::Bytes; | ||
| use wasmer_types::{ | ||
| CompileError, DeserializeError, ExportType, ExportsIterator, ExternType, FunctionType, | ||
| GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, Mutability, Pages, | ||
| SerializeError, TableType, Type, | ||
| CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator, | ||
| ExternType, FunctionType, GlobalType, ImportType, ImportsIterator, MemoryType, ModuleInfo, | ||
| Mutability, Pages, SerializeError, TableType, Type, | ||
| }; | ||
| pub(crate) struct ModuleHandle { | ||
| pub(crate) inner: *mut wasm_module_t, | ||
|
|
@@ -74,6 +74,14 @@ impl Module { | |
| unsafe { Self::from_binary_unchecked(_engine, binary) } | ||
| } | ||
|
|
||
| pub(crate) fn from_binary_with_progress( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should only be needed on the sys crate. Remove this |
||
| engine: &impl AsEngineRef, | ||
| binary: &[u8], | ||
| _callback: CompilationProgressCallback, | ||
| ) -> Result<Self, CompileError> { | ||
| Self::from_binary(engine, binary) | ||
| } | ||
|
|
||
| #[allow(clippy::arc_with_non_send_sync)] | ||
| pub(crate) unsafe fn from_binary_unchecked( | ||
| engine: &impl AsEngineRef, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| use wasmer_types::CompilationProgressCallback; | ||
|
|
||
| /// Provides progress-related extensions to the `Engine` trait. | ||
| pub trait ProgressEngineExt { | ||
| /// Compile a module from bytes with a progress callback. | ||
| /// | ||
| /// The callback is invoked with progress updates during the compilation process. | ||
| /// The callback also may return an error to abort the compilation. | ||
| /// | ||
| /// Signature of the callback function: `Fn(CompilationProgress) -> Result<(), UserAbort> + Send + Sync + 'static` | ||
| /// | ||
| /// # Aborting compilation | ||
| /// | ||
| /// The callback has to return a `Result<(), UserAbort>`. | ||
| /// | ||
| /// If the callback returns an error, the compilation will fail with a `CompileError::Aborted`. | ||
| /// | ||
| /// See [`CompilationProgressCallback::new`] for more details. | ||
| fn new_module_with_progress( | ||
| &self, | ||
| bytes: &[u8], | ||
| on_progress: CompilationProgressCallback, | ||
| ) -> Result<crate::Module, wasmer_types::CompileError>; | ||
| } | ||
|
|
||
| impl ProgressEngineExt for crate::Engine { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This impl and work should not live here. Should live only on the sys implementation that already exists ( |
||
| /// See [`ProgressEngineExt::new_module_with_progress`]. | ||
| fn new_module_with_progress( | ||
| &self, | ||
| bytes: &[u8], | ||
| on_progress: CompilationProgressCallback, | ||
| ) -> Result<crate::Module, wasmer_types::CompileError> { | ||
| crate::BackendModule::new_with_progress(self, bytes, on_progress).map(crate::Module) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,8 @@ use thiserror::Error; | |
| #[cfg(feature = "wat")] | ||
| use wasmer_types::WasmError; | ||
| use wasmer_types::{ | ||
| CompileError, DeserializeError, ExportType, ExportsIterator, ImportType, ImportsIterator, | ||
| ModuleInfo, SerializeError, | ||
| CompilationProgressCallback, CompileError, DeserializeError, ExportType, ExportsIterator, | ||
| ImportType, ImportsIterator, ModuleInfo, SerializeError, | ||
| }; | ||
|
|
||
| use crate::{ | ||
|
|
@@ -43,6 +43,21 @@ impl BackendModule { | |
| Self::from_binary(engine, bytes.as_ref()) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn new_with_progress( | ||
| engine: &impl AsEngineRef, | ||
| bytes: impl AsRef<[u8]>, | ||
| callback: CompilationProgressCallback, | ||
| ) -> Result<Self, CompileError> { | ||
| #[cfg(feature = "wat")] | ||
| let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| { | ||
| CompileError::Wasm(WasmError::Generic(format!( | ||
| "Error when converting wat: {e}", | ||
| ))) | ||
| })?; | ||
| Self::from_binary_with_progress(engine, bytes.as_ref(), callback) | ||
| } | ||
|
Comment on lines
+46
to
+59
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not live here |
||
|
|
||
| /// Creates a new WebAssembly module from a file path. | ||
| #[inline] | ||
| pub fn from_file( | ||
|
|
@@ -100,6 +115,67 @@ impl BackendModule { | |
| } | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn from_binary_with_progress( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete me |
||
| engine: &impl AsEngineRef, | ||
| binary: &[u8], | ||
| callback: CompilationProgressCallback, | ||
| ) -> Result<Self, CompileError> { | ||
| match engine.as_engine_ref().inner.be { | ||
| #[cfg(feature = "sys")] | ||
| crate::BackendEngine::Sys(_) => Ok(Self::Sys( | ||
| crate::backend::sys::entities::module::Module::from_binary_with_progress( | ||
| engine, | ||
| binary, | ||
| callback.clone(), | ||
| )?, | ||
| )), | ||
|
|
||
| #[cfg(feature = "wamr")] | ||
| crate::BackendEngine::Wamr(_) => Ok(Self::Wamr( | ||
| crate::backend::wamr::entities::module::Module::from_binary_with_progress( | ||
| engine, | ||
| binary, | ||
| callback.clone(), | ||
| )?, | ||
| )), | ||
|
|
||
| #[cfg(feature = "wasmi")] | ||
| crate::BackendEngine::Wasmi(_) => Ok(Self::Wasmi( | ||
| crate::backend::wasmi::entities::module::Module::from_binary_with_progress( | ||
| engine, | ||
| binary, | ||
| callback.clone(), | ||
| )?, | ||
| )), | ||
|
|
||
| #[cfg(feature = "v8")] | ||
| crate::BackendEngine::V8(_) => Ok(Self::V8( | ||
| crate::backend::v8::entities::module::Module::from_binary_with_progress( | ||
| engine, | ||
| binary, | ||
| callback.clone(), | ||
| )?, | ||
| )), | ||
|
|
||
| #[cfg(feature = "js")] | ||
| crate::BackendEngine::Js(_) => Ok(Self::Js( | ||
| crate::backend::js::entities::module::Module::from_binary_with_progress( | ||
| engine, | ||
| binary, | ||
| callback.clone(), | ||
| )?, | ||
| )), | ||
|
|
||
| #[cfg(feature = "jsc")] | ||
| crate::BackendEngine::Jsc(_) => Ok(Self::Jsc( | ||
| crate::backend::jsc::entities::module::Module::from_binary_with_progress( | ||
| engine, binary, callback, | ||
| )?, | ||
| )), | ||
| } | ||
| } | ||
|
|
||
| /// Creates a new WebAssembly module from a Wasm binary, | ||
| /// skipping any kind of validation on the WebAssembly file. | ||
| /// | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should only be needed on the sys crate. Remove this