Skip to content

Tracking issue for wrapping stabilization #27755

Closed
@aturon

Description

@aturon
Member

The std::num::wrapping module provides a trait, OverflowingOps, that permits overflowing arithmetic on primitive types and tells whether an overflow occurred.

Other methods, like saturating_add and wrapping_add, are included directly as inherent methods on these types.

It's not clear whether the overflowing_foo methods 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 the wrapping module would be removed.

Activity

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
B-unstableBlocker: Implemented in the nightly compiler and unstable.
on Aug 12, 2015
changed the title [-]Tracking issee for `wrapping` stabilization[/-] [+]Tracking issue for `wrapping` stabilization[/+] on Aug 12, 2015
petrochenkov

petrochenkov commented on Aug 21, 2015

@petrochenkov
Contributor
bmastenbrook

bmastenbrook commented on Dec 10, 2015

@bmastenbrook

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?

aturon

aturon commented on Dec 16, 2015

@aturon
MemberAuthor

Nominating for discussion at libs team meeting.

alexcrichton

alexcrichton commented on Dec 17, 2015

@alexcrichton
Member

🔔 This issue is now entering its final comment period for tweaked stabilization 🔔

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 checked_* and saturating_* methods as well. There are some missing (like saturating_mul or checked_neg), and making sure we've got a full suite everywhere would ensure consistency!

added
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
and removed on Dec 17, 2015
petrochenkov

petrochenkov commented on Dec 18, 2015

@petrochenkov
Contributor

I'd like to remind the libs team about existence of RFC 1218.
One of the main points of it is to stabilize integer casts together with other arithmetic operations.
A comment to the RFC, which I linked above, also suggests an alternative to making checked_* and friends inherent methods, namely traits like

// Possibly an unstable trait with stable methods
trait IntAdd<Rhs = Self>: Add<Rhs> {
    fn wrapping_add(self) -> Self::Output;
    fn checked_add(self) -> Option<Self::Output>;
    /* other add operations */
}

Casts can't be implemented as inherent methods without double dispatch through yet another trait. Arithmetic operations like checked_add can be inherent methods, if the operands are supposed to be always homogeneous, but I don't see motivation for preferring inherent methods to a trait in this case.
I'm against stabilizing arithmetic methods unless they are gathered together with casts and arranged in one coherent picture.

glaebhoerl

glaebhoerl commented on Dec 18, 2015

@glaebhoerl
Contributor

@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 wrapping_op methods have already been stabilized as inherent methods, doing likewise for the others would at least be consistent.

SimonSapin

SimonSapin commented on Dec 18, 2015

@SimonSapin
Contributor

Arithmetic operations like checked_add can be inherent methods, if the operands are supposed to be always homogeneous

Primitive numeric types only implement Add with homogeneous operands.

And yes, the advantage of inherent methods is to not require users to import the trait and not "pollute" the prelude.

6 remaining items

huonw

huonw commented on Jan 8, 2016

@huonw
Member
added a commit that references this issue on Jan 14, 2016

Auto merge of #30466 - alexcrichton:move-wrapping-and-fill-out, r=aturon

alexcrichton

alexcrichton commented on Jan 15, 2016

@alexcrichton
Member

The libs team discussed this in triage recently and the decision was to stabilize

added a commit that references this issue on Jan 17, 2016

Rollup merge of rust-lang#30943 - alexcrichton:stabilize-1.7, r=aturon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexcrichton@eddyb@SimonSapin@aturon@huonw

      Issue actions

        Tracking issue for `wrapping` stabilization · Issue #27755 · rust-lang/rust