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

Adjust inlining attributes around panic_immediate_abort #104999

Merged
merged 1 commit into from
Dec 2, 2022

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Nov 28, 2022

The goal of panic_immediate_abort is to permit the panic runtime and formatting code paths to be optimized away. But while poking through some disassembly of a small program compiled with that option, I found that was not the case. Enabling LTO did address that specific issue, but enabling LTO is a steep price to pay for this feature doing its job.

This PR fixes that, by tweaking two things:

  • All the slice indexing functions that we const_eval_select on get #[inline]. objdump -dC told me that originally some _ct functions could end up in an executable. I won't pretend to understand what's going on there.
  • Normalize attributes across all panic! wrappers: use inline(never) + cold normally, and inline when panic_immediate_abort is enabled.

But also, with LTO and panic_immediate_abort enabled, this patch knocks ~709 kB out of the .text segment of librustc_driver.so. That is slightly surprising to me, my best theory is that this shifts some inlining earlier in compilation, enabling some subsequent optimizations. The size improvement of librustc_driver.so with panic_immediate_abort due to this patch is greater with LTO than without LTO, which I suppose backs up this theory.

I do not know how to test this. I would quite like to, because I think what this is solving was an accidental regression. This only works with -Zbuild-std which is a cargo flag, and thus can't be used in a rustc codegen test.

r? @thomcc


I do not seriously think anyone is going to use a compiler built with panic_immediate_abort, but I wanted a big complicated Rust program to try this out on, and the compiler is such.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 28, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

library/core/src/slice/index.rs Show resolved Hide resolved
library/core/src/slice/index.rs Show resolved Hide resolved
@thomcc
Copy link
Member

thomcc commented Nov 28, 2022

I don't think we want to change runtime things for the non-panic_immediate_abort case.

@saethlin saethlin marked this pull request as draft November 28, 2022 06:41
@saethlin
Copy link
Member Author

Based on some of your prompting elsewhere I think I have found other opportunities for tweaks along these lines. I want to run those down then decide if they belong in here.

@thomcc
Copy link
Member

thomcc commented Nov 28, 2022

@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 Nov 28, 2022
@bors
Copy link
Contributor

bors commented Nov 28, 2022

⌛ Trying commit 5b0baa9614a34329e90f08b8f70a5df86425be45 with merge 17e1dcef1c425dbbe0e2f0d4f6f1fcf962d1cc90...

@bors
Copy link
Contributor

bors commented Nov 28, 2022

☀️ Try build successful - checks-actions
Build commit: 17e1dcef1c425dbbe0e2f0d4f6f1fcf962d1cc90 (17e1dcef1c425dbbe0e2f0d4f6f1fcf962d1cc90)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (17e1dcef1c425dbbe0e2f0d4f6f1fcf962d1cc90): comparison URL.

Overall result: no relevant changes - no 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.

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

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 29, 2022
@saethlin saethlin force-pushed the immediate-abort-inlining branch from 5b0baa9 to 906c360 Compare November 29, 2022 14:24
@saethlin saethlin marked this pull request as ready for review November 29, 2022 14:24
@saethlin
Copy link
Member Author

@rustbot ready

@thomcc
Copy link
Member

thomcc commented Nov 29, 2022

LGTM, thanks.

@bors r+

@bors
Copy link
Contributor

bors commented Nov 29, 2022

📌 Commit 906c360 has been approved by thomcc

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 29, 2022
@bors
Copy link
Contributor

bors commented Nov 30, 2022

⌛ Testing commit 906c360 with merge 96c520d2784be83c65edcec5d87bb5dde74b1a6e...

@bors
Copy link
Contributor

bors commented Nov 30, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 30, 2022
@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)
.......... (80/90)
.......... (90/90)


/checkout/src/test/rustdoc-gui/basic-code.goml basic-code... FAILED
[ERROR] (line 3) Error: Execution context was destroyed, most likely because of a navigation.: for command `assert-count: (".src-line-numbers", 1)`
Build completed unsuccessfully in 0:02:19

@saethlin
Copy link
Member Author

saethlin commented Dec 1, 2022

@thomcc The failure looks like some kind of network-related flake to me? Maybe I'm just grasping because I don't understand how this could cause any issues. Can you retry?

@thomcc
Copy link
Member

thomcc commented Dec 2, 2022

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 2, 2022
@bors
Copy link
Contributor

bors commented Dec 2, 2022

⌛ Testing commit 906c360 with merge 32e613b...

@bors
Copy link
Contributor

bors commented Dec 2, 2022

☀️ Test successful - checks-actions
Approved by: thomcc
Pushing 32e613b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 2, 2022
@bors bors merged commit 32e613b into rust-lang:master Dec 2, 2022
@rustbot rustbot added this to the 1.67.0 milestone Dec 2, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (32e613b): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-0.4%, -0.4%] 1

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…=thomcc

Adjust inlining attributes around panic_immediate_abort

The goal of `panic_immediate_abort` is to permit the panic runtime and formatting code paths to be optimized away. But while poking through some disassembly of a small program compiled with that option, I found that was not the case. Enabling LTO did address that specific issue, but enabling LTO is a steep price to pay for this feature doing its job.

This PR fixes that, by tweaking two things:
* All the slice indexing functions that we `const_eval_select` on get `#[inline]`. `objdump -dC` told me that originally some `_ct` functions could end up in an executable. I won't pretend to understand what's going on there.
* Normalize attributes across all `panic!` wrappers: use `inline(never) + cold` normally, and `inline` when `panic_immediate_abort` is enabled.

But also, with LTO and `panic_immediate_abort` enabled, this patch knocks ~709 kB out of the `.text` segment of `librustc_driver.so`. That is slightly surprising to me, my best theory is that this shifts some inlining earlier in compilation, enabling some subsequent optimizations. The size improvement of `librustc_driver.so` with `panic_immediate_abort` due to this patch is greater with LTO than without LTO, which I suppose backs up this theory.

I do not know how to test this. I would quite like to, because I think what this is solving was an accidental regression. This only works with `-Zbuild-std` which is a cargo flag, and thus can't be used in a rustc codegen test.

r? `@thomcc`

---

I do not seriously think anyone is going to use a compiler built with `panic_immediate_abort`, but I wanted a big complicated Rust program to try this out on, and the compiler is such.
@saethlin saethlin deleted the immediate-abort-inlining branch March 15, 2023 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants