rust-lang / rust-playground

The Rust Playground
https://play.rust-lang.org/
Apache License 2.0
1.2k stars 203 forks source link

"Show LLVM IR" and "Show ASM" are missing some functions #1032

Closed RalfJung closed 6 months ago

RalfJung commented 6 months ago

I tried this code:

pub fn foo(x: i32) -> i32 { x }

Then I [edit: switched to release mode,] clicked "show LLVM IR" and expected to see the IR for this function. However, the generated LLVM IR doesn't contain any function.

RalfJung commented 6 months ago

Interestingly, adding #[inline(never)] helps. But this is new, we used to be able to see the LLVM IR of functions without extra shenanigans like that.

I wonder if this is related to https://github.com/rust-lang/rust/pull/116505, Cc @saethlin

RalfJung commented 6 months ago

Ah I guess this explains it. However that also says

And then wait for us to fix the inliner visibility issue, it is a bug and we should get to it eventually.

Is that bug tracked anywhere?

shepmaster commented 6 months ago

I wonder if this is related to rust-lang/rust#116505

Almost certainly. See also https://github.com/rust-lang/rust-playground/commit/03c098a67339a729c8744d92270751c5a869b880 and https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/.E2.9C.94.20Beta.20no.20longer.20creates.20assembly.20for.20small.20optimized.20libs

saethlin commented 6 months ago

Is that bug tracked anywhere?

No. Probably I should track the whole tangled mess of the reachability analysis, MIR inlining with its query cycle avoidance, MIR collection, instantiation modes, and the various exceptions to that whole system that are carved out for special functions. I'm barely smart enough to hack on this system, but I'm getting better. Right now all I can really do is point out that it's troubling, not do anything to improve it.

But none of this is actually going to fix the situation for the playground and compiler explorer. People got used to the previous behavior of the compiler, where a hand-written fn item without any attributes would be eagerly codegenned in the current crate. This is at odds with making an efficient compiler, because in some situations we have learned that it is less work to lower in callers (if they exist!) rather than lower eagerly. (note the widespread perf improvements when cross-crate-inlining landed)

It is entirely plausible that we add a compiler flag to produce the behavior that tools like the playground want. But I don't know how to get that stabilized (compiler explorer at least seems not that interested in using an unstable option to produce the old behavior), and in the current situation in the compiler I am not even sure how to implement it without perturbing optimization of functions that call a cross-crate-inlinable function. If you press "Show LLVM IR" or "Show ASM" in the playground and get different output than you do locally because locally you're not using a playground-only flag, that seems like it significantly degrades the value of this feature.

RalfJung commented 6 months ago

That still seems worth an issue. Closing in favor of https://github.com/rust-lang/rust/issues/119850.

@shepmaster feel free to reopen if you want to keep this visible in the playground issue tracker as well.