-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Flatten numeric trait hierarchy and allow for user extensibility. #10387
Comments
Another idea would be to remove generic maths completely from |
Of course some traits would still be left - I'm mainly talking about the math functions. |
Nominating. |
I'm actually starting to think we should just zap the traits entirely (yay, back to the beginning!), and bring on the fragmentation! We still don't know how best to use traits yet, so maybe it would be better to leave that up to the community. |
The methods contained in `std::num::{Algebraic, Trigonometric, Exponential, Hyperbolic}` have now been moved into `std::num::Real`. This is part of an ongoing effort to simplify `std::num` (see issue rust-lang#10387). `std::num::RealExt` has also been removed from the prelude because it is not a commonly used trait.
The methods contained in `std::num::{Algebraic, Trigonometric, Exponential, Hyperbolic}` have now been moved into `std::num::Real`. This is part of an ongoing effort to simplify `std::num` (see issue #10387). `std::num::RealExt` has also been removed from the prelude because it is not a commonly used trait. r? @alexcrichton
Accepted for 1.0, P-backcompat-libs |
I'm now working on what I hope to become something like What I'm planning is to do is make How does this sound? |
👍 |
oo, i like this stuff. prevent lockin while making is sane to experiment. 👍 |
One less trait in `std::num` and three less exported in the prelude. cc. #10387
As part of #10387, this removes the `Primitive::{bits, bytes, is_signed}` methods and removes the trait's operator trait constraints for the reasons outlined below: - The `Primitive::{bits, bytes}` associated functions were originally added to reflect the existing `BITS` and `BYTES`statics included in the numeric modules. These statics are only exist as a workaround for Rust's lack of CTFE, and should be deprecated in the future in favor of using the `std::mem::size_of` function (see #11621). - `Primitive::is_signed` seems to be of little utility and does not seem to be used anywhere in the Rust compiler or libraries. It is also rather ugly to call due to the `Option<Self>` workaround for #8888. - The operator trait constraints are already covered by the `Num` trait.
This is part of the effort to simplify `std::num`, as tracked in issue rust-lang#10387.
This is part of the effort to simplify `std::num`, as tracked in issue #10387.
@bjz What's left on this? |
We could merge |
Move the rounding functions into the `std::num::Float` trait and then remove `std::num::Round`. This continues the flattening of the numeric traits tracked in rust-lang#10387. The aim is to make `std::num` very simple and tied to the built in types, leaving the definition of more complex numeric towers to third-party libraries. [breaking-change]
This pull request: - Merges the `Round` trait into the `Float` trait, continuing issue #10387. - Has floating point functions take their parameters by value. - Cleans up the formatting and organisation in the definition and implementations of the `Float` trait. More information on the breaking changes can be found in the commit messages.
@bjz What's left on this now? |
As a heads-up: as part of library stabilization, I am now working on removing all the numerics traits (as per @bjz's comment above. These traits are currently providing little value in |
👍 |
After some discussion with @alexcrichton, it looks like this is probably an RFC-worthy change. I will write an RFC in the near future and link to it from here. |
Nice! Are there going to be any issues in providing polymorphic functions in the bundled libraries though? |
@bjz The RFC will likely keep |
Can we remove them from the prelude? looks hopefully |
If we don't have them in the prelude, the various int/float methods they define won't be available by default (you'd have to import the traits). But these are pretty specialized methods, so that might be OK. What's are the drawbacks you see to having these in the prelude? |
It will handicap future experimentation with numeric APIs by polluting the method namespace. It would be a shame for folks to have to go down the route of the numeric-prelude in the future. Perhaps it would be cool if we could have: // num.rs
pub use Int::{count_ones, leading_zeros, ... };
pub trait Int: ... {
fn count_ones(self) -> uint;
fn leading_zeros(self) -> uint;
...
} |
RFC here: rust-lang/rfcs#369 |
I'm not sure if you're keeping so many // Replace these
fn pi() -> Self;
fn two_pi() -> Self;
fn frac_pi_2() -> Self;
fn frac_2_sqrtpi() -> Self;
// With these:
fn pi() -> Self;
fn two_pi() -> Self;
fn pi_over_2() -> Self;
fn 2_over_sqrtpi() -> Self; |
@bjz I think we can close this now, agreed? |
Closed :) |
Fix rust-lang#107877, etc. Fix rust-lang#10009 Fix rust-lang#10387 Fix rust-lang#107877 The fix is to verify that the associated item's trait is implemented before trying to project the item's type. r? `@Jarcho` --- changelog: ICE: [`needless_borrow`]: No longer panics on ambiguous projections [rust-lang#10403](rust-lang/rust-clippy#10403) <!-- changelog_checked -->
I am growing increasingly concerned that we are locking ourselves into a substandard numeric API heading toward 1.0 that will be hard to alter in the future without breaking a significant amount of client code.
Perhaps we could investigate simplifying the numeric trait hierarchy to be centered around built-in types. Perhaps the traits could be removed from the prelude as default instead using free, method wrapper functions as the primary form of using the numeric functions. This would make the API more amenable to being extended by users in the future. Perhaps an algebraic hierarchy could be included in
extra
.For example the
Round
,Fractional
,Algebraic
,Trigonometric
,Exponential
,Hyperbolic
,Real
andFloat
could be consolidated into a singleFloat
trait. Then the primary way of accessing the functions would be via the wrapper functions, eg.num::atan2(x, y)
.This is related to the numeric trait reform tracked at #4819
The text was updated successfully, but these errors were encountered: