Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 268d7bc

Browse files
committed
Remove fn_sig_for_fn_abi
1 parent e564a0a commit 268d7bc

File tree

2 files changed

+4
-83
lines changed

2 files changed

+4
-83
lines changed

src/abi/mod.rs

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -18,84 +18,6 @@ use crate::prelude::*;
1818

1919
pub(crate) use self::returning::{can_return_to_ssa_var, codegen_return};
2020

21-
// FIXME remove
22-
// Copied from https://github.com/rust-lang/rust/blob/f52c72948aa1dd718cc1f168d21c91c584c0a662/src/librustc_middle/ty/layout.rs#L2301
23-
#[rustfmt::skip]
24-
pub(crate) fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> {
25-
use rustc_middle::ty::subst::Subst;
26-
27-
// FIXME(davidtwco,eddyb): A `ParamEnv` should be passed through to this function.
28-
let ty = instance.ty(tcx, ty::ParamEnv::reveal_all());
29-
match *ty.kind() {
30-
ty::FnDef(..) => {
31-
// HACK(davidtwco,eddyb): This is a workaround for polymorphization considering
32-
// parameters unused if they show up in the signature, but not in the `mir::Body`
33-
// (i.e. due to being inside a projection that got normalized, see
34-
// `src/test/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
35-
// track of a polymorphization `ParamEnv` to allow normalizing later.
36-
let mut sig = match *ty.kind() {
37-
ty::FnDef(def_id, substs) => tcx
38-
.normalize_erasing_regions(tcx.param_env(def_id), tcx.fn_sig(def_id))
39-
.subst(tcx, substs),
40-
_ => unreachable!(),
41-
};
42-
43-
if let ty::InstanceDef::VtableShim(..) = instance.def {
44-
// Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
45-
sig = sig.map_bound(|mut sig| {
46-
let mut inputs_and_output = sig.inputs_and_output.to_vec();
47-
inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]);
48-
sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output);
49-
sig
50-
});
51-
}
52-
sig
53-
}
54-
ty::Closure(def_id, substs) => {
55-
let sig = substs.as_closure().sig();
56-
57-
let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
58-
sig.map_bound(|sig| {
59-
tcx.mk_fn_sig(
60-
std::iter::once(env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
61-
sig.output(),
62-
sig.c_variadic,
63-
sig.unsafety,
64-
sig.abi,
65-
)
66-
})
67-
}
68-
ty::Generator(_, substs, _) => {
69-
let sig = substs.as_generator().poly_sig();
70-
71-
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { kind: ty::BrEnv });
72-
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
73-
74-
let pin_did = tcx.require_lang_item(rustc_hir::LangItem::Pin, None);
75-
let pin_adt_ref = tcx.adt_def(pin_did);
76-
let pin_substs = tcx.intern_substs(&[env_ty.into()]);
77-
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);
78-
79-
sig.map_bound(|sig| {
80-
let state_did = tcx.require_lang_item(rustc_hir::LangItem::GeneratorState, None);
81-
let state_adt_ref = tcx.adt_def(state_did);
82-
let state_substs =
83-
tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
84-
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
85-
86-
tcx.mk_fn_sig(
87-
[env_ty, sig.resume_ty].iter(),
88-
&ret_ty,
89-
false,
90-
rustc_hir::Unsafety::Normal,
91-
rustc_target::spec::abi::Abi::Rust,
92-
)
93-
})
94-
}
95-
_ => bug!("unexpected type {:?} in Instance::fn_sig", ty),
96-
}
97-
}
98-
9921
fn clif_sig_from_fn_abi<'tcx>(
10022
tcx: TyCtxt<'tcx>,
10123
triple: &target_lexicon::Triple,

src/pretty_clif.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ use cranelift_codegen::{
6161
write::{FuncWriter, PlainWriter},
6262
};
6363

64+
use rustc_middle::ty::layout::FnAbiExt;
6465
use rustc_session::config::OutputType;
66+
use rustc_target::abi::call::FnAbi;
6567

6668
use crate::prelude::*;
6769

@@ -78,11 +80,8 @@ impl CommentWriter {
7880
format!("symbol {}", tcx.symbol_name(instance).name),
7981
format!("instance {:?}", instance),
8082
format!(
81-
"sig {:?}",
82-
tcx.normalize_erasing_late_bound_regions(
83-
ParamEnv::reveal_all(),
84-
crate::abi::fn_sig_for_fn_abi(tcx, instance)
85-
)
83+
"abi {:?}",
84+
FnAbi::of_instance(&RevealAllLayoutCx(tcx), instance, &[])
8685
),
8786
String::new(),
8887
]

0 commit comments

Comments
 (0)