Skip to content

Comments

Remove redundant call to check_codegen_attributes_extra in Inliner#152984

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
stellanomia:remove-redundant-inline-check
Feb 23, 2026
Merged

Remove redundant call to check_codegen_attributes_extra in Inliner#152984
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
stellanomia:remove-redundant-inline-check

Conversation

@stellanomia
Copy link
Contributor

Inside try_inlining, check_codegen_attributes is called first. This function internally invokes check_codegen_attributes_extra.
However, immediately after that returns, try_inlining calls check_codegen_attributes_extra again.

First call:

fn check_codegen_attributes<'tcx, I: Inliner<'tcx>>(
inliner: &I,
callsite: &CallSite<'tcx>,
callee_attrs: &CodegenFnAttrs,
) -> Result<(), &'static str> {
let tcx = inliner.tcx();
if let InlineAttr::Never = callee_attrs.inline {
return Err("never inline attribute");
}
if let OptimizeAttr::DoNotOptimize = callee_attrs.optimize {
return Err("has DoNotOptimize attribute");
}
inliner.check_codegen_attributes_extra(callee_attrs)?;

Second call:

fn try_inlining<'tcx, I: Inliner<'tcx>>(
inliner: &I,
caller_body: &mut Body<'tcx>,
callsite: &CallSite<'tcx>,
) -> Result<std::ops::Range<BasicBlock>, &'static str> {
let tcx = inliner.tcx();
check_mir_is_available(inliner, caller_body, callsite.callee)?;
let callee_attrs = tcx.codegen_instance_attrs(callsite.callee.def);
let callee_attrs = callee_attrs.as_ref();
check_inline::is_inline_valid_on_fn(tcx, callsite.callee.def_id())?;
check_codegen_attributes(inliner, callsite, callee_attrs)?;
inliner.check_codegen_attributes_extra(callee_attrs)?;
let terminator = caller_body[callsite.block].terminator.as_ref().unwrap();

    // Inside try_inlining:
    check_codegen_attributes(inliner, callsite, callee_attrs)?; // Internally calls `check_codegen_attributes_extra`
    inliner.check_codegen_attributes_extra(callee_attrs)?;      // Called again here

In try_inlining, inliner is held as a shared reference (&I). Since check_codegen_attributes_extra takes &self and does not rely on interior mutability or external state, there does not seem to be any state change between the two calls.

Therefore, the second call appears to be redundant.

Currently, check_codegen_attributes is only called from try_inlining, and check_codegen_attributes_extra appears to be called only from these two locations. It seems reasonable for the check_codegen_attributes wrapper to handle the hook automatically.

@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2026

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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. labels Feb 22, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, mir, mir-opt
  • compiler, mir, mir-opt expanded to 68 candidates
  • Random selection from 15 candidates

@JonathanBrouwer
Copy link
Contributor

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 22, 2026

📌 Commit febd3b9 has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Feb 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 22, 2026
…e-check, r=JonathanBrouwer

Remove redundant call to `check_codegen_attributes_extra` in Inliner

Inside `try_inlining`, `check_codegen_attributes` is called first. This function internally invokes `check_codegen_attributes_extra`.
However, immediately after that returns, `try_inlining` calls `check_codegen_attributes_extra` again.

First call:
https://github.com/rust-lang/rust/blob/7ec34defe9e62a1a6946d3e700b5903d8dc89ece/compiler/rustc_mir_transform/src/inline.rs#L800-L814

Second call:
https://github.com/rust-lang/rust/blob/7ec34defe9e62a1a6946d3e700b5903d8dc89ece/compiler/rustc_mir_transform/src/inline.rs#L598-L612

```rust
    // Inside try_inlining:
    check_codegen_attributes(inliner, callsite, callee_attrs)?; // Internally calls `check_codegen_attributes_extra`
    inliner.check_codegen_attributes_extra(callee_attrs)?;      // Called again here
```

In `try_inlining`, inliner is held as a shared reference (`&I`). Since `check_codegen_attributes_extra` takes `&self` and does not rely on interior mutability or external state, there does not seem to be any state change between the two calls.

Therefore, the second call appears to be redundant.

Currently, `check_codegen_attributes` is only called from `try_inlining`, and `check_codegen_attributes_extra` appears to be called only from these two locations. It seems reasonable for the `check_codegen_attributes` wrapper to handle the hook automatically.
jhpratt added a commit to jhpratt/rust that referenced this pull request Feb 22, 2026
…e-check, r=JonathanBrouwer

Remove redundant call to `check_codegen_attributes_extra` in Inliner

Inside `try_inlining`, `check_codegen_attributes` is called first. This function internally invokes `check_codegen_attributes_extra`.
However, immediately after that returns, `try_inlining` calls `check_codegen_attributes_extra` again.

First call:
https://github.com/rust-lang/rust/blob/7ec34defe9e62a1a6946d3e700b5903d8dc89ece/compiler/rustc_mir_transform/src/inline.rs#L800-L814

Second call:
https://github.com/rust-lang/rust/blob/7ec34defe9e62a1a6946d3e700b5903d8dc89ece/compiler/rustc_mir_transform/src/inline.rs#L598-L612

```rust
    // Inside try_inlining:
    check_codegen_attributes(inliner, callsite, callee_attrs)?; // Internally calls `check_codegen_attributes_extra`
    inliner.check_codegen_attributes_extra(callee_attrs)?;      // Called again here
```

In `try_inlining`, inliner is held as a shared reference (`&I`). Since `check_codegen_attributes_extra` takes `&self` and does not rely on interior mutability or external state, there does not seem to be any state change between the two calls.

Therefore, the second call appears to be redundant.

Currently, `check_codegen_attributes` is only called from `try_inlining`, and `check_codegen_attributes_extra` appears to be called only from these two locations. It seems reasonable for the `check_codegen_attributes` wrapper to handle the hook automatically.
rust-bors bot pushed a commit that referenced this pull request Feb 23, 2026
Rollup of 9 pull requests

Successful merges:

 - #152229 (Remove deterministic picking from query cycle handling)
 - #152970 (extend unpin noalias tests to cover mutable references)
 - #149783 (stabilize `cfg_select!`)
 - #151744 (fix refining_impl_trait suggestion with return_type_notation)
 - #152366 (Add try_shrink_to and try_shrink_to_fit to Vec)
 - #152640 (Add direct link to rustc-dev-guide in README)
 - #152963 (Revert "Stabilize `str_as_str`")
 - #152984 (Remove redundant call to `check_codegen_attributes_extra` in Inliner)
 - #152987 (Use `HashStable` derive in more places)
@rust-bors rust-bors bot merged commit 499fca9 into rust-lang:main Feb 23, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 23, 2026
rust-timer added a commit that referenced this pull request Feb 23, 2026
Rollup merge of #152984 - stellanomia:remove-redundant-inline-check, r=JonathanBrouwer

Remove redundant call to `check_codegen_attributes_extra` in Inliner

Inside `try_inlining`, `check_codegen_attributes` is called first. This function internally invokes `check_codegen_attributes_extra`.
However, immediately after that returns, `try_inlining` calls `check_codegen_attributes_extra` again.

First call:
https://github.com/rust-lang/rust/blob/7ec34defe9e62a1a6946d3e700b5903d8dc89ece/compiler/rustc_mir_transform/src/inline.rs#L800-L814

Second call:
https://github.com/rust-lang/rust/blob/7ec34defe9e62a1a6946d3e700b5903d8dc89ece/compiler/rustc_mir_transform/src/inline.rs#L598-L612

```rust
    // Inside try_inlining:
    check_codegen_attributes(inliner, callsite, callee_attrs)?; // Internally calls `check_codegen_attributes_extra`
    inliner.check_codegen_attributes_extra(callee_attrs)?;      // Called again here
```

In `try_inlining`, inliner is held as a shared reference (`&I`). Since `check_codegen_attributes_extra` takes `&self` and does not rely on interior mutability or external state, there does not seem to be any state change between the two calls.

Therefore, the second call appears to be redundant.

Currently, `check_codegen_attributes` is only called from `try_inlining`, and `check_codegen_attributes_extra` appears to be called only from these two locations. It seems reasonable for the `check_codegen_attributes` wrapper to handle the hook automatically.
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Feb 24, 2026
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#152229 (Remove deterministic picking from query cycle handling)
 - rust-lang/rust#152970 (extend unpin noalias tests to cover mutable references)
 - rust-lang/rust#149783 (stabilize `cfg_select!`)
 - rust-lang/rust#151744 (fix refining_impl_trait suggestion with return_type_notation)
 - rust-lang/rust#152366 (Add try_shrink_to and try_shrink_to_fit to Vec)
 - rust-lang/rust#152640 (Add direct link to rustc-dev-guide in README)
 - rust-lang/rust#152963 (Revert "Stabilize `str_as_str`")
 - rust-lang/rust#152984 (Remove redundant call to `check_codegen_attributes_extra` in Inliner)
 - rust-lang/rust#152987 (Use `HashStable` derive in more places)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants