Skip to content
Permalink
Browse files

rustc: take a PolyFnSig instead of an FnSig in FnAbi::of_fn_ptr.

  • Loading branch information
eddyb committed Oct 29, 2019
1 parent 2b921d5 commit 902433b5bf4f42714ed8d5b6bbf0d574d83a4f0f
@@ -2347,11 +2347,11 @@ where
+ HasTyCtxt<'tcx>
+ HasParamEnv<'tcx>,
{
fn of_fn_ptr(cx: &C, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
fn new_internal(
cx: &C,
sig: ty::FnSig<'tcx>,
sig: ty::PolyFnSig<'tcx>,
extra_args: &[Ty<'tcx>],
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>,
) -> Self;
@@ -2366,15 +2366,12 @@ where
+ HasTyCtxt<'tcx>
+ HasParamEnv<'tcx>,
{
fn of_fn_ptr(cx: &C, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
call::FnAbi::new_internal(cx, sig, extra_args, |ty, _| ArgAbi::new(cx.layout_of(ty)))
}

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

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

fn new_internal(
cx: &C,
sig: ty::FnSig<'tcx>,
sig: ty::PolyFnSig<'tcx>,
extra_args: &[Ty<'tcx>],
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>,
) -> Self {
debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args);

let sig = cx
.tcx()
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);

use rustc_target::spec::abi::Abi::*;
let conv = match cx.tcx().sess.target.target.adjust_abi(sig.abi) {
RustIntrinsic | PlatformIntrinsic | Rust | RustCall => Conv::C,
@@ -413,13 +413,13 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
return llfn;
}

let sig = tcx.mk_fn_sig(
let sig = ty::Binder::bind(tcx.mk_fn_sig(
iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
tcx.types.never,
false,
hir::Unsafety::Unsafe,
Abi::C
);
));

let fn_abi = FnAbi::of_fn_ptr(self, sig, &[]);
let llfn = self.declare_fn("rust_eh_unwind_resume", &fn_abi);
@@ -1005,13 +1005,13 @@ fn gen_fn<'ll, 'tcx>(
output: Ty<'tcx>,
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
) -> &'ll Value {
let rust_fn_sig = cx.tcx.mk_fn_sig(
let rust_fn_sig = ty::Binder::bind(cx.tcx.mk_fn_sig(
inputs.into_iter(),
output,
false,
hir::Unsafety::Unsafe,
Abi::Rust
);
));
let fn_abi = FnAbi::of_fn_ptr(cx, rust_fn_sig, &[]);
let llfn = cx.declare_fn(name, &fn_abi);
// FIXME(eddyb) find a nicer way to do this.
@@ -235,10 +235,6 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
cx.type_ptr_to(cx.layout_of(self.ty.boxed_ty()).llvm_type(cx))
}
ty::FnPtr(sig) => {
let sig = cx.tcx.normalize_erasing_late_bound_regions(
ty::ParamEnv::reveal_all(),
&sig,
);
cx.fn_ptr_backend_type(&FnAbi::of_fn_ptr(cx, sig, &[]))
}
_ => self.scalar_llvm_type_at(cx, scalar, Size::ZERO)
@@ -488,11 +488,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// available - right now `sig` is only needed for getting the `abi`
// and figuring out how many extra args were passed to a C-variadic `fn`.
let sig = callee.layout.ty.fn_sig(bx.tcx());
let sig = bx.tcx().normalize_erasing_late_bound_regions(
ty::ParamEnv::reveal_all(),
&sig,
);
let abi = sig.abi;
let abi = sig.abi();

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

let extra_args = &args[sig.inputs().skip_binder().len()..];
let extra_args = extra_args.iter().map(|op_arg| {
let op_ty = op_arg.ty(*self.mir, bx.tcx());
self.monomorphize(&op_ty)
}).collect::<Vec<_>>();

let fn_abi = match instance {
Some(instance) => FnAbi::of_instance(&bx, instance, &extra_args),
None => FnAbi::of_fn_ptr(&bx, sig, &extra_args)
};

if intrinsic == Some("transmute") {
if let Some(destination_ref) = destination.as_ref() {
let &(ref dest, target) = destination_ref;
@@ -515,23 +522,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// we can do what we like. Here, we declare that transmuting
// into an uninhabited type is impossible, so anything following
// it must be unreachable.
assert_eq!(bx.layout_of(sig.output()).abi, layout::Abi::Uninhabited);
assert_eq!(fn_abi.ret.layout.abi, layout::Abi::Uninhabited);
bx.unreachable();
}
return;
}

let extra_args = &args[sig.inputs().len()..];
let extra_args = extra_args.iter().map(|op_arg| {
let op_ty = op_arg.ty(*self.mir, bx.tcx());
self.monomorphize(&op_ty)
}).collect::<Vec<_>>();

let fn_abi = match instance {
Some(instance) => FnAbi::of_instance(&bx, instance, &extra_args),
None => FnAbi::of_fn_ptr(&bx, sig, &extra_args)
};

// For normal codegen, this Miri-specific intrinsic is just a NOP.
if intrinsic == Some("miri_start_panic") {
let target = destination.as_ref().unwrap().1;

0 comments on commit 902433b

Please sign in to comment.
You can’t perform that action at this time.