Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `wrapping` stabilization #27755
Comments
aturon
added
T-libs
B-unstable
labels
Aug 12, 2015
sfackler
changed the title
Tracking issee for `wrapping` stabilization
Tracking issue for `wrapping` stabilization
Aug 12, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bmastenbrook
commented
Dec 10, 2015
|
I'm currently using the overflowing_* operations in a specialized bignum implementation, and it's a bit of a bother that they aren't stable. Given that these are implemented via LLVM intrinsics, is there any good reason for them to be removed? If they're not going to be removed, is there any way I can contribute to the stabilization? |
This comment has been minimized.
This comment has been minimized.
|
Nominating for discussion at libs team meeting. |
aturon
added
the
I-nominated
label
Dec 16, 2015
This comment has been minimized.
This comment has been minimized.
|
In triage discussion yesterday it was decided that the trait in this module should move to inherent methods on all the primitives, and we should likely fill out all the |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Dec 17, 2015
This comment has been minimized.
This comment has been minimized.
|
I'd like to remind the libs team about existence of RFC 1218.
Casts can't be implemented as inherent methods without double dispatch through yet another trait. Arithmetic operations like |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov I don't see the reason for preferring inherent methods over traits either (maybe it's just not having to import the trait?), but given that the existing |
This comment has been minimized.
This comment has been minimized.
Primitive numeric types only implement And yes, the advantage of inherent methods is to not require users to import the trait and not "pollute" the prelude. |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Dec 18, 2015
alexcrichton
referenced this issue
Dec 18, 2015
Merged
std: Move overflowing ops to inherent methods #30466
This comment has been minimized.
This comment has been minimized.
|
To clarify, yes, part of the motivation of inherent methods was doing away with the large soup of traits we used to have (and as @SimonSapin says, this allows you to avoid an explicit import). For numerics, specifically, we tried to move in the direction of concrete types and inherent methods, leaving abstractions/numeric hierarchy to traits than can be built externally and perhaps added later. This has been a general approach in the standard library: avoid premature abstraction. The trait system makes it easy to create abstractions after the fact, and we prefer to see strong use cases before committing to them. Finally, as @glaebhoerl points out, the existing stable API surface already takes this approach.
Most arithmetic methods are already stable. I don't understand the concern about packaging them together; can you elaborate? As I mentioned above, we're shy about numeric abstractions, having tried several times before 1.0 to build a hierarchy, before ultimately ditching the whole thing. I continue to think this needs to be baked out of tree, and don't see why it can't be. |
This comment has been minimized.
This comment has been minimized.
|
Ok, I've reviewed this again (I haven't touched my RFC or used these methods for a long time) and changed my position from "mildly against" to "don't care". Inherent methods don't prevent having equivalent trait methods in the future and inconsistencies between casts and other operators are not the end of the world. |
This comment has been minimized.
This comment has been minimized.
|
This is maybe off-topic, but since casts were mentioned I’d like to have fallible casts like |
bluss
referenced this issue
Dec 22, 2015
Merged
Add OpAssign to Wrapping<T>, etc. in core::num::wrapping #30523
This comment has been minimized.
This comment has been minimized.
|
Is there any reason why |
This comment has been minimized.
This comment has been minimized.
|
@eddyb Not that I know of. Probably just an oversight. |
This comment has been minimized.
This comment has been minimized.
|
cc #23975 |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Jan 12, 2016
bors
added a commit
that referenced
this issue
Jan 14, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this in triage recently and the decision was to stabilize |
aturon commentedAug 12, 2015
The
std::num::wrappingmodule provides a trait,OverflowingOps, that permits overflowing arithmetic on primitive types and tells whether an overflow occurred.Other methods, like
saturating_addandwrapping_add, are included directly as inherent methods on these types.It's not clear whether the
overflowing_foomethods are useful, and if so, whether there's any reason for them to live on a trait. Ideally, if we kept them, they'd move onto the primitive types, and thewrappingmodule would be removed.