Try to hoist the conversion of diverging calls to aborts to a layer above MIR lowering
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
In https://github.com/rust-lang/rust/pull/122580 I added some code that prevents the magic compiler_builtins crate from linking against core. The replacement of calls happens as late as possible, so we end up with some odd behavior, where the LLVM IR and LLVM bitcode contain declarations of panic functions from core that are never called. We have those declarations because of this loop:
https://github.com/rust-lang/rust/blob/d6eb0f5a09247ff8443e68b4d17e0350c74bafb1/compiler/rustc_codegen_llvm/src/base.rs#L87-L89
We have MonoItems for the panic functions, and no calls to them. The key point is that we have MonoItems for items that we know would be invalid to call.
Is it possible to not have those MonoItems in builds of compiler_builtins?
One possible implementation of this would be to hoist this "error or abort on upstream call" to a MIR transform that's only run when building compiler_builtins. Then maybe we could drop the logic from cg_ssa?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the MonoItem loop in compiler/rustc_codegen_llvm/src/base.rs and the existing "error or abort on upstream call" logic in cg_ssa. Trace how MIR lowering handles compiler_builtins, then determine whether that behavior can move to a MIR transform used only for compiler_builtins. Done means invalid panic functions no longer produce unused MonoItems or declarations in its LLVM IR and bitcode.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100