Skip to content

Conversation

CrooseGit
Copy link
Contributor

#[rustc_force_inline] is an internal-only attribute similar to #[inline(always)] but which emits an error if inlining cannot occur. rustc_force_inline uses the MIR inliner to do this and has limitations on where it can be applied to ensure that an error is always emitted if inlining can't happen (e.g. it can't be applied to trait methods because calls to those can't always be resolved).

#[rustc_force_inline] is motivated by AArch64 pointer authentication intrinsics where it is vital for the security properties of these intrinsics that they do not exist in standalone functions that could be used as gadgets in an exploit (if they could, then you could sign whatever pointers you want, for example, which is bad, but if you force inlining, then you can't jump to a reusable function containing only these instructions).

Since its initial implementation, #[rustc_force_inline] could only be applied to free functions. This can be relaxed to also allow inherent methods while still preserving the desired properties. In a work-in-progress patch for manual pointer authentication intrinsics, it is useful to introduce types with inherent methods that would need to be force inlined.

r? @saethlin

@rustbot
Copy link
Collaborator

rustbot commented Oct 1, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. labels Oct 1, 2025
@davidtwco davidtwco changed the title Extending #[rustc_foce_inline] to be applicable to inherent methods Extending #[rustc_force_inline] to be applicable to inherent methods Oct 1, 2025
@saethlin
Copy link
Member

saethlin commented Oct 1, 2025

Thank you for writing a thorough PR description.

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 1, 2025

📌 Commit 89bd8f3 has been approved by saethlin

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 Oct 1, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 2, 2025
…c_force_inline, r=saethlin

Extending `#[rustc_force_inline]` to be applicable to inherent methods

`#[rustc_force_inline]` is an internal-only attribute similar to `#[inline(always)]` but which emits an error if inlining cannot occur. rustc_force_inline uses the MIR inliner to do this and has limitations on where it can be applied to ensure that an error is always emitted if inlining can't happen (e.g. it can't be applied to trait methods because calls to those can't always be resolved).

