-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Try to hoist the conversion of diverging calls to aborts to a layer above MIR lowering #122956
Comments
Two questions here from a
|
Only if optimizations are enabled; we want this behavior in debug builds too.
This issue we're talking on right now is about improving my PR that's linked in the original issue description, which is linked to (because it solves) this issue: #121552. The problem reported in that issue is the harm. The run-make test that's in my linked PR is a demonstration of the desired use case. |
Okay, thank you! To check my understanding, the issue is caused because some targets link before optimizing and debug builds may not optimize at all. There are also crates (maybe only My first thought is to use explicit aborts in anything that is compiled before From my perspective the ideal is |
Okay, I re-read what I wrote above and I think I'm still a bit confused. Try 2: In order to compile the code generator, we use functions defined in certain crates. Those crates may have other functions that depend on So what I think I missed above is that there may be a need to refactor those crates before using Again, please let me know if I'm totally off base here. |
Nope, Code review is absolutely not a suitable replacement for automation. In this case it's especially not suitable, because no matter how good the code review is on
There is no such thing, really. rust/compiler/rustc_monomorphize/src/lib.rs Lines 50 to 76 in 3bec617
And then should_codegen_locally accounts for the fact that #[inline] and generic functions are compiled locally instead of being linked to.
|
I'm looking at the cranelift
I'm having trouble finding any reference to
This is not clear from any of the linked discussion. Blame my lack of experience, but I'm not seeing it. Is this because |
compiler-builtins is here: https://github.com/rust-lang/compiler-builtins/ |
When debug assertions are enabled, the assertions that the compiler adds contain a call to a symbol that is in All the panic helpers are
What you're getting at here is the part of the problem that I don't personally understand. The
The reverse of this is a potential solution. |
Okay, I am getting a much better picture (and kicking myself for not seeing that As you pointed out, core is a declared dependency: Cargo.toml I see core being imported but not used in a lot places? The Regardless, if Top-down inlining seems like a fairly general solution that would solve this issue and possibly other problems, although I don't have any guess as to how difficult it would be to implement. // if only...
#[inline_crate]
use core; |
Yeah, you're describing the possible solution I was alluding to in that last paragraph. We can't apply the inlining optimization, but we can do local codegen (which is confusingly called inlining by some people and also some places in the compiler) which drops the linkage requirement, but statics must be instantiated only once, so they'll need a different solution. |
Hmm, can you give some more background info on local codegen? I haven't seen this used anywhere before but it definitely seems useful enough to already exist. I'm starting to get some idea of where a cycle could occur:
On first inspection, Solution 0: #122580Replace calls into Solution A: Fused MIRIIUC (and that's a big if), this is your most recent proposal. We compile In some sense this is adding another compiler option to fuse MIR graphs before sending them to the code generator. Again IIUC, the reason I think this is a pretty re-usable and elegant solution. But for completeness, here are some other thoughts: Solution B: Abstraction RefinementThe above cycle is at the crate-level of granularity, so to resolve it we could move down an abstraction level to functions.
Yada yada yada... Ultimately this needs to terminate. In theory proving termination is hard. In practice I can't imagine this function-level dependency being more than like 3 layers deep. Solution C: Crate-version dependencyInstead of having |
Basically, this function and all users of it: rust/compiler/rustc_monomorphize/src/collector.rs Lines 931 to 933 in 25acbbd
That's not an easy set of things to track down, but the monomorphization system in rustc is definitely one of the worst-maintained parts. The core idea is that some items are compiled in the crate that uses them, not the crate that defines them. |
In #122580 I added some code that prevents the magic
compiler_builtins
crate from linking againstcore
. 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 fromcore
that are never called. We have those declarations because of this loop:rust/compiler/rustc_codegen_llvm/src/base.rs
Lines 87 to 89 in d6eb0f5
We have
MonoItem
s for the panic functions, and no calls to them. The key point is that we haveMonoItem
s for items that we know would be invalid to call.Is it possible to not have those
MonoItem
s in builds ofcompiler_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?The text was updated successfully, but these errors were encountered: