From d8f9615b11c291a7998c446231f56ec7e4fd5cf8 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Mon, 1 Dec 2025 11:55:48 +0100 Subject: [PATCH] refactor: `IgnoreDebug` helper --- host/src/ignore_debug.rs | 48 ++++++++++++++++++++++++++++ host/src/lib.rs | 67 ++++++---------------------------------- 2 files changed, 57 insertions(+), 58 deletions(-) create mode 100644 host/src/ignore_debug.rs diff --git a/host/src/ignore_debug.rs b/host/src/ignore_debug.rs new file mode 100644 index 0000000..308f2f1 --- /dev/null +++ b/host/src/ignore_debug.rs @@ -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); + +impl std::fmt::Debug for IgnoreDebug { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "<{}>", std::any::type_name::()) + } +} + +impl Deref for IgnoreDebug { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for IgnoreDebug { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl From for IgnoreDebug { + 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)), ""); + assert_eq!( + format!("{:?}", IgnoreDebug::from(Arc::::from("foo"))), + ">", + ); + } +} diff --git a/host/src/lib.rs b/host/src/lib.rs index a324db5..92836d6 100644 --- a/host/src/lib.rs +++ b/host/src/lib.rs @@ -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, @@ -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. /// @@ -82,7 +85,7 @@ struct WasmStateImpl { stderr: MemoryOutputPipe, /// WASI context. - wasi_ctx: WasiCtx, + wasi_ctx: IgnoreDebug, /// WASI HTTP context. wasi_http_ctx: WasiHttpCtx, @@ -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", &"") - .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 { @@ -423,6 +402,7 @@ impl WasmPermissions { /// /// /// [runtime]: tokio::runtime::Runtime +#[derive(Debug)] pub struct WasmScalarUdf { /// Mutable state. /// @@ -430,6 +410,7 @@ pub struct WasmScalarUdf { store: Arc>>, /// Background task that keeps the WASM epoch timer running. + #[expect(dead_code)] epoch_task: Arc>, /// Timeout for blocking tasks. @@ -439,7 +420,7 @@ pub struct WasmScalarUdf { trusted_data_limits: TrustedDataLimits, /// WIT-based bindings that we resolved within the payload. - bindings: Arc, + bindings: IgnoreDebug>, /// Resource handle for the Scalar UDF within the VM. /// @@ -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), @@ -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(), @@ -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", &"") - .field("resource", resource) - .field("name", name) - .field("id", id) - .field("signature", signature) - .field("return_type", return_type) - .finish() - } -} - impl PartialEq for WasmScalarUdf { fn eq(&self, other: &Self) -> bool { self.id == other.id