`#[rustc_force_inline]` is motivated by AArch64 pointer authentication intrinsics where it is vital for the security properties of these intrinsics that they do not exist in standalone functions that could be used as gadgets in an exploit (if they could, then you could sign whatever pointers you want, for example, which is bad, but if you force inlining, then you can't jump to a reusable function containing only these instructions).

Since its initial implementation, `#[rustc_force_inline]` could only be applied to free functions. This can be relaxed to also allow inherent methods while still preserving the desired properties. In a work-in-progress patch for manual pointer authentication intrinsics, it is useful to introduce types with inherent methods that would need to be force inlined.

r? `@saethlin`
bors added a commit that referenced this pull request Oct 2, 2025
Rollup of 10 pull requests

Successful merges:

 - #146281 (Support `#[rustc_align_static]` inside `thread_local!`)
 - #146535 (mbe: Implement `unsafe` attribute rules)
 - #146585 (indexing: reword help)
 - #147004 (Tweak handling of "struct like start" where a struct isn't supported)
 - #147221 (Forbid `//@ compile-flags: -Cincremental=` in tests)
 - #147225 (Don't enable shared memory by default with Wasm atomics)
 - #147227 (implement `Box::take`)
 - #147231 (Extending `#[rustc_force_inline]` to be applicable to inherent methods)
 - #147233 (Initialize llvm submodule if not already the case to run citool)
 - #147236 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-
#147253 (comment)

jhpratt added a commit to jhpratt/rust that referenced this pull request Oct 2, 2025
…c_force_inline, r=saethlin

Extending `#[rustc_force_inline]` to be applicable to inherent methods

`#[rustc_force_inline]` is an internal-only attribute similar to `#[inline(always)]` but which emits an error if inlining cannot occur. rustc_force_inline uses the MIR inliner to do this and has limitations on where it can be applied to ensure that an error is always emitted if inlining can't happen (e.g. it can't be applied to trait methods because calls to those can't always be resolved).

`#[rustc_force_inline]` is motivated by AArch64 pointer authentication intrinsics where it is vital for the security properties of these intrinsics that they do not exist in standalone functions that could be used as gadgets in an exploit (if they could, then you could sign whatever pointers you want, for example, which is bad, but if you force inlining, then you can't jump to a reusable function containing only these instructions).

Since its initial implementation, `#[rustc_force_inline]` could only be applied to free functions. This can be relaxed to also allow inherent methods while still preserving the desired properties. In a work-in-progress patch for manual pointer authentication intrinsics, it is useful to introduce types with inherent methods that would need to be force inlined.

r? `@saethlin`
@matthiaskrgr
Copy link
Member

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 2, 2025
- Changes parser to allow application to inherent methods.
- Adds tests to confirm extended functionality works just as the existing.
@CrooseGit CrooseGit force-pushed the dev/reucru01/extend_rustc_force_inline branch from 89bd8f3 to 5bf5e71 Compare October 2, 2025 10:31
@bors
Copy link
Collaborator

bors commented Oct 2, 2025

@CrooseGit: 🔑 Insufficient privileges: Not in reviewers

@CrooseGit
Copy link
Contributor Author

@saethlin
Some diff files were missing, I have amended the commit and it should be fixed now.

@saethlin
Copy link
Member

saethlin commented Oct 2, 2025

Weird. I thought I had made sure PR CI would fail in that situation.

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 2, 2025

📌 Commit 5bf5e71 has been approved by saethlin

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 2, 2025
@bors
Copy link
Collaborator

bors commented Oct 2, 2025

⌛ Testing commit 5bf5e71 with merge 8d603ef...

@bors
Copy link
Collaborator

bors commented Oct 3, 2025

☀️ Test successful - checks-actions
Approved by: saethlin
Pushing 8d603ef to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 3, 2025
@bors bors merged commit 8d603ef into rust-lang:master Oct 3, 2025
11 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 3, 2025
Copy link
Contributor

github-actions bot commented Oct 3, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 5c7ae0c (parent) -> 8d603ef (this PR)

Test differences

Show 16 test diffs

Stage 1

  • [mir-opt] tests/mir-opt/inline/forced_closure_inherent.rs: [missing] -> pass (J1)
  • [mir-opt] tests/mir-opt/inline/forced_inherent.rs: [missing] -> pass (J1)
  • [mir-opt] tests/mir-opt/inline/forced_inherent_ambiguous.rs: [missing] -> pass (J1)
  • [mir-opt] tests/mir-opt/inline/forced_inherent_async.rs: [missing] -> pass (J1)
  • [mir-opt] tests/mir-opt/inline/forced_inherent_dead_code.rs: [missing] -> pass (J1)
  • [ui] tests/ui/force-inlining/inherent.rs: [missing] -> pass (J1)

Stage 2

  • [mir-opt] tests/mir-opt/inline/forced_closure_inherent.rs: [missing] -> pass (J0)
  • [mir-opt] tests/mir-opt/inline/forced_inherent.rs: [missing] -> pass (J0)
  • [mir-opt] tests/mir-opt/inline/forced_inherent_ambiguous.rs: [missing] -> pass (J0)
  • [mir-opt] tests/mir-opt/inline/forced_inherent_async.rs: [missing] -> pass (J0)
  • [mir-opt] tests/mir-opt/inline/forced_inherent_dead_code.rs: [missing] -> pass (J0)
  • [ui] tests/ui/force-inlining/inherent.rs: [missing] -> pass (J2)

Additionally, 4 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 8d603ef2879fd263f8e9aea340b4c035ed7973db --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-apple-various: 4603.5s -> 3080.5s (-33.1%)
  2. aarch64-apple: 9443.1s -> 7500.9s (-20.6%)
  3. dist-x86_64-freebsd: 6227.8s -> 5023.6s (-19.3%)
  4. dist-i686-msvc: 7921.7s -> 9085.6s (14.7%)
  5. pr-check-1: 1385.2s -> 1571.7s (13.5%)
  6. x86_64-gnu-distcheck: 6188.6s -> 6945.8s (12.2%)
  7. x86_64-gnu-llvm-20-3: 6164.3s -> 6805.3s (10.4%)
  8. dist-aarch64-msvc: 6172.1s -> 5655.7s (-8.4%)
  9. dist-x86_64-mingw: 9296.5s -> 8578.9s (-7.7%)
  10. i686-msvc-2: 7751.9s -> 8346.8s (7.7%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8d603ef): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
3.1% [3.1%, 3.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.1% [3.1%, 3.1%] 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.

Binary size

Results (primary 1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.1% [1.1%, 1.1%] 1

Bootstrap: 471.823s -> 472.119s (0.06%)
Artifact size: 387.78 MiB -> 387.77 MiB (-0.00%)

@rustbot rustbot added the perf-regression Performance regression. label Oct 3, 2025
@panstromek
Copy link
Contributor

perf triage:

clap_derive bimodal noise

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants