Skip to content

Commit 66b5f9d

Browse files
committed
Auto merge of rust-lang#137907 - compiler-errors:inline-fnonce, r=<try>
Inline `FnOnce`/`FnMut`/`Fn` shims once again cc rust-lang#137901 r? `@ghost`
2 parents daf5985 + 3be05c2 commit 66b5f9d

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Diff for: compiler/rustc_mir_transform/src/inline.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,6 @@ fn try_inlining<'tcx, I: Inliner<'tcx>>(
626626
return Err("implementation limitation");
627627
}
628628
if callsite.fn_sig.abi() == ExternAbi::RustCall {
629-
// FIXME: Don't inline user-written `extern "rust-call"` functions,
630-
// since this is generally perf-negative on rustc, and we hope that
631-
// LLVM will inline these functions instead.
632-
if callee_body.spread_arg.is_some() {
633-
return Err("user-written rust-call functions");
634-
}
635-
636629
let (self_arg, arg_tuple) = match &args[..] {
637630
[arg_tuple] => (None, arg_tuple),
638631
[self_arg, arg_tuple] => (Some(self_arg), arg_tuple),
@@ -642,17 +635,23 @@ fn try_inlining<'tcx, I: Inliner<'tcx>>(
642635
let self_arg_ty = self_arg.map(|self_arg| self_arg.node.ty(&caller_body.local_decls, tcx));
643636

644637
let arg_tuple_ty = arg_tuple.node.ty(&caller_body.local_decls, tcx);
645-
let ty::Tuple(arg_tuple_tys) = *arg_tuple_ty.kind() else {
646-
bug!("Closure arguments are not passed as a tuple");
638+
let arg_tys = if callee_body.spread_arg.is_some() {
639+
std::slice::from_ref(&arg_tuple_ty)
640+
} else {
641+
let ty::Tuple(arg_tuple_tys) = *arg_tuple_ty.kind() else {
642+
bug!("Closure arguments are not passed as a tuple");
643+
};
644+
arg_tuple_tys.as_slice()
647645
};
648646

649647
for (arg_ty, input) in
650-
self_arg_ty.into_iter().chain(arg_tuple_tys).zip(callee_body.args_iter())
648+
self_arg_ty.into_iter().chain(arg_tys.iter().copied()).zip(callee_body.args_iter())
651649
{
652650
let input_type = callee_body.local_decls[input].ty;
653651
if !util::sub_types(tcx, inliner.typing_env(), input_type, arg_ty) {
654652
trace!(?arg_ty, ?input_type);
655653
debug!("failed to normalize tuple argument type");
654+
println!("sub {input_type:?} {arg_ty:?}");
656655
return Err("implementation limitation");
657656
}
658657
}
@@ -1060,8 +1059,7 @@ fn make_call_args<'tcx, I: Inliner<'tcx>>(
10601059

10611060
closure_ref_arg.chain(tuple_tmp_args).collect()
10621061
} else {
1063-
// FIXME(edition_2024): switch back to a normal method call.
1064-
<_>::into_iter(args)
1062+
args.into_iter()
10651063
.map(|a| create_temp_if_necessary(inliner, a.node, callsite, caller_body, return_block))
10661064
.collect()
10671065
}

0 commit comments

Comments
 (0)