-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor integer range handling in the usefulness algorithm #66326
Conversation
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
Actually I figured out a test case where |
@@ -1418,6 +1427,12 @@ impl<'tcx> IntRange<'tcx> { | |||
} | |||
} | |||
|
|||
fn is_subrange(&self, other: &Self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a useful operation that could be added to the standard library on ranges; cc @dtolnay
@bors try @rust-timer queue |
Awaiting bors try build completion |
Refactor integer range handling in the usefulness algorithm Integer range handling had accumulated a lot of debt. This cleans up a lot of it. In particular this: - removes unnecessary conversions between `Const` and `u128`, and between `Constructor` and `IntRange` - clearly distinguishes between on the one hand ranges of integers that may or may not be matched exhaustively, and on the other hand ranges of non-integers that are never matched exhaustively and are compared using Const-based shenanigans - cleans up some overly complicated code paths - generally tries to be more idiomatic. As a nice side-effect, I measured a 10% perf increase on `unicode_normalization`. There's one thing that I feel remains to clean up: the [overlapping range check](#64007), which is currently quite ad-hoc. But that is intricate enough that I'm leaving it out of this PR. There's also one little thing I'm not sure I understand: can `try_eval_bits` fail for an integer constant value in that code ? What would that mean, and how do I construct a test case for this possibility ?
Hmm, it turns out I unknowingly fixed a bug: const BAR: &i32 = &42;
match &0 {
BAR => {}
_ => {}
} used to flag the first branch as unreachable. This looks similar to #65413. |
Does this fix #53708 as well? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like what you've done here. Just have a couple of very minor comments :)
@bors try @rust-timer queue |
Awaiting bors try build completion |
Refactor integer range handling in the usefulness algorithm Integer range handling had accumulated a lot of debt. This cleans up a lot of it. In particular this: - removes unnecessary conversions between `Const` and `u128`, and between `Constructor` and `IntRange` - clearly distinguishes between on the one hand ranges of integers that may or may not be matched exhaustively, and on the other hand ranges of non-integers that are never matched exhaustively and are compared using Const-based shenanigans - cleans up some overly complicated code paths - generally tries to be more idiomatic. As a nice side-effect, I measured a 10% perf increase on `unicode_normalization`. There's one thing that I feel remains to clean up: the [overlapping range check](#64007), which is currently quite ad-hoc. But that is intricate enough that I'm leaving it out of this PR. There's also one little thing I'm not sure I understand: can `try_eval_bits` fail for an integer constant value in that code ? What would that mean, and how do I construct a test case for this possibility ?
☀️ Try build successful - checks-azure |
Queued 9fabb30 with parent 374ad1b, future comparison URL. |
Finished benchmarking try commit 9fabb30, comparison URL. |
@bors rollup=never |
Only IntRange should need to worry about range exhaustiveness really.
That way no `ConstantRange` or `ConstantValue` ever needs to be converted to `IntRange`.
That condition was leftover from a refactor, and was probably not intended. In fact it can't trigger: it would require a ConstantValue of an integral type for which `try_eval_bits` fails. But since we only apply `subtract_ctors` to the output of `all_ctors`, this won't happen.
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
0e3ec65
to
694a511
Compare
Rebased onto master and applied latest reviews :) |
@bors r+ |
📌 Commit 694a511 has been approved by |
Refactor integer range handling in the usefulness algorithm Integer range handling had accumulated a lot of debt. This cleans up a lot of it. In particular this: - removes unnecessary conversions between `Const` and `u128`, and between `Constructor` and `IntRange` - clearly distinguishes between on the one hand ranges of integers that may or may not be matched exhaustively, and on the other hand ranges of non-integers that are never matched exhaustively and are compared using Const-based shenanigans - cleans up some overly complicated code paths - generally tries to be more idiomatic. As a nice side-effect, I measured a 10% perf increase on `unicode_normalization`. There's one thing that I feel remains to clean up: the [overlapping range check](#64007), which is currently quite ad-hoc. But that is intricate enough that I'm leaving it out of this PR. There's also one little thing I'm not sure I understand: can `try_eval_bits` fail for an integer constant value in that code ? What would that mean, and how do I construct a test case for this possibility ?
☀️ Test successful - checks-azure |
Integer range handling had accumulated a lot of debt. This cleans up a lot of it.
In particular this:
Const
andu128
, and betweenConstructor
andIntRange
As a nice side-effect, I measured a 10% perf increase on
unicode_normalization
.There's one thing that I feel remains to clean up: the overlapping range check, which is currently quite ad-hoc. But that is intricate enough that I'm leaving it out of this PR.
There's also one little thing I'm not sure I understand: can
try_eval_bits
fail for an integer constant value in that code ? What would that mean, and how do I construct a test case for this possibility ?