Skip to content

Conversation

@sfackler
Copy link
Member

@sfackler sfackler commented Oct 26, 2025

Before this PR

Conjure-defined types using f64 need to implement traits that they would not normally be able to using Rust's built-in derive. We previously used the educe crate to be able to customize the behavior of fields containing f64. However, educe is unmaintained and has some significant correctness issues.

After this PR

==COMMIT_MSG==
Replaced educe with a custom derive macro.
==COMMIT_MSG==

To minimize the complexity of the macro, we proxy the trait impls through a delegate type. This allows us to rely on Rust's built-in derive logic for all of the heavy codegen lifting:

#[derive(DeriveWith)]
#[derive_with(PartialEq)]
struct MyType(#[derive_with(with = conjure_object::private::DoubleWrapper)] f64);

// expands to (more or less)

const _: () = {
    #[derive(PartialEq)]
    struct __MyTypeDelegate<'a>(DoubleWrapper<&'a f64>);

    impl<'a> From<&'a MyType> for __MyTypeDelegate<'a> {
        fn from(v: &'a MyType>) -> Self {
            __MyTypeDelegate(DoubleWrapper(&v.0))
        }
    }

    impl PartialEq for MyType {
        fn eq(&self, other: &Self) -> bool {
            __MyTypeDelegate::from(self) == __MyTypeDelegate(other)
        }
    }
};

Possible downsides?

The conversions through the delegate type may make these trait implementations slower.

Since the derive is only intended for use by conjure_codegen, the implementation cuts some corners. For example, it doesn't work on any generic types.

@sfackler sfackler requested a review from a team October 26, 2025 00:46
@changelog-app
Copy link

changelog-app bot commented Oct 26, 2025

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Replaced educe with a custom derive macro.

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link

changelog-app bot commented Oct 26, 2025

Successfully generated changelog entry!

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

🐛 Fixes

  • Replaced educe with a custom derive macro. (#508)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants