Skip to content

Commit 43c07dd

Browse files
committed
rustc: take a PolyFnSig instead of an FnSig in FnAbi::of_fn_ptr.
1 parent 0b65020 commit 43c07dd

File tree

5 files changed

+25
-32
lines changed

5 files changed

+25
-32
lines changed

src/librustc/ty/layout.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -2495,11 +2495,11 @@ where
24952495
+ HasTyCtxt<'tcx>
24962496
+ HasParamEnv<'tcx>,
24972497
{
2498-
fn of_fn_ptr(cx: &C, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
2498+
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
24992499
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
25002500
fn new_internal(
25012501
cx: &C,
2502-
sig: ty::FnSig<'tcx>,
2502+
sig: ty::PolyFnSig<'tcx>,
25032503
extra_args: &[Ty<'tcx>],
25042504
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>,
25052505
) -> Self;
@@ -2514,15 +2514,12 @@ where
25142514
+ HasTyCtxt<'tcx>
25152515
+ HasParamEnv<'tcx>,
25162516
{
2517-
fn of_fn_ptr(cx: &C, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
2517+
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
25182518
call::FnAbi::new_internal(cx, sig, extra_args, |ty, _| ArgAbi::new(cx.layout_of(ty)))
25192519
}
25202520

25212521
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
25222522
let sig = instance.fn_sig(cx.tcx());
2523-
let sig = cx
2524-
.tcx()
2525-
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
25262523

25272524
call::FnAbi::new_internal(cx, sig, extra_args, |ty, arg_idx| {
25282525
let mut layout = cx.layout_of(ty);
@@ -2580,12 +2577,16 @@ where
25802577

25812578
fn new_internal(
25822579
cx: &C,
2583-
sig: ty::FnSig<'tcx>,
2580+
sig: ty::PolyFnSig<'tcx>,
25842581
extra_args: &[Ty<'tcx>],
25852582
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>,
25862583
) -> Self {
25872584
debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args);
25882585

2586+
let sig = cx
2587+
.tcx()
2588+
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
2589+
25892590
use rustc_target::spec::abi::Abi::*;
25902591
let conv = match cx.tcx().sess.target.target.adjust_abi(sig.abi) {
25912592
RustIntrinsic | PlatformIntrinsic | Rust | RustCall => Conv::C,

src/librustc_codegen_llvm/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,13 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
409409
return llfn;
410410
}
411411

412-
let sig = tcx.mk_fn_sig(
412+
let sig = ty::Binder::bind(tcx.mk_fn_sig(
413413
iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
414414
tcx.types.never,
415415
false,
416416
hir::Unsafety::Unsafe,
417417
Abi::C
418-
);
418+
));
419419

420420
let fn_abi = FnAbi::of_fn_ptr(self, sig, &[]);
421421
let llfn = self.declare_fn("rust_eh_unwind_resume", &fn_abi);

src/librustc_codegen_llvm/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1001,13 +1001,13 @@ fn gen_fn<'ll, 'tcx>(
10011001
output: Ty<'tcx>,
10021002
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
10031003
) -> &'ll Value {
1004-
let rust_fn_sig = cx.tcx.mk_fn_sig(
1004+
let rust_fn_sig = ty::Binder::bind(cx.tcx.mk_fn_sig(
10051005
inputs.into_iter(),
10061006
output,
10071007
false,
10081008
hir::Unsafety::Unsafe,
10091009
Abi::Rust
1010-
);
1010+
));
10111011
let fn_abi = FnAbi::of_fn_ptr(cx, rust_fn_sig, &[]);
10121012
let llfn = cx.declare_fn(name, &fn_abi);
10131013
// FIXME(eddyb) find a nicer way to do this.

src/librustc_codegen_llvm/type_of.rs

-4
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,6 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
235235
cx.type_ptr_to(cx.layout_of(self.ty.boxed_ty()).llvm_type(cx))
236236
}
237237
ty::FnPtr(sig) => {
238-
let sig = cx.tcx.normalize_erasing_late_bound_regions(
239-
ty::ParamEnv::reveal_all(),
240-
&sig,
241-
);
242238
cx.fn_ptr_backend_type(&FnAbi::of_fn_ptr(cx, sig, &[]))
243239
}
244240
_ => self.scalar_llvm_type_at(cx, scalar, Size::ZERO)

src/librustc_codegen_ssa/mir/block.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
488488
// available - right now `sig` is only needed for getthing the `abi`
489489
// and figuring out how many extra args were passed to a C-variadic `fn`.
490490
let sig = callee.layout.ty.fn_sig(bx.tcx());
491-
let sig = bx.tcx().normalize_erasing_late_bound_regions(
492-
ty::ParamEnv::reveal_all(),
493-
&sig,
494-
);
495-
let abi = sig.abi;
491+
let abi = sig.abi();
496492

497493
// Handle intrinsics old codegen wants Expr's for, ourselves.
498494
let intrinsic = match def {
@@ -502,6 +498,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
502498
};
503499
let intrinsic = intrinsic.as_ref().map(|s| &s[..]);
504500

501+
let extra_args = &args[sig.inputs().skip_binder().len()..];
502+
let extra_args = extra_args.iter().map(|op_arg| {
503+
let op_ty = op_arg.ty(self.mir, bx.tcx());
504+
self.monomorphize(&op_ty)
505+
}).collect::<Vec<_>>();
506+
507+
let fn_abi = match instance {
508+
Some(instance) => FnAbi::of_instance(&bx, instance, &extra_args),
509+
None => FnAbi::of_fn_ptr(&bx, sig, &extra_args)
510+
};
511+
505512
if intrinsic == Some("transmute") {
506513
if let Some(destination_ref) = destination.as_ref() {
507514
let &(ref dest, target) = destination_ref;
@@ -515,23 +522,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
515522
// we can do what we like. Here, we declare that transmuting
516523
// into an uninhabited type is impossible, so anything following
517524
// it must be unreachable.
518-
assert_eq!(bx.layout_of(sig.output()).abi, layout::Abi::Uninhabited);
525+
assert_eq!(fn_abi.ret.layout.abi, layout::Abi::Uninhabited);
519526
bx.unreachable();
520527
}
521528
return;
522529
}
523530

524-
let extra_args = &args[sig.inputs().len()..];
525-
let extra_args = extra_args.iter().map(|op_arg| {
526-
let op_ty = op_arg.ty(self.mir, bx.tcx());
527-
self.monomorphize(&op_ty)
528-
}).collect::<Vec<_>>();
529-
530-
let fn_abi = match instance {
531-
Some(instance) => FnAbi::of_instance(&bx, instance, &extra_args),
532-
None => FnAbi::of_fn_ptr(&bx, sig, &extra_args)
533-
};
534-
535531
// Emit a panic or a no-op for `panic_if_uninhabited`.
536532
if intrinsic == Some("panic_if_uninhabited") {
537533
let ty = instance.unwrap().substs.type_at(0);

0 commit comments

Comments
 (0)