Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Sep 5, 2023

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 as format_args!, but will call panic_fmt with the generated arguments. It generates a new function in HIR for the formatting setup and panic_fmt call.

Now this:

panic!("test {}", a);

will expand to:

#[inline(never)]
#[track_caller]
#[cold]
fn panic_cold<'a, A0: Display>(a0: &'a A0) -> ! {
    panic_fmt(Arguments::new_v1(&["test "], &[Argument::new_display(a0)]))
}
panic_cold(&a);

This should also reduce noise from panics in the performance measurements of #115129.

cc @m-ou-se

@rustbot
Copy link
Collaborator

rustbot commented Sep 5, 2023

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 5, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Sep 6, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@oli-obk
Copy link
Contributor

oli-obk commented Sep 6, 2023

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

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 6, 2023
@bors
Copy link
Contributor

bors commented Sep 6, 2023

⌛ Trying commit b48cbfbcbcbed74b13dec5b38f9517ef0194698a with merge 2e7ecf2eecd97617a1834d5e7f5d3ee4d43f4cdd...

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk assigned oli-obk and m-ou-se and unassigned petrochenkov Sep 6, 2023
@m-ou-se
Copy link
Member

m-ou-se commented Sep 6, 2023

It'd be cool if we had a feature that allowed this entire change to just be the addition of a #[outline] { … } block in the panic!() macro.

@rustbot
Copy link
Collaborator

rustbot commented Sep 6, 2023

The Miri subtree was changed

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

#[cold]
#[track_caller]
#[inline(never)]
#[rustc_do_not_const_check] // Allow the call to `panic_display`.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@RalfJung RalfJung Sep 6, 2023

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.

@RalfJung
Copy link
Member

RalfJung commented Sep 6, 2023

In order to do this, a panic_args! builtin macro is introduced. It has the same arguments as format_args!, but will call panic_fmt with the generated arguments. It generates a new function in HIR for the formatting setup and panic_fmt call.

So there's no way to do this as a regular macro?

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
...........................................................................................F.......F 300
.FFF................................................................................................ 400
........................................................
tests/fail/panic/no_std.rs FAILED:
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--target" "x86_64-unknown-linux-gnu" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rlib" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rmeta" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rlib" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rmeta" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rlib" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rmeta" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rlib" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rmeta" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rlib" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rmeta" "--extern" "miri_test_deps=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/miri-test-deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/parking_lot_core-9bdeebce5fa9e654" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/getrandom-411106a7d83e1c5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/proc-macro2-7355c72729c2ad6f" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/syn-cf93ee47d0aaea1b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/quote-b08851073e1a2b12" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/log-0ca1ad2c2013013e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/lock_api-d760b7744004939a" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/tokio-0abef059fb4058da" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/libc-2918892fb0531a5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/memchr-27ff70bb6751a99e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui" "tests/fail/panic/no_std.rs" "--edition" "2021"

actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/panic/no_std.stderr` to the actual output
--- tests/fail/panic/no_std.stderr
--- tests/fail/panic/no_std.stderr
+++ <stderr output>
... 12 lines skipped ...
 LL |     panic!("blarg I am dead")
-   = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
+   = note: this error originates in the macro `$crate::panic_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
... 4 lines skipped ...


full stderr:
panicked at tests/fail/panic/no_std.rs:31:5:
blarg I am dead
##[error]  --> tests/fail/panic/no_std.rs:37:5
   |
LL |     core::intrinsics::abort();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ the program aborted execution
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ the program aborted execution
   |
   = note: inside `panic_handler` at tests/fail/panic/no_std.rs:37:5: 37:30
note: inside `start`
  --> tests/fail/panic/no_std.rs:31:5
   |
