From c228c6ff93fb89f9c003dfaf0f0d1342dc2c91cb Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Sat, 19 Sep 2026 14:41:42 -0700 Subject: [PATCH] emit shared default functions only where something calls them The defaults set records a helper when a default value is considered, not when a call site survives rendering, so vega emitted a default_i64 nothing called. Filter at output time, the way the error module now works. --- typify-impl/src/lib.rs | 28 ++++++++++++++++++++++++---- typify-impl/tests/vega.out | 7 ------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/typify-impl/src/lib.rs b/typify-impl/src/lib.rs index 462e30e2..ee1a2615 100644 --- a/typify-impl/src/lib.rs +++ b/typify-impl/src/lib.rs @@ -235,6 +235,18 @@ pub(crate) enum DefaultImpl { NZU64, } +impl DefaultImpl { + /// The name of the shared function this renders as. + fn fn_name(&self) -> &'static str { + match self { + DefaultImpl::Boolean => "default_bool", + DefaultImpl::I64 => "default_i64", + DefaultImpl::U64 => "default_u64", + DefaultImpl::NZU64 => "default_nzu64", + } + } +} + /// Type name to use in generated code. #[derive(Clone)] pub struct MapType(pub syn::Type); @@ -907,14 +919,22 @@ impl TypeSpace { .values() .for_each(|type_entry| type_entry.output(self, &mut output)); - // Add all shared default functions. - self.defaults + // Add the shared default functions that some emitted item actually + // calls. This is gross, and may have false-positives, but those should + // be basically benign. + let called = self + .defaults .iter() + .filter(|x| output.contains(x.fn_name())) + .collect::>(); + called + .into_iter() .for_each(|x| output.add_item(output::OutputSpaceMod::Defaults, "", x.into())); // Add the error type conversions use, but only when some emitted item - // references it. This is kind of gross that we're groveling around - // through output to decide, but it will--I hope--be short-lived. + // references it. This is also kind of gross that we're groveling + // around through output to decide, but it will--I hope--be + // short-lived. if output.contains("ConversionError") { self.add_error_item(&mut output); } diff --git a/typify-impl/tests/vega.out b/typify-impl/tests/vega.out index cdb59c94..6c3dea2c 100644 --- a/typify-impl/tests/vega.out +++ b/typify-impl/tests/vega.out @@ -45358,13 +45358,6 @@ pub mod defaults { pub(super) fn default_bool() -> bool { V } - pub(super) fn default_i64() -> T - where - T: ::std::convert::TryFrom, - >::Error: ::std::fmt::Debug, - { - T::try_from(V).unwrap() - } pub(super) fn aggregate_transform_drop() -> super::AggregateTransformDrop { super::AggregateTransformDrop::Boolean(true) }