rust-lang / rust-lang/rust

`rustc_force_inline` used in `core` fails when called from `alloc`

Open
#148,915 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-mir-opt-inlining requires-internal-features requires-nightly T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

In https://github.com/rust-lang/rust/pull/148725 I tried to use rustc_force_inline (cc https://github.com/rust-lang/rust/pull/134082) on the following

/// Used in `try {}` blocks so the type produced in the `?` desugaring
/// depends on the residual type `R` and the output type of the block `O`,
/// but importantly not on the contextual type the way it would be if
/// we called `<_ as FromResidual>::from_residual(r)` directly.
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
// needs to be `pub` to avoid `private type` errors
#[expect(unreachable_pub)]
#[rustc_force_inline]
#[lang = "into_try_type"]
pub fn residual_into_try_type<R: Residual<O>, O>(r: R) -> <R as Residual<O>>::TryType {
    FromResidual::from_residual(r)
}

since it's only called directly to constrain type inference, and is never allowed to be called by users.

However, it failed in CI because https://triage.rust-lang.org/gha-logs/rust-lang/rust/55265405601

	[TIMING:start] check::PrepareStdRmetaSysroot { build_compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: i686-pc-windows-gnu }
[TIMING:start] check::Std { build_compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: i686-pc-windows-gnu, crates: [] }
##[group]Checking stage1 library artifacts (stage1:x86_64-unknown-linux-gnu -> stage1:i686-pc-windows-gnu)
[...]
	error: `ops::try_trait::residual_into_try_type` could not be inlined into `Box::<T>::try_map` but is required to be inlined
   --> library/alloc/src/boxed.rs:462:21
    |
462 |                     f(value)?,
    |                     ^^^^^^^^^ ...`ops::try_trait::residual_into_try_type` called here
    |
    = note: could not be inlined due to: implementation limitation -- MIR unavailable
error: `ops::try_trait::residual_into_try_type` could not be inlined into `Box::<T>::try_map` but is required to be inlined
   --> library/alloc/src/boxed.rs:466:28
    |
466 |             try { Box::new(f(*this)?) }
    |                            ^^^^^^^^^ ...`ops::try_trait::residual_into_try_type` called here
    |
    = note: could not be inlined due to: implementation limitation -- MIR unavailable
error: `ops::try_trait::residual_into_try_type` could not be inlined into `Rc::<T>::try_map` but is required to be inlined
   --> library/alloc/src/rc.rs:728:27
    |
728 |             try { Rc::new(f(&*this)?) }
    |                           ^^^^^^^^^^ ...`ops::try_trait::residual_into_try_type` called here
    |
    = note: could not be inlined due to: implementation limitation -- MIR unavailable

I would have expected this to work -- why wouldn't we have MIR for core when compiling alloc? -- so figured I'd file the bug even though it's an internal feature. This is the kind of place where I'd really like to use the feature in core, after all.

Makes me wonder if there's something odd about cycle checking going on, or similar?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the stage1 cross-compilation failure described in the CI log, then inspect the residual_into_try_type call sites in library/alloc/src/boxed.rs and library/alloc/src/rc.rs. Trace why the core function has no MIR when used from alloc; done means the reported rustc_force_inline errors no longer occur for these calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.