Ask questionsSome closures are not inlined in release mode
Consider the following code (playground):
fn main() {
let err = Err(());
let _: usize = err.unwrap_or_else(|err| err_exit(err));
unreachable!();
}
fn err_exit(_: ()) -> ! {
std::process::exit(1);
}
When compiled with rustc 1.36, it gives the following assembly:
core::result::Result<T,E>::unwrap_or_else:
pushq %rax
callq playground::main::{{closure}}
ud2
playground::main:
pushq %rax
callq core::result::Result<T,E>::unwrap_or_else
ud2
playground::main::{{closure}}:
pushq %rax
callq playground::err_exit
ud2
playground::err_exit:
pushq %rax
movl $1, %edi
callq *std::process::exit@GOTPCREL(%rip)
ud2
Note how the closure is not inlined, even though it would be trivial to do so (replace callq playground::main::{{closure}} with callq playground::err_exit).
Answer
questions
dotdash
There was already a bug report at https://bugs.llvm.org/show_bug.cgi?id=26495
I commented there with what I found out so far.
Related questions