Skip to content

Commit dde0381

Browse files
committed
Auto merge of rust-lang#116042 - Nadrieril:linear-pass-take-2, r=<try>
[Experiment] Rewrite exhaustiveness in one pass Arm reachability checking does a quadratic amount of work: for each arm we check if it is reachable given the arms above it. This feels wasteful since we often end up re-exploring the same cases when we check for exhaustiveness. This PR is an attempt to check reachability at the same time as exhaustiveness. This opens the door to a bunch of code simplifications I'm very excited about. The main question is whether I can get actual performance gains out of this. I had started the experiment in rust-lang#111720 but I can't reopen it. r? `@ghost`
2 parents 7b4d9e1 + 1efc54c commit dde0381

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ fn expand_or_pat<'p, 'tcx>(pat: &'p Pat<'tcx>) -> Vec<&'p Pat<'tcx>> {
9999
#[derive(Clone, PartialEq, Eq)]
100100
pub(crate) struct IntRange {
101101
range: RangeInclusive<u128>,
102-
/// Keeps the bias used for encoding the range. It depends on the type of the range and
103-
/// possibly the pointer size of the current architecture. The algorithm ensures we never
104-
/// compare `IntRange`s with different types/architectures.
105-
bias: u128,
106102
}
107103

108104
impl IntRange {
@@ -150,7 +146,7 @@ impl IntRange {
150146
}?;
151147

152148
let val = val ^ bias;
153-
Some(IntRange { range: val..=val, bias })
149+
Some(IntRange { range: val..=val })
154150
}
155151

156152
#[inline]
@@ -171,7 +167,7 @@ impl IntRange {
171167
// This should have been caught earlier by E0030.
172168
bug!("malformed range pattern: {}..={}", lo, (hi - offset));
173169
}
174-
IntRange { range: lo..=(hi - offset), bias }
170+
IntRange { range: lo..=(hi - offset) }
175171
})
176172
}
177173

@@ -194,7 +190,7 @@ impl IntRange {
194190
let (lo, hi) = self.boundaries();
195191
let (other_lo, other_hi) = other.boundaries();
196192
if lo <= other_hi && other_lo <= hi {
197-
Some(IntRange { range: max(lo, other_lo)..=min(hi, other_hi), bias: self.bias })
193+
Some(IntRange { range: max(lo, other_lo)..=min(hi, other_hi) })
198194
} else {
199195
None
200196
}
@@ -221,7 +217,7 @@ impl IntRange {
221217
fn to_pat<'tcx>(&self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Pat<'tcx> {
222218
let (lo, hi) = self.boundaries();
223219

224-
let bias = self.bias;
220+
let bias = IntRange::signed_bias(tcx, ty);
225221
let (lo, hi) = (lo ^ bias, hi ^ bias);
226222

227223
let env = ty::ParamEnv::empty().and(ty);
@@ -304,8 +300,6 @@ impl IntRange {
304300
impl fmt::Debug for IntRange {
305301
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
306302
let (lo, hi) = self.boundaries();
307-
let bias = self.bias;
308-
let (lo, hi) = (lo ^ bias, hi ^ bias);
309303
write!(f, "{lo}")?;
310304
write!(f, "{}", RangeEnd::Included)?;
311305
write!(f, "{hi}")
@@ -402,7 +396,7 @@ impl SplitIntRange {
402396
(JustBefore(n), AfterMax) => n..=u128::MAX,
403397
_ => unreachable!(), // Ruled out by the sorting and filtering we did
404398
};
405-
IntRange { range, bias: self.range.bias }
399+
IntRange { range }
406400
})
407401
}
408402
}

0 commit comments

Comments
 (0)