-
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
More powerful const panic #90488
More powerful const panic #90488
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit c3ea64c with merge 513ad0280218aa8bfcb61c04b8d0384fceb042ea... |
This comment has been minimized.
This comment has been minimized.
(FYI, you may want to wait to fix tests until after the bors try run finishes; IIRC, sometimes pushing will cancel a try.) |
☀️ Try build successful - checks-actions |
Queued 513ad0280218aa8bfcb61c04b8d0384fceb042ea with parent db062de, future comparison URL. |
Finished benchmarking commit (513ad0280218aa8bfcb61c04b8d0384fceb042ea): comparison url. Summary: This change led to large relevant mixed results 🤷 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking 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 led 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 |
arg_new!(new_pointer, Pointer); | ||
arg_new!(new_binary, Binary); | ||
arg_new!(new_lower_exp, LowerExp); | ||
arg_new!(new_upper_exp, UpperExp); |
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.
Can these be inlined into the format_args!() expansion?
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.
These are generic functions so I think yes.
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 actually meant can we inline their definition into the format_args!() expansion and omit those function definitions themself.
fc830ab
to
c3ea64c
Compare
(Pushed to the wrong branch) |
This comment has been minimized.
This comment has been minimized.
Create `core::fmt::ArgumentV1` with generics instead of fn pointer Split from (and prerequisite of) rust-lang#90488, as this seems to have perf implication. `@rustbot` label: +T-libs
Create `core::fmt::ArgumentV1` with generics instead of fn pointer Split from (and prerequisite of) rust-lang#90488, as this seems to have perf implication. `@rustbot` label: +T-libs
@nbdd0121 this has conflicts to be resolved, once done we can get this reviewed quickly after that |
Summary of the zulip thread: There are three ways to continue:
Ralf and I consider option 2 to be problematic and would prefer to go with option 3. We can always go for option 2 later, but if we start with it we can't revert to option 3. That said, we need a feature gate for this anyway, so we could just merge it modulo some additional tests making sure the feature gate works and split out option 3 under a separate gate later. |
In order to make #96496 work in constant environments (or even a future stabilization), this PR or functionality is a must have. |
This PR has been stagnated due to lack of strong motivating use case -- I am glad that it now has one! |
Can you elaborate on what functionality of this PR is needed? Afaict option 3 is sufficient for #96496 |
If we have |
That sounds like a bug in the implementation of #96496. Inside a |
That'll make a const fn and a non-const fn behave differently even if the const fn is not called in const context. |
you cannot call non-const fn from const fn at all. Did you flip |
const _: () = {
let a = 1;
assert!(a != 1);
}; Currently works but such thing won't be possible in #96496 without constant |
As long as #96496 only requires integers and booleans to be formattable, then it will work out of the box. If it requires arbitrary types to be formattable (e.g. |
Yes, types are arbitrary but all must implement |
ah perfect. If you are going via trait bounds instead of just syntax, then it will reject all types that do not implement |
Thanks! Looking forward to see const _: () = {
let a = 1i32;
panic!("Something {}", a);
}; Work someday |
This is what will happen for all other traits, too, not just Debug/Display. On the PR itself: I would like to move this PR along. But neither Ralf nor I will approve the current version. I know you feel strongly for allowing arbitrary types to be printed in const eval, even if they are unprintable (e.g. pointers). While I personally don't ever want this, and think you should not propose it, I think the right way to get this approved in your version would be an RFC/lang-team-MCP. Your proposed scheme just diverges too far from what we have right now, it can't just be a simple feature and stabilization. Please consider restricting your implementation to builtin types that are guaranteed to get const evaluable Debug and Display impls |
Closing this based on comment. |
Add a
const_panic_extra
feature gate that enables const panic to panic with any format arguments.It should make the example given in the rust-lang/rfcs#2345 possible:
The mechanism implemented in this PR essentially extracts arguments from const-eval
Arguments
and delegate the formatting to formatting machinary that's compiled with rustc. Currently only these types are formatted:impl<T: Display> for &Display
)String
(the only constString
is empty string)Arguments
dyn Trait
ifTrait
is one of the formatting traits.Other types will be formatted to
<failed to format {ty}>
.I think it's possible to require that only types that can be correctly formatted are accepted by having an additional marker type, but that'll require const trait impl and specialization like this:
IMO it's okay to accept types that couldn't be formatted, given that const panic messages are considered diagnostics. It'll also make constification of
assert_eq!
easier (which uses&dyn Debug
internally) since we current have no way to represent&dyn ~const ConstDebug
.I implement the feature in this way:
Result::unwrap
const;I plan to file/work on a few follow up PRs if this one is accepted:
Result::unwrap
Debug
implementation is derivedThis is a bulky PR, but I've separated it to individually meaningful commits so I'd suggest to review by commits. Some changes are made to
ArgumentV1::new
to allow theconst_panic_extra
being used withoutconst_fn_fn_ptr_basics
andconst_mut_refs
. Given this is hot code I'd suggest a perf run.r? @oli-obk
@rustbot label: T-compiler A-const-eval