-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Outline formatting code from the panic! macro #115562
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
cbc8dd1
to
b48cbfb
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
That's a lot of complexity for an optimization. Maybe we could wait until #111693 can be landed and then implement this as an actual outlining mir-opt? @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit b48cbfbcbcbed74b13dec5b38f9517ef0194698a with merge 2e7ecf2eecd97617a1834d5e7f5d3ee4d43f4cdd... |
This comment has been minimized.
This comment has been minimized.
It'd be cool if we had a feature that allowed this entire change to just be the addition of a |
b48cbfb
to
1666baa
Compare
The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
#[cold] | ||
#[track_caller] | ||
#[inline(never)] | ||
#[rustc_do_not_const_check] // Allow the call to `panic_display`. |
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.
panic_display
is a const fn
, so why is this attribute needed?
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.
It's constrained to only work with &'static str
by const checking, so we can't pass the argument of type &T
to it.
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.
Ah... that's un-pretty.
I think a better approach would be to generalize what happens to panic_display
. I'm imagining an attribute like #[const_panic_display]
such that all functions with this attribute
- are allowed to be called in const context if the argument type is
&str
- if evaluation reaches them, the magic hook kicks in (this branch)
That way, both the original fn panic_display
and the outlined functions you are adding here can just get that attribute, and we don't need all this rustc_do_not_const_check
and const_eval_select
stuff here.
So there's no way to do this as a regular macro? |
1666baa
to
3c80038
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
There's a fair bit of verbosity, not too much complexity. An actual outlining pass would be far more complex. I'm also not sure how effective such a pass would be more generally.
We can kind of do this with closures today:
We need to do the outlining inside the expansion of |
Looks like I got unassigned, but I also wouldn't want a special case threaded through all the compilation for a minor optimization. |
sorry ^^ input is of course welcome from anyone, just didn't want to keep you on the hook if I'm assigning myself. |
@@ -134,15 +136,56 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { | |||
} | |||
} | |||
|
|||
fn expr_might_diverge(e: &Expr<'_>) -> 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.
We have a really elaborate implementation fo diverging expressions in clippy_lints/src/manual_let_else.rs
called expr_diverges
. This can probably also be used here. For this, moving that function to clippy_utils
is probably the best thing to do.
I initially had a macro which expanded differently in const fns, but I did avoid using it for this PR. I can move the constness tracking from macro expansion to AST lowering now. Being able to write macros that work both in and out of const fns seems to be quite desirable though, but I think a language feature like |
const closures are definitely planned (#106003), so if they would simplify this PR significantly, then maybe we should postpone this PR and link to it from the tracking issue as something that gets unblocked by it |
it seems the bot didn't enqueue the perf run or the force push messed up reporting the try build completion @rust-timer build 2e7ecf2eecd97617a1834d5e7f5d3ee4d43f4cdd |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (2e7ecf2eecd97617a1834d5e7f5d3ee4d43f4cdd): 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 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.
Binary sizeResultsThis 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.
Bootstrap: 627.572s -> 632.07s (0.72%) |
Closures doesn't work here, as we need I think I can do this more in the standard library if I restrict the change to format argument below a fixed number. That may have a larger compile time hit however. |
Partially outline code inside the panic! macro This outlines code inside the panic! macro in some cases. This is split out from rust-lang#115562 to exclude changes to rustc.
…imulacrum Partially outline code inside the panic! macro This outlines code inside the panic! macro in some cases. This is split out from rust-lang#115562 to exclude changes to rustc.
☔ The latest upstream changes (presumably #115670) made this pull request unmergeable. Please resolve the merge conflicts. |
So, I had a cursory look here checking for progress. I think there a number of open comments here. I'm also looking at these two comments here and here, though not sure what's the current status and how do they compare with this patch. Anyway, switching to waiting on author for some feedbacks here and there, also for a rebase and a perf. run in need of triaging. Feel free to request a review with @rustbot author |
Partially outline code inside the panic! macro This outlines code inside the panic! macro in some cases. This is split out from rust-lang/rust#115562 to exclude changes to rustc.
Partially outline code inside the panic! macro This outlines code inside the panic! macro in some cases. This is split out from rust-lang/rust#115562 to exclude changes to rustc.
ping from triage - can you post your status on this PR? There hasn't been an update in a few months. Thanks! FYI: when a PR is ready for review, send a message containing |
Partially outline code inside the panic! macro This outlines code inside the panic! macro in some cases. This is split out from rust-lang/rust#115562 to exclude changes to rustc.
Partially outline code inside the panic! macro This outlines code inside the panic! macro in some cases. This is split out from rust-lang/rust#115562 to exclude changes to rustc.
This PR makes the
panic!
macro generate an inner function which contains the formatting setup code. This reduces the size of the code for panics in callers. It also allows LLVM to eliminate passing of the#[track_caller]
argument where it's statically known.In order to do this, a
panic_args!
builtin macro is introduced. It has the same arguments asformat_args!
, but will callpanic_fmt
with the generated arguments. It generates a new function in HIR for the formatting setup andpanic_fmt
call.Now this:
will expand to:
This should also reduce noise from panics in the performance measurements of #115129.
cc @m-ou-se