Skip to content

Commit c1837ef

Browse files
committed
Querify fn_abi_of_{fn_ptr,instance}.
1 parent e9b6830 commit c1837ef

File tree

19 files changed

+152
-93
lines changed

19 files changed

+152
-93
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ pub(crate) fn get_function_sig<'tcx>(
5353
inst: Instance<'tcx>,
5454
) -> Signature {
5555
assert!(!inst.substs.needs_infer());
56-
clif_sig_from_fn_abi(tcx, triple, &RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, &[]))
56+
clif_sig_from_fn_abi(
57+
tcx,
58+
triple,
59+
&RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()),
60+
)
5761
}
5862

5963
/// Instance must be monomorphized
@@ -350,14 +354,13 @@ pub(crate) fn codegen_terminator_call<'tcx>(
350354
};
351355

352356
let extra_args = &args[fn_sig.inputs().len()..];
353-
let extra_args = extra_args
354-
.iter()
355-
.map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx)))
356-
.collect::<Vec<_>>();
357+
let extra_args = fx
358+
.tcx
359+
.mk_type_list(extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx))));
357360
let fn_abi = if let Some(instance) = instance {
358-
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, &extra_args)
361+
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args)
359362
} else {
360-
RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_ty.fn_sig(fx.tcx), &extra_args)
363+
RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_ty.fn_sig(fx.tcx), extra_args)
361364
};
362365

363366
let is_cold = instance
@@ -525,7 +528,8 @@ pub(crate) fn codegen_drop<'tcx>(
525528
def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0),
526529
substs: drop_instance.substs,
527530
};
528-
let fn_abi = RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, &[]);
531+
let fn_abi =
532+
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty());
529533

530534
let sig = clif_sig_from_fn_abi(fx.tcx, fx.triple(), &fn_abi);
531535
let sig = fx.bcx.import_signature(sig);
@@ -534,7 +538,8 @@ pub(crate) fn codegen_drop<'tcx>(
534538
_ => {
535539
assert!(!matches!(drop_instance.def, InstanceDef::Virtual(_, _)));
536540

537-
let fn_abi = RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, &[]);
541+
let fn_abi =
542+
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, ty::List::empty());
538543

539544
let arg_value = drop_place.place_ref(
540545
fx,

compiler/rustc_codegen_cranelift/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) fn codegen_fn<'tcx>(
6161
instance,
6262
symbol_name,
6363
mir,
64-
fn_abi: Some(RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, &[])),
64+
fn_abi: Some(RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())),
6565

6666
bcx,
6767
block_map,

compiler/rustc_codegen_cranelift/src/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
276276
&self,
277277
err: FnAbiError<'tcx>,
278278
span: Span,
279-
fn_abi_request: FnAbiRequest<'_, 'tcx>,
279+
fn_abi_request: FnAbiRequest<'tcx>,
280280
) -> ! {
281281
RevealAllLayoutCx(self.tcx).handle_fn_abi_err(err, span, fn_abi_request)
282282
}
@@ -402,7 +402,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
402402
&self,
403403
err: FnAbiError<'tcx>,
404404
span: Span,
405-
fn_abi_request: FnAbiRequest<'_, 'tcx>,
405+
fn_abi_request: FnAbiRequest<'tcx>,
406406
) -> ! {
407407
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
408408
self.0.sess.span_fatal(span, &err.to_string())

compiler/rustc_codegen_cranelift/src/pretty_clif.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ impl CommentWriter {
8080
vec![
8181
format!("symbol {}", tcx.symbol_name(instance).name),
8282
format!("instance {:?}", instance),
83-
format!("abi {:?}", RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, &[])),
83+
format!(
84+
"abi {:?}",
85+
RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())
86+
),
8487
String::new(),
8588
]
8689
} else {

compiler/rustc_codegen_llvm/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl FnAbiOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
107107
&self,
108108
err: FnAbiError<'tcx>,
109109
span: Span,
110-
fn_abi_request: FnAbiRequest<'_, 'tcx>,
110+
fn_abi_request: FnAbiRequest<'tcx>,
111111
) -> ! {
112112
self.cx.handle_fn_abi_err(err, span, fn_abi_request)
113113
}

compiler/rustc_codegen_llvm/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
4242
sym
4343
);
4444

45-
let fn_abi = cx.fn_abi_of_instance(instance, &[]);
45+
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
4646

4747
let llfn = if let Some(llfn) = cx.get_declared_value(&sym) {
4848
// Create a fn pointer with the new signature.

compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ impl FnAbiOfHelpers<'tcx> for CodegenCx<'ll, 'tcx> {
867867
&self,
868868
err: FnAbiError<'tcx>,
869869
span: Span,
870-
fn_abi_request: FnAbiRequest<'_, 'tcx>,
870+
fn_abi_request: FnAbiRequest<'tcx>,
871871
) -> ! {
872872
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
873873
self.sess().span_fatal(span, &err.to_string())

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn declare_unused_fn(cx: &CodegenCx<'ll, 'tcx>, def_id: &DefId) -> Instance<'tcx
208208
hir::Unsafety::Unsafe,
209209
Abi::Rust,
210210
)),
211-
&[],
211+
ty::List::empty(),
212212
),
213213
);
214214

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn make_mir_scope(
9393
ty::ParamEnv::reveal_all(),
9494
callee,
9595
);
96-
let callee_fn_abi = cx.fn_abi_of_instance(callee, &[]);
96+
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
9797
cx.dbg_scope_fn(callee, &callee_fn_abi, None)
9898
}
9999
None => unsafe {

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ fn gen_fn<'ll, 'tcx>(
737737
rust_fn_sig: ty::PolyFnSig<'tcx>,
738738
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
739739
) -> (&'ll Type, &'ll Value) {
740-
let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, &[]);
740+
let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty());
741741
let llty = fn_abi.llvm_type(cx);
742742
let llfn = cx.declare_fn(name, &fn_abi);
743743
cx.set_frame_pointer_type(llfn);

