Skip to content

Commit 39c9a30

Browse files
authored
Unrolled build for rust-lang#118307
Rollup merge of rust-lang#118307 - scottmcm:tuple-eq-simpler, r=joshtriplett Remove an unneeded helper from the tuple library code Thanks to rust-lang#107022, this is just what `==` does, so we don't need the helper here anymore.
2 parents 899c895 + 4b3f115 commit 39c9a30

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

library/core/src/tuple.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,6 @@ macro_rules! maybe_tuple_doc {
154154
};
155155
}
156156

157-
#[inline]
158-
const fn ordering_is_some(c: Option<Ordering>, x: Ordering) -> bool {
159-
// FIXME: Just use `==` once that's const-stable on `Option`s.
160-
// This is mapping `None` to 2 and then doing the comparison afterwards
161-
// because it optimizes better (`None::<Ordering>` is represented as 2).
162-
x as i8
163-
== match c {
164-
Some(c) => c as i8,
165-
None => 2,
166-
}
167-
}
168-
169157
// Constructs an expression that performs a lexical ordering using method `$rel`.
170158
// The values are interleaved, so the macro invocation for
171159
// `(a1, a2, a3) < (b1, b2, b3)` would be `lexical_ord!(lt, opt_is_lt, a1, b1,
@@ -176,7 +164,7 @@ const fn ordering_is_some(c: Option<Ordering>, x: Ordering) -> bool {
176164
macro_rules! lexical_ord {
177165
($rel: ident, $ne_rel: ident, $a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {{
178166
let c = PartialOrd::partial_cmp(&$a, &$b);
179-
if !ordering_is_some(c, Equal) { ordering_is_some(c, $ne_rel) }
167+
if c != Some(Equal) { c == Some($ne_rel) }
180168
else { lexical_ord!($rel, $ne_rel, $($rest_a, $rest_b),+) }
181169
}};
182170
($rel: ident, $ne_rel: ident, $a:expr, $b:expr) => {

tests/codegen/comparison-operators-2-tuple.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ type TwoTuple = (i16, u16);
1010
//
1111
// The operators are all overridden directly, so should optimize easily.
1212
//
13-
// Yes, the `s[lg]t` is correct for the `[lg]e` version because it's only used
14-
// in the side of the select where we know the values are *not* equal.
13+
// slt-vs-sle and sgt-vs-sge don't matter because they're only used in the side
14+
// of the select where we know the values are not equal, and thus the tests
15+
// use a regex to allow either, since unimportant changes to the implementation
16+
// sometimes result in changing what LLVM decides to emit for this.
1517
//
1618

1719
// CHECK-LABEL: @check_lt_direct
1820
// CHECK-SAME: (i16 noundef %[[A0:.+]], i16 noundef %[[A1:.+]], i16 noundef %[[B0:.+]], i16 noundef %[[B1:.+]])
1921
#[no_mangle]
2022
pub fn check_lt_direct(a: TwoTuple, b: TwoTuple) -> bool {
2123
// CHECK-DAG: %[[EQ:.+]] = icmp eq i16 %[[A0]], %[[B0]]
22-
// CHECK-DAG: %[[CMP0:.+]] = icmp slt i16 %[[A0]], %[[B0]]
24+
// CHECK-DAG: %[[CMP0:.+]] = icmp {{slt|sle}} i16 %[[A0]], %[[B0]]
2325
// CHECK-DAG: %[[CMP1:.+]] = icmp ult i16 %[[A1]], %[[B1]]
2426
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[CMP1]], i1 %[[CMP0]]
2527
// CHECK: ret i1 %[[R]]
@@ -31,7 +33,7 @@ pub fn check_lt_direct(a: TwoTuple, b: TwoTuple) -> bool {
3133
#[no_mangle]
3234
pub fn check_le_direct(a: TwoTuple, b: TwoTuple) -> bool {
3335
// CHECK-DAG: %[[EQ:.+]] = icmp eq i16 %[[A0]], %[[B0]]
34-
// CHECK-DAG: %[[CMP0:.+]] = icmp slt i16 %[[A0]], %[[B0]]
36+
// CHECK-DAG: %[[CMP0:.+]] = icmp {{slt|sle}} i16 %[[A0]], %[[B0]]
3537
// CHECK-DAG: %[[CMP1:.+]] = icmp ule i16 %[[A1]], %[[B1]]
3638
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[CMP1]], i1 %[[CMP0]]
3739
// CHECK: ret i1 %[[R]]
@@ -43,7 +45,7 @@ pub fn check_le_direct(a: TwoTuple, b: TwoTuple) -> bool {
4345
#[no_mangle]
4446
pub fn check_gt_direct(a: TwoTuple, b: TwoTuple) -> bool {
4547
// CHECK-DAG: %[[EQ:.+]] = icmp eq i16 %[[A0]], %[[B0]]
46-
// CHECK-DAG: %[[CMP0:.+]] = icmp sgt i16 %[[A0]], %[[B0]]
48+
// CHECK-DAG: %[[CMP0:.+]] = icmp {{sgt|sge}} i16 %[[A0]], %[[B0]]
4749
// CHECK-DAG: %[[CMP1:.+]] = icmp ugt i16 %[[A1]], %[[B1]]
4850
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[CMP1]], i1 %[[CMP0]]
4951
// CHECK: ret i1 %[[R]]
@@ -55,7 +57,7 @@ pub fn check_gt_direct(a: TwoTuple, b: TwoTuple) -> bool {
5557
#[no_mangle]
5658
pub fn check_ge_direct(a: TwoTuple, b: TwoTuple) -> bool {
5759
// CHECK-DAG: %[[EQ:.+]] = icmp eq i16 %[[A0]], %[[B0]]
58-
// CHECK-DAG: %[[CMP0:.+]] = icmp sgt i16 %[[A0]], %[[B0]]
60+
// CHECK-DAG: %[[CMP0:.+]] = icmp {{sgt|sge}} i16 %[[A0]], %[[B0]]
5961
// CHECK-DAG: %[[CMP1:.+]] = icmp uge i16 %[[A1]], %[[B1]]
6062
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[CMP1]], i1 %[[CMP0]]
6163
// CHECK: ret i1 %[[R]]

0 commit comments

Comments
 (0)