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
28 changes: 24 additions & 4 deletions typify-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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::<Vec<_>>();
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);
}
Expand Down
7 changes: 0 additions & 7 deletions typify-impl/tests/vega.out
Original file line number Diff line number Diff line change
Expand Up @@ -45358,13 +45358,6 @@ pub mod defaults {
pub(super) fn default_bool<const V: bool>() -> bool {
V
}
pub(super) fn default_i64<T, const V: i64>() -> T
where
T: ::std::convert::TryFrom<i64>,
<T as ::std::convert::TryFrom<i64>>::Error: ::std::fmt::Debug,
{
T::try_from(V).unwrap()
}
pub(super) fn aggregate_transform_drop() -> super::AggregateTransformDrop {
super::AggregateTransformDrop::Boolean(true)
}
Expand Down
Loading