compiler/rustc_codegen_llvm/src/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> {
5252
) {
5353
assert!(!instance.substs.needs_infer());
5454

55-
let fn_abi = self.fn_abi_of_instance(instance, &[]);
55+
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
5656
let lldecl = self.declare_fn(symbol_name, &fn_abi);
5757
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
5858
let attrs = self.tcx.codegen_fn_attrs(instance.def_id());

compiler/rustc_codegen_llvm/src/type_of.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
230230
ty::Adt(def, _) if def.is_box() => {
231231
cx.type_ptr_to(cx.layout_of(self.ty.boxed_ty()).llvm_type(cx))
232232
}
233-
ty::FnPtr(sig) => cx.fn_ptr_backend_type(&cx.fn_abi_of_fn_ptr(sig, &[])),
233+
ty::FnPtr(sig) => {
234+
cx.fn_ptr_backend_type(&cx.fn_abi_of_fn_ptr(sig, ty::List::empty()))
235+
}
234236
_ => self.scalar_llvm_type_at(cx, scalar, Size::ZERO),
235237
};
236238
cx.scalar_lltypes.borrow_mut().insert(self.ty, llty);

compiler/rustc_codegen_ssa/src/mir/block.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
337337
def: ty::InstanceDef::Virtual(drop_fn.def_id(), 0),
338338
substs: drop_fn.substs,
339339
};
340-
let fn_abi = bx.fn_abi_of_instance(virtual_drop, &[]);
340+
let fn_abi = bx.fn_abi_of_instance(virtual_drop, ty::List::empty());
341341
let vtable = args[1];
342342
args = &args[..1];
343343
(
@@ -346,7 +346,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
346346
fn_abi,
347347
)
348348
}
349-
_ => (bx.get_fn_addr(drop_fn), bx.fn_abi_of_instance(drop_fn, &[])),
349+
_ => (bx.get_fn_addr(drop_fn), bx.fn_abi_of_instance(drop_fn, ty::List::empty())),
350350
};
351351
helper.do_call(
352352
self,
@@ -433,7 +433,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
433433
// Obtain the panic entry point.
434434
let def_id = common::langcall(bx.tcx(), Some(span), "", lang_item);
435435
let instance = ty::Instance::mono(bx.tcx(), def_id);
436-
let fn_abi = bx.fn_abi_of_instance(instance, &[]);
436+
let fn_abi = bx.fn_abi_of_instance(instance, ty::List::empty());
437437
let llfn = bx.get_fn_addr(instance);
438438

439439
// Codegen the actual panic invoke/call.
@@ -494,7 +494,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
494494
let def_id =
495495
common::langcall(bx.tcx(), Some(source_info.span), "", LangItem::Panic);
496496
let instance = ty::Instance::mono(bx.tcx(), def_id);
497-
let fn_abi = bx.fn_abi_of_instance(instance, &[]);
497+
let fn_abi = bx.fn_abi_of_instance(instance, ty::List::empty());
498498
let llfn = bx.get_fn_addr(instance);
499499

500500
// Codegen the actual panic invoke/call.
@@ -570,17 +570,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
570570
};
571571

572572
let extra_args = &args[sig.inputs().skip_binder().len()..];
573-
let extra_args = extra_args
574-
.iter()
575-
.map(|op_arg| {
576-
let op_ty = op_arg.ty(self.mir, bx.tcx());
577-
self.monomorphize(op_ty)
578-
})
579-
.collect::<Vec<_>>();
573+
let extra_args = bx.tcx().mk_type_list(extra_args.iter().map(|op_arg| {
574+
let op_ty = op_arg.ty(self.mir, bx.tcx());
575+
self.monomorphize(op_ty)
576+
}));
580577

581578
let fn_abi = match instance {
582-
Some(instance) => bx.fn_abi_of_instance(instance, &extra_args),
583-
None => bx.fn_abi_of_fn_ptr(sig, &extra_args),
579+
Some(instance) => bx.fn_abi_of_instance(instance, extra_args),
580+
None => bx.fn_abi_of_fn_ptr(sig, extra_args),
584581
};
585582

586583
if intrinsic == Some(sym::transmute) {

compiler/rustc_codegen_ssa/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
139139

140140
let mir = cx.tcx().instance_mir(instance.def);
141141

142-
let fn_abi = cx.fn_abi_of_instance(instance, &[]);
142+
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
143143
debug!("fn_abi: {:?}", fn_abi);
144144

145145
let debug_context = cx.create_function_debug_context(instance, &fn_abi, llfn, &mir);

compiler/rustc_middle/src/query/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,27 @@ rustc_queries! {
11281128
desc { "computing layout of `{}`", key.value }
11291129
}
11301130

1131+
/// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1132+
///
1133+
/// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1134+
/// instead, where the instance is an `InstanceDef::Virtual`.
1135+
query fn_abi_of_fn_ptr(
1136+
key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1137+
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1138+
desc { "computing call ABI of `{}` function pointers", key.value.0 }
1139+
}
1140+
1141+
/// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1142+
/// direct calls to an `fn`.
1143+
///
1144+
/// NB: that includes virtual calls, which are represented by "direct calls"
1145+
/// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1146+
query fn_abi_of_instance(
1147+
key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1148+
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1149+
desc { "computing call ABI of `{}`", key.value.0 }
1150+
}
1151+
11311152
query dylib_dependency_formats(_: CrateNum)
11321153
-> &'tcx [(CrateNum, LinkagePreference)] {
11331154
desc { "dylib dependency formats of crate" }

0 commit comments

Comments
 (0)