Add extra unchecked_disjoint_bitor implementations.#147368
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use |
|
@rustbot label +T-libs-api -T-libs r? libs-api |
This comment has been minimized.
This comment has been minimized.
943d050 to
845a872
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
r? libs-api |
This comment has been minimized.
This comment has been minimized.
845a872 to
39c4367
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
39c4367 to
ac624b5
Compare
This comment has been minimized.
This comment has been minimized.
ac624b5 to
41533fe
Compare
This comment has been minimized.
This comment has been minimized.
41533fe to
4f310fa
Compare
This comment has been minimized.
This comment has been minimized.
4f310fa to
c24ec23
Compare
There was a problem hiding this comment.
Seems reasonable to me but should get a @rust-lang/libs-api okay.
@rustbot label +I-libs-api-nominated
r? tgross35
| } | ||
|
|
||
| /// Same value as `self | other`, but UB if any bit position is set in both inputs. | ||
| /// Disjoint, bitwise or. Computes `self | rhs`, assuming no one bits in common. |
There was a problem hiding this comment.
"assuming no one bits in common" -> "assuming there are no one bits in common."
Or something like "Computes self | rhs given the precondition that no set bits of the inputs overlap."
| /// `((a as u32) << 16) | (b as u32)`, that's fine, as the backend will | ||
| /// know those sides of the `|` are disjoint without needing help. | ||
| /// Practically, this requires that `self | rhs`, `self ^ rhs`, and `self + rhs` all | ||
| /// yield the same result, allowing for any of the three to be emitted in code gen |
There was a problem hiding this comment.
Nit: "code gen" -> either "codegen" or "code generation"
There was a problem hiding this comment.
What is wrong with "code gen" ? It's already used in the repo: https://github.com/search?q=repo%3Arust-lang%2Frust%20%22code%20gen%22&type=code.
There was a problem hiding this comment.
Most of those hits are part of "code generation" https://github.com/search?q=repo%3Arust-lang%2Frust+%2Fcode+gen%5Cb%2F&type=code. Loosely I think "gen" is considered an abbreviation rather than a word that can stand on its own, but we do consider "codegen" to be one.
Also we have codegen-units, codegen-backend etc. rather than code-gen-units and code-gen-backend.
c24ec23 to
315ca01
Compare
…'i64', 'i128', and 'isize'; Update existing 'unchecked_disjoint_bitor' docs; Add 'must_use' to 'unchecked_disjoint_bitor';
315ca01 to
7d9b4e4
Compare
| if self { Ok(()) } else { Err(f()) } | ||
| } | ||
|
|
||
| /// Disjoint, bitwise or. Computes `self | rhs`, assuming inequality. |
There was a problem hiding this comment.
| /// Disjoint, bitwise or. Computes `self | rhs`, assuming inequality. | |
| /// Disjoint, bitwise or. Computes `self | rhs`, assuming at most one is `true`. |
Right, or no? I'd expect (false, false) to be valid.
| /// #![feature(disjoint_bitor)] | ||
| /// | ||
| /// assert_eq!( | ||
| /// // SAFETY: `false` and `true` are inequal. |
There was a problem hiding this comment.
| /// // SAFETY: `false` and `true` are inequal. | |
| /// // SAFETY: `false` and `true` have no bits in common. |
As above.
There was a problem hiding this comment.
I actually requested this move away from talking about bits with booleans, since I don't think users should need to think about the representation when thinking about values is sufficient. But looks like I gave a bad suggestion here.
So perhaps "has only one true" or "has at most one true"?
There was a problem hiding this comment.
Adding a false, false test to the doc would be good too
There was a problem hiding this comment.
| /// // SAFETY: `false` and `true` are inequal. | |
| /// // SAFETY: `false` and `true` are not both `true`. |
| /// | ||
| /// # Safety | ||
| /// | ||
| /// This results in undefined behaviour if `self` and `rhs` are equal. |
There was a problem hiding this comment.
| /// This results in undefined behaviour if `self` and `rhs` are equal. | |
| /// This results in undefined behavior if `self` and `rhs` are both `true`. |
As above.
Nit: We generally use American spellings.
| pub const unsafe fn unchecked_disjoint_bitor(self, rhs: Self) -> Self { | ||
| assert_unsafe_precondition!( | ||
| check_language_ub, | ||
| "bool::unchecked_disjoint_bitor cannot bitor equal values", |
There was a problem hiding this comment.
| "bool::unchecked_disjoint_bitor cannot bitor equal values", | |
| "bool::unchecked_disjoint_bitor cannot bitor overlapping ones", |
As above.
There was a problem hiding this comment.
Similarly, maybe "more than one true"
There was a problem hiding this comment.
| "bool::unchecked_disjoint_bitor cannot bitor equal values", | |
| "bool::unchecked_disjoint_bitor cannot bitor two `true` values", |
| ( | ||
| lhs: bool = self, | ||
| rhs: bool = rhs, | ||
| ) => lhs != rhs, |
There was a problem hiding this comment.
| ) => lhs != rhs, | |
| ) => !(lhs && rhs), |
Right? As above, I'd expect (false, false) to be valid.
|
We discussed this in today's libs-api meeting; we're happy to add these functions. Thanks! |
|
Just a couple of small remaining review comments @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
View all comments
Tracking issue: #135758.
This PR implements the
unchecked_disjoint_bitormethod for additional types:Our
disjoint_bitorintrinsic is already implemented for these types. This method specifically is also already present on unsigned, integral types.Additionally, this PR rewrites the existing docs for
unchecked_disjoint_bitorand adds themust_useattribute to the method.