Refactor integer range handling in the usefulness algorithm#66326
Refactor integer range handling in the usefulness algorithm#66326bors merged 29 commits intorust-lang:masterfrom
Conversation
|
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
|
Actually I figured out a test case where |
| } | ||
| } | ||
|
|
||
| fn is_subrange(&self, other: &Self) -> bool { |
There was a problem hiding this comment.
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? |
varkor
left a comment
There was a problem hiding this comment.
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 <twingoow@gmail.com>
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:
Constandu128, and betweenConstructorandIntRangeAs 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_bitsfail for an integer constant value in that code ? What would that mean, and how do I construct a test case for this possibility ?