about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2021-01-27 10:36:40 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2021-01-27 10:36:40 +0100
commit268d7bc459d436d28171e37050edec287f950bfe (patch)
tree707b7c761548e730a5c84f38b4343382fce2b577
parente564a0ad319c8fabddc3e62616be0dbfd761ecec (diff)
downloadrust-268d7bc459d436d28171e37050edec287f950bfe.tar.gz
rust-268d7bc459d436d28171e37050edec287f950bfe.zip
Remove fn_sig_for_fn_abi
-rw-r--r--src/abi/mod.rs78
-rw-r--r--src/pretty_clif.rs9
2 files changed, 4 insertions, 83 deletions
diff --git a/src/abi/mod.rs b/src/abi/mod.rs
index a27d5b8ab02..92d6b389753 100644
--- a/src/abi/mod.rs
+++ b/src/abi/mod.rs
@@ -18,84 +18,6 @@ use crate::prelude::*;
 
 pub(crate) use self::returning::{can_return_to_ssa_var, codegen_return};
 
-// FIXME remove
-// Copied from https://github.com/rust-lang/rust/blob/f52c72948aa1dd718cc1f168d21c91c584c0a662/src/librustc_middle/ty/layout.rs#L2301
-#[rustfmt::skip]
-pub(crate) fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> {
-    use rustc_middle::ty::subst::Subst;
-
-    // FIXME(davidtwco,eddyb): A `ParamEnv` should be passed through to this function.
-    let ty = instance.ty(tcx, ty::ParamEnv::reveal_all());
-    match *ty.kind() {
-        ty::FnDef(..) => {
-            // HACK(davidtwco,eddyb): This is a workaround for polymorphization considering
-            // parameters unused if they show up in the signature, but not in the `mir::Body`
-            // (i.e. due to being inside a projection that got normalized, see
-            // `src/test/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
-            // track of a polymorphization `ParamEnv` to allow normalizing later.
-            let mut sig = match *ty.kind() {
-                ty::FnDef(def_id, substs) => tcx
-                    .normalize_erasing_regions(tcx.param_env(def_id), tcx.fn_sig(def_id))
-                    .subst(tcx, substs),
-                _ => unreachable!(),
-            };
-
-            if let ty::InstanceDef::VtableShim(..) = instance.def {
-                // Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
-                sig = sig.map_bound(|mut sig| {
-                    let mut inputs_and_output = sig.inputs_and_output.to_vec();
-                    inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]);
-                    sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output);
-                    sig
-                });
-            }
-            sig
-        }
-        ty::Closure(def_id, substs) => {
-            let sig = substs.as_closure().sig();
-
-            let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
-            sig.map_bound(|sig| {
-                tcx.mk_fn_sig(
-                    std::iter::once(env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
-                    sig.output(),
-                    sig.c_variadic,
-                    sig.unsafety,
-                    sig.abi,
-                )
-            })
-        }
-        ty::Generator(_, substs, _) => {
-            let sig = substs.as_generator().poly_sig();
-
-            let env_region = ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { kind: ty::BrEnv });
-            let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
-
-            let pin_did = tcx.require_lang_item(rustc_hir::LangItem::Pin, None);
-            let pin_adt_ref = tcx.adt_def(pin_did);
-            let pin_substs = tcx.intern_substs(&[env_ty.into()]);
-            let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);
-
-            sig.map_bound(|sig| {
-                let state_did = tcx.require_lang_item(rustc_hir::LangItem::GeneratorState, None);
-                let state_adt_ref = tcx.adt_def(state_did);
-                let state_substs =
-                    tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
-                let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
-
-                tcx.mk_fn_sig(
-                    [env_ty, sig.resume_ty].iter(),
-                    &ret_ty,
-                    false,
-                    rustc_hir::Unsafety::Normal,
-                    rustc_target::spec::abi::Abi::Rust,
-                )
-            })
-        }
-        _ => bug!("unexpected type {:?} in Instance::fn_sig", ty),
-    }
-}
-
 fn clif_sig_from_fn_abi<'tcx>(
     tcx: TyCtxt<'tcx>,
     triple: &target_lexicon::Triple,
diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs
index 22c94fec82f..f4a15ab12d5 100644
--- a/src/pretty_clif.rs
+++ b/src/pretty_clif.rs
@@ -61,7 +61,9 @@ use cranelift_codegen::{
     write::{FuncWriter, PlainWriter},
 };
 
+use rustc_middle::ty::layout::FnAbiExt;
 use rustc_session::config::OutputType;
+use rustc_target::abi::call::FnAbi;
 
 use crate::prelude::*;
 
@@ -78,11 +80,8 @@ impl CommentWriter {
                 format!("symbol {}", tcx.symbol_name(instance).name),
                 format!("instance {:?}", instance),
                 format!(
-                    "sig {:?}",
-                    tcx.normalize_erasing_late_bound_regions(
-                        ParamEnv::reveal_all(),
-                        crate::abi::fn_sig_for_fn_abi(tcx, instance)
-                    )
+                    "abi {:?}",
+                    FnAbi::of_instance(&RevealAllLayoutCx(tcx), instance, &[])
                 ),
                 String::new(),
             ]