LL |     panic!("blarg I am dead")
   = note: this error originates in the macro `$crate::panic_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace


error: aborting due to previous error




tests/fail/panic/panic_abort1.rs FAILED:
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--target" "x86_64-unknown-linux-gnu" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rlib" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rmeta" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rlib" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rmeta" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rlib" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rmeta" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rlib" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rmeta" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rlib" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rmeta" "--extern" "miri_test_deps=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/miri-test-deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/parking_lot_core-9bdeebce5fa9e654" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/getrandom-411106a7d83e1c5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/proc-macro2-7355c72729c2ad6f" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/syn-cf93ee47d0aaea1b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/quote-b08851073e1a2b12" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/log-0ca1ad2c2013013e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/lock_api-d760b7744004939a" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/tokio-0abef059fb4058da" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/libc-2918892fb0531a5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/memchr-27ff70bb6751a99e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui" "tests/fail/panic/panic_abort1.rs" "-C" "panic=abort" "--edition" "2021"

actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/panic/panic_abort1.stderr` to the actual output
--- tests/fail/panic/panic_abort1.stderr
---



tests/fail/panic/panic_abort2.rs FAILED:
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--target" "x86_64-unknown-linux-gnu" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rlib" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rmeta" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rlib" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rmeta" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rlib" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rmeta" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rlib" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rmeta" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rlib" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rmeta" "--extern" "miri_test_deps=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/miri-test-deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/parking_lot_core-9bdeebce5fa9e654" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/getrandom-411106a7d83e1c5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/proc-macro2-7355c72729c2ad6f" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/syn-cf93ee47d0aaea1b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/quote-b08851073e1a2b12" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/log-0ca1ad2c2013013e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/lock_api-d760b7744004939a" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/tokio-0abef059fb4058da" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/libc-2918892fb0531a5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/memchr-27ff70bb6751a99e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui" "tests/fail/panic/panic_abort2.rs" "-C" "panic=abort" "--edition" "2021"

actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/panic/panic_abort2.stderr` to the actual output
--- tests/fail/panic/panic_abort2.stderr
---



tests/fail/panic/panic_abort3.rs FAILED:
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--target" "x86_64-unknown-linux-gnu" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rlib" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rmeta" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rlib" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rmeta" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rlib" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rmeta" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rlib" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rmeta" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rlib" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rmeta" "--extern" "miri_test_deps=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/miri-test-deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/parking_lot_core-9bdeebce5fa9e654" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/getrandom-411106a7d83e1c5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/proc-macro2-7355c72729c2ad6f" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/syn-cf93ee47d0aaea1b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/quote-b08851073e1a2b12" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/log-0ca1ad2c2013013e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/lock_api-d760b7744004939a" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/tokio-0abef059fb4058da" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/libc-2918892fb0531a5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/memchr-27ff70bb6751a99e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui" "tests/fail/panic/panic_abort3.rs" "-C" "panic=abort" "--edition" "2021"

actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/panic/panic_abort3.stderr` to the actual output
--- tests/fail/panic/panic_abort3.stderr
---



tests/fail/panic/panic_abort4.rs FAILED:
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--target" "x86_64-unknown-linux-gnu" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rlib" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d7a4052c69114fb5.rmeta" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rlib" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-5991f5d440f70ef3.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-be8bd72d0542ae04.rmeta" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rlib" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-a80677ae50b20308.rmeta" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rlib" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/librand-e12fe57f7c618d0e.rmeta" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rlib" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-803279deabcf4836.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-603931411f1c023e.rmeta" "--extern" "miri_test_deps=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/miri-test-deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/parking_lot_core-9bdeebce5fa9e654" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/getrandom-411106a7d83e1c5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/proc-macro2-7355c72729c2ad6f" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/syn-cf93ee47d0aaea1b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/quote-b08851073e1a2b12" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/log-0ca1ad2c2013013e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/lock_api-d760b7744004939a" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/tokio-0abef059fb4058da" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/libc-2918892fb0531a5b" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/debug/build/memchr-27ff70bb6751a99e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui/miri/x86_64-unknown-linux-gnu/debug/deps" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui" "tests/fail/panic/panic_abort4.rs" "-C" "panic=abort" "--edition" "2021"

actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/panic/panic_abort4.stderr` to the actual output
--- tests/fail/panic/panic_abort4.stderr
---
test result: FAIL. 5 tests failed, 448 tests passed, 3 ignored, 0 filtered out
Error: 
   0: tests failed

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/compiletest-35881ecbf657b161 --quiet` (exit status: 1)
Build completed unsuccessfully in 0:02:57

@Zoxc
Copy link
Contributor Author

Zoxc commented Sep 6, 2023

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?

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.

It'd be cool if we had a feature that allowed this entire change to just be the addition of a #[outline] { … } block in the panic!() macro.

We can kind of do this with closures today: outline(|| { ... }). The code generation of closures is not ideal at the moment however. We also don't have functional const closures.

So there's no way to do this as a regular macro?

We need to do the outlining inside the expansion of format_args!, so we either need to modify it or duplicate it. The former being the easier option taken by this PR.

@petrochenkov
Copy link
Contributor

Looks like I got unassigned, but I also wouldn't want a special case threaded through all the compilation for a minor optimization.
The macro expansion changes in particular are a "no go" from me.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 6, 2023

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 {
Copy link
Member

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.

@petrochenkov petrochenkov removed their assignment Sep 6, 2023
@Zoxc
Copy link
Contributor Author

Zoxc commented Sep 6, 2023

The macro expansion changes in particular are a "no go" from me.

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(super) which inherit constness would work. For example None.map(const(super) |a| { a }) would work in macros both in and out of const fns.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 6, 2023

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

@cjgillot cjgillot self-assigned this Sep 6, 2023
@lqd
Copy link
Member

lqd commented Sep 6, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2e7ecf2eecd97617a1834d5e7f5d3ee4d43f4cdd): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

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 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 @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.3% [0.2%, 3.3%] 27
Regressions ❌
(secondary)
1.8% [0.4%, 3.3%] 52
Improvements ✅
(primary)
-0.8% [-1.4%, -0.3%] 9
Improvements ✅
(secondary)
-0.8% [-0.8%, -0.8%] 1
All ❌✅ (primary) 0.8% [-1.4%, 3.3%] 36

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
3.1% [0.4%, 13.0%] 13
Regressions ❌
(secondary)
2.6% [1.8%, 3.4%] 2
Improvements ✅
(primary)
-4.1% [-11.5%, -0.4%] 9
Improvements ✅
(secondary)
-2.3% [-4.7%, -0.7%] 4
All ❌✅ (primary) 0.2% [-11.5%, 13.0%] 22

Cycles

Results

This 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.

mean range count
Regressions ❌
(primary)
3.5% [0.6%, 4.4%] 10
Regressions ❌
(secondary)
3.1% [1.4%, 4.3%] 38
Improvements ✅
(primary)
-1.8% [-2.6%, -1.0%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.3% [-2.6%, 4.4%] 13

Binary size

Results

This 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.

mean range count
Regressions ❌
(primary)
0.4% [0.0%, 1.1%] 81
Regressions ❌
(secondary)
0.9% [0.2%, 1.2%] 79
Improvements ✅
(primary)
-0.3% [-2.1%, -0.0%] 16
Improvements ✅
(secondary)
-0.2% [-0.8%, -0.1%] 15
All ❌✅ (primary) 0.3% [-2.1%, 1.1%] 97

Bootstrap: 627.572s -> 632.07s (0.72%)
Artifact size: 317.85 MiB -> 318.63 MiB (0.25%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 6, 2023
@Zoxc
Copy link
Contributor Author

Zoxc commented Sep 8, 2023

Closures doesn't work here, as we need return, yield, etc. to be handled properly.

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.

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 17, 2023
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.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 1, 2023
…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.
@bors
Copy link
Contributor

bors commented Oct 1, 2023

☔ The latest upstream changes (presumably #115670) made this pull request unmergeable. Please resolve the merge conflicts.

@apiraino
Copy link
Contributor

apiraino commented Oct 5, 2023

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 ready, thanks!

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 5, 2023
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Oct 6, 2023
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.
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Oct 6, 2023
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.
@JohnCSimon
Copy link
Member

@Zoxc

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
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@Zoxc Zoxc closed this Nov 14, 2023
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 7, 2024
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.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.