Skip to content

Commit 0e70c4d

Browse files
committed
rustc: take a PolyFnSig instead of an FnSig in FnAbi::of_fn_ptr.
1 parent 49bed20 commit 0e70c4d

File tree

5 files changed

+25
-32
lines changed

5 files changed

+25
-32
lines changed

src/librustc/ty/layout.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,11 +2347,11 @@ where
23472347
+ HasTyCtxt<'tcx>
23482348
+ HasParamEnv<'tcx>,
23492349
{
2350-
fn of_fn_ptr(cx: &C, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
2350+
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
23512351
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
23522352
fn new_internal(
23532353
cx: &C,
2354-
sig: ty::FnSig<'tcx>,
2354+
sig: ty::PolyFnSig<'tcx>,
23552355
extra_args: &[Ty<'tcx>],
23562356
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>,
23572357
) -> Self;
@@ -2366,15 +2366,12 @@ where
23662366
+ HasTyCtxt<'tcx>
23672367
+ HasParamEnv<'tcx>,
23682368
{
2369-
fn of_fn_ptr(cx: &C, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
2369+
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
23702370
call::FnAbi::new_internal(cx, sig, extra_args, |ty, _| ArgAbi::new(cx.layout_of(ty)))
23712371
}
23722372

23732373
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
23742374
let sig = instance.fn_sig(cx.tcx());
2375-
let sig = cx
2376-
.tcx()
2377-
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
23782375

23792376
call::FnAbi::new_internal(cx, sig, extra_args, |ty, arg_idx| {
23802377
let mut layout = cx.layout_of(ty);
@@ -2432,12 +2429,16 @@ where
24322429

24332430
fn new_internal(
24342431
cx: &C,
2435-
sig: ty::FnSig<'tcx>,
2432+
sig: ty::PolyFnSig<'tcx>,
24362433
extra_args: &[Ty<'tcx>],
24372434
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>,
24382435
) -> Self {
24392436
debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args);
24402437

2438+
let sig = cx
2439+
.tcx()
2440+
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
2441+
24412442
use rustc_target::spec::abi::Abi::*;
24422443
let conv = match cx.tcx().sess.target.target.adjust_abi(sig.abi) {
24432444
RustIntrinsic | PlatformIntrinsic | Rust | RustCall => Conv::C,

src/librustc_codegen_llvm/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,13 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
413413
return llfn;
414414
}
415415

416-
let sig = tcx.mk_fn_sig(
416+
let sig = ty::Binder::bind(tcx.mk_fn_sig(
417417
iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
418418
tcx.types.never,
419419
false,
420420
hir::Unsafety::Unsafe,
421421
Abi::C
422-
);
422+
));
423423

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

src/librustc_codegen_llvm/intrinsic.rs

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

src/librustc_codegen_llvm/type_of.rs

Lines changed: 0 additions & 4 deletions
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

Lines changed: 13 additions & 17 deletions
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 getting 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
// This should never be reachable at runtime:
536532
// We should only emit a call to this intrinsic in #[cfg(miri)] mode,
537533
// which means that we will never actually use the generate object files

0 commit comments

Comments
 (0)