-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add a Ranged
wrapper struct to replace the rustc_scalar_range_valid attributes
#103724
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
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.
Quick look at the diff LGTM, aside from CI of course. Just the one nit that was already mentioned.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 7fba3595ed0357e7c844ca106473c4cc968dc4d9 with merge 6a3b3432328dc85a19d780ed0e3b8be54628d292... |
☀️ Try build successful - checks-actions |
Queued 6a3b3432328dc85a19d780ed0e3b8be54628d292 with parent edf0182, future comparison URL. |
Finished benchmarking commit (6a3b3432328dc85a19d780ed0e3b8be54628d292): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Warning ⚠: The following benchmark(s) failed to build:
Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit e5c9675481e48da4a88e473f0d5c39a4d2f11fd6 with merge 8983d23afaf5483644a8983f75cb575b8e430d59... |
☀️ Try build successful - checks-actions |
Queued 8983d23afaf5483644a8983f75cb575b8e430d59 with parent 432b1a4, future comparison URL. |
Finished benchmarking commit (8983d23afaf5483644a8983f75cb575b8e430d59): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Warning ⚠: The following benchmark(s) failed to build:
Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
☔ The latest upstream changes (presumably #104591) made this pull request unmergeable. Please resolve the merge conflicts. |
Various cleanups around scalar layout restrictions Pulled out of rust-lang#103724
Big 👍 from me! The RFC about attributes had to spend so much effort on describing parsing rules and such that just completely disappear if it can go into const generics as normal Rust values that already have all that defined, and it's more useful to boot to be able to make it generic! |
Unfortunately I don't believe we can eliminate the perf regression unless we codegen |
@oli-obk You've convinced me. I'm going to close RFC 3334 in favor of this. I do agree that we shouldn't stabilize this until we can write the range in terms of the Given a range based on |
The ranges given are wraparound, so there's no issue with
The LLVM perf regression due to the extra field access is still fairly annoying and I am exploring not adding a level of indirection, but desugaring the existing unstable attributes to a (not surface-syntax representable) pattern type. Pattern types are essentially a pair of an existing type and a pattern that restricts said type to a subset. So for example If this experiment succeeds for fields of the NonZero and NonNull types, I will write up a proper proposal to add it to the surface syntax and replacing the existing These pattern types have all the same advantages of this PR's wrapper struct, but avoids nesting things unnecessarily in structs. |
#[unstable(feature = "ranged_int", issue = "none")] | ||
#[rustc_const_unstable(feature = "ranged_int", issue = "none")] | ||
#[inline(always)] | ||
pub const fn get(self) -> T { |
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.
Why do the get
and new_unchecked
implementations require T: CheckInRange
when they don't seem to need it? And if it is needed, shouldn't the struct itself or at least the Deref
implementation also have this requirement? Otherwise, you can easily bypass the requirement with transmute
(for new_unchecked
) and deref
(for get
), the latter of which would be the most concerning since it's safe and usually automatic.
/// A helper trait until we can declare `struct Ranged<T, const RANGE: RangeInclusive<T>>(T);`. | ||
/// This is not meant to ever be stabilized. | ||
#[unstable(feature = "ranged_int", issue = "none")] | ||
pub trait CheckInRange { |
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.
Shouldn't the CheckInRange
trait be unsafe
to implement since Ranged::new
depends on its correct implementation?
This is definitely something that can be fixed later, but one clear thing that will need to be worked around is how |
Closing in favor of #107606 |
r? @joshtriplett
blocked on a decision on rust-lang/rfcs#3334
This PR removes the attribute and instead adds a type to the standard library that takes a field type and a const generic range to constraint that field type. All the previous logic that was required in the compiler to make the attribute sound has been removed and replaced by library functions and privacy rules.
It also eliminated all uses of
cfg_attr(pointer_width=xxx)
, as we can now just use const eval andusize
/isize
to abstract over the pointer sized integer ranges.The main limitation of the current implementation is that
struct Foo<T, const C: T>(T);
is not legal Rust yet. It is impossible as of yet to use generic parameters as the type of generic constants. Even with this limitation, I believe the compiler simplifications brought by this PR are important enough to warrant reconsidering the attribute stabilization RFC. Though I do not expect this type to get stabilized before const generics of generic types.Zulip discussion on this topic