Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the FloatFuncs trait a sealed public trait, add sin/sinf. #332

Merged
merged 3 commits into from
Feb 9, 2024

Conversation

ratmice
Copy link
Contributor

@ratmice ratmice commented Feb 6, 2024

This trait, with the addition of sin/sinf is needed to build peniko with the --no-default-features --features libm combination (added in the pr below).

The approach taken here is that rather than duplicating this common module in peniko, to make it pub, and add the sin/sinf. for peniko. This trait is only conditionally defined so use of it in peniko would look something like:

+#[cfg(not(feature = "std"))]
+#[allow(unused_imports)]
+use kurbo::common::FloatFuncs as _

This patch is in regards to fixing the testsuite failures for default features added in
linebender/peniko#23

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a Kurbo maintainer, so I'm not certain that they would want this

@@ -5,6 +5,10 @@

#![allow(missing_docs)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know why this is here? Does any of this new public API need docs, even just something very simple?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is here to avoid documenting the existing pub const GAUSS_LEGENDRE_COEFFS* values.
I added basically a stub documentation explaining the trait, and pointing to the std implementation for further docs.

src/common.rs Outdated
@@ -5,6 +5,10 @@

#![allow(missing_docs)]

mod common_sealed {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that common_sealed is a great name for this - I think I'd prefer something like:

mod sealed {
    /// Seals [super::FloatFunc]
    pub trait FloatFuncsSealed {}
}

I don't think the Rust project documents sealed traits itself, so I think we should also probably have a link which explains it.
I don't know what link that would be, however

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in cb3c29d

src/common.rs Outdated
@@ -14,13 +18,16 @@ macro_rules! define_float_funcs {
=> $lname:ident/$lfname:ident;
)+) => {
#[cfg(not(feature = "std"))]
pub(crate) trait FloatFuncs : Sized {
pub trait FloatFuncs : Sized + common_sealed::Sealed {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have some docs now that it's public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in 85ad5eb

@ratmice
Copy link
Contributor Author

ratmice commented Feb 6, 2024

One thing this patch doesn't try to fix is cargo test --no-default-features --features libm I manually checked that the respective build target works, don't know see that this combination is actually being tested by ci though.

It is perhaps worth adding that.
Edit: Nevermind I see now it is being checked on one of the macos runs

src/common.rs Outdated
@@ -6,7 +6,9 @@
#![allow(missing_docs)]

mod sealed {
pub trait Sealed {}
/// A sealed trait which [sealed trait](https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/) which stops this trait
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this reads:
A sealed trait which sealed trait which..., which doesn't seem right

Copy link
Contributor Author

@ratmice ratmice Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops fixed in bdfa0e7

@richard-uk1
Copy link
Collaborator

Hey @ratmice sorry if this is a silly question, but why do we need to seal the trait?

@ratmice
Copy link
Contributor Author

ratmice commented Feb 8, 2024

I just did it in the spirit of it being the more conservative change, i.e. it is easy to unseal it later, but sealing it would be a breaking change.

So honestly no good reason.

@richard-uk1
Copy link
Collaborator

I just did it in the spirit of it being the more conservative change, i.e. it is easy to unseal it later, but sealing it would be a breaking change.

@ratmice Would you mind putting a comment on the sealing trait along these lines? Then future me knows we can remove the sealing if we need to :). Other than that LGTM.

src/common.rs Outdated
Comment on lines 9 to 11
/// A [sealed trait](https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/)
/// which stops this trait from being derived outside the library. This could be relaxed
/// in the future if there is are good reasons to allow outside impls.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A [sealed trait](https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/)
/// which stops this trait from being derived outside the library. This could be relaxed
/// in the future if there is are good reasons to allow outside impls.
/// A [sealed trait](https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/)
/// which stops [super::FloatFuncs] from being implemented outside kurbo. This could be relaxed
/// in the future if there are good reasons to allow outside impls.

I'd also probably change 'outside' to 'external' in the final line

Copy link
Contributor Author

@ratmice ratmice Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should really be fixed now in 4a849c3

@ratmice
Copy link
Contributor Author

ratmice commented Feb 8, 2024

If it's alright i'll squash/force push this all down to one commit with the initial commit message.

@DJMcNab
Copy link
Member

DJMcNab commented Feb 8, 2024

That would be alright, although that will also happen as part of the merge process

This trait, with the addition of sin/sinf is needed to build peniko
with the `--no-default-features --features libm` combination.

The approach taken here is that rather than duplicating
this common module in peniko, to make it pub, and add the sin/sinf.
for peniko.
src/common.rs Outdated Show resolved Hide resolved
src/common.rs Outdated Show resolved Hide resolved
ratmice and others added 2 commits February 8, 2024 23:07
Co-authored-by: Daniel McNab <[email protected]>
Co-authored-by: Daniel McNab <[email protected]>
Copy link
Collaborator

@richard-uk1 richard-uk1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, feel free to make any changes/improvements if you'd like

@ratmice
Copy link
Contributor Author

ratmice commented Feb 9, 2024

I'm happy with it as is, and ran the peniko patch on top of this revision through it's CI.

I don't believe anything in a peniko review would require changes here, but feel like I
should wait for at least a cursory a review there until landing this here.

@ratmice ratmice merged commit 223a487 into linebender:main Feb 9, 2024
14 checks passed
@ratmice ratmice deleted the pub_floatfuncs branch February 12, 2024 17:11
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.

3 participants