Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions host/src/ignore_debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! Helper to simplify [`Debug`] implementation by ignoring it.

use std::ops::{Deref, DerefMut};

/// Helper to simplify [`Debug`] implementation by ignoring it.
pub(crate) struct IgnoreDebug<T>(T);

impl<T> std::fmt::Debug for IgnoreDebug<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "<{}>", std::any::type_name::<T>())
}
}

impl<T> Deref for IgnoreDebug<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<T> DerefMut for IgnoreDebug<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl<T> From<T> for IgnoreDebug<T> {
fn from(value: T) -> Self {
Self(value)
}
}

#[cfg(test)]
mod test {
use std::sync::Arc;

use super::*;

#[test]
fn test_debug() {
assert_eq!(format!("{:?}", IgnoreDebug::from(1u8)), "<u8>");
assert_eq!(
format!("{:?}", IgnoreDebug::from(Arc::<str>::from("foo"))),
"<alloc::sync::Arc<str>>",
);
}
}
67 changes: 9 additions & 58 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::{
conversion::limits::{CheckedInto, ComplexityToken, TrustedDataLimits},
error::{DataFusionResultExt, WasmToDataFusionResultExt, WitDataFusionResultExt},
http::{HttpRequestValidator, RejectAllHttpRequests},
ignore_debug::IgnoreDebug,
limiter::{Limiter, StaticResourceLimits},
linker::link,
tokio_helpers::async_in_sync_context,
Expand All @@ -61,12 +62,14 @@ mod bindings;
pub mod conversion;
pub mod error;
pub mod http;
mod ignore_debug;
pub mod limiter;
mod linker;
mod tokio_helpers;
pub mod vfs;

/// State of the WASM payload.
#[derive(Debug)]
struct WasmStateImpl {
/// Virtual filesystem for the WASM payload.
///
Expand All @@ -82,7 +85,7 @@ struct WasmStateImpl {
stderr: MemoryOutputPipe,

/// WASI context.
wasi_ctx: WasiCtx,
wasi_ctx: IgnoreDebug<WasiCtx>,

/// WASI HTTP context.
wasi_http_ctx: WasiHttpCtx,
Expand All @@ -97,30 +100,6 @@ struct WasmStateImpl {
io_rt: Handle,
}

impl std::fmt::Debug for WasmStateImpl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self {
vfs_state,
limiter,
stderr,
wasi_ctx: _,
wasi_http_ctx: _,
resource_table,
http_validator,
io_rt,
} = self;
f.debug_struct("WasmStateImpl")
.field("vfs_state", vfs_state)
.field("limiter", limiter)
.field("stderr", stderr)
.field("wasi_ctx", &"<WASI_CTX>")
.field("resource_table", resource_table)
.field("http_validator", http_validator)
.field("io_rt", io_rt)
.finish()
}
}

impl WasiView for WasmStateImpl {
fn ctx(&mut self) -> WasiCtxView<'_> {
WasiCtxView {
Expand Down Expand Up @@ -423,13 +402,15 @@ impl WasmPermissions {
///
///
/// [runtime]: tokio::runtime::Runtime
#[derive(Debug)]
pub struct WasmScalarUdf {
/// Mutable state.
///
/// This mostly contains [`WasmStateImpl`].
store: Arc<Mutex<Store<WasmStateImpl>>>,

/// Background task that keeps the WASM epoch timer running.
#[expect(dead_code)]
epoch_task: Arc<JoinSet<()>>,

/// Timeout for blocking tasks.
Expand All @@ -439,7 +420,7 @@ pub struct WasmScalarUdf {
trusted_data_limits: TrustedDataLimits,

/// WIT-based bindings that we resolved within the payload.
bindings: Arc<bindings::Datafusion>,
bindings: IgnoreDebug<Arc<bindings::Datafusion>>,

/// Resource handle for the Scalar UDF within the VM.
///
Expand Down Expand Up @@ -543,7 +524,7 @@ impl WasmScalarUdf {
vfs_state,
limiter,
stderr,
wasi_ctx: wasi_ctx_builder.build(),
wasi_ctx: wasi_ctx_builder.build().into(),
wasi_http_ctx: WasiHttpCtx::new(),
resource_table: ResourceTable::new(),
http_validator: Arc::clone(&permissions.http),
Expand Down Expand Up @@ -669,7 +650,7 @@ impl WasmScalarUdf {
epoch_task: Arc::clone(&epoch_task),
inplace_blocking_timeout,
trusted_data_limits: permissions.trusted_data_limits.clone(),
bindings: Arc::clone(&bindings),
bindings: Arc::clone(&bindings).into(),
resource,
name,
id: Uuid::new_v4(),
Expand Down Expand Up @@ -716,36 +697,6 @@ impl WasmScalarUdf {
}
}

impl std::fmt::Debug for WasmScalarUdf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self {
store,
epoch_task,
inplace_blocking_timeout,
trusted_data_limits,
bindings: _,
resource,
name,
id,
signature,
return_type,
} = self;

f.debug_struct("WasmScalarUdf")
.field("store", store)
.field("epoch_task", epoch_task)
.field("inplace_blocking_timeout", inplace_blocking_timeout)
.field("trusted_data_limits", trusted_data_limits)
.field("bindings", &"<BINDINGS>")
.field("resource", resource)
.field("name", name)
.field("id", id)
.field("signature", signature)
.field("return_type", return_type)
.finish()
}
}

impl PartialEq<Self> for WasmScalarUdf {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
Expand Down