Skip to content

Commit 0bd01a7

Browse files
authored
Unrolled build for rust-lang#133874
Rollup merge of rust-lang#133874 - compiler-errors:fn-sig-binder, r=oli-obk `fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder r? oli-obk Split out of rust-lang#133122
2 parents 5a0a5e6 + 03aec5d commit 0bd01a7

File tree

2 files changed

+52
-82
lines changed

2 files changed

+52
-82
lines changed

compiler/rustc_mir_transform/src/shim.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ fn build_call_shim<'tcx>(
747747
sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
748748
}
749749

750-
// FIXME(eddyb) avoid having this snippet both here and in
751-
// `Instance::fn_sig` (introduce `InstanceKind::fn_sig`?).
750+
// FIXME: Avoid having to adjust the signature both here and in
751+
// `fn_sig_for_fn_abi`.
752752
if let ty::InstanceKind::VTableShim(..) = instance {
753753
// Modify fn(self, ...) to fn(self: *mut Self, ...)
754754
let mut inputs_and_output = sig.inputs_and_output.to_vec();

compiler/rustc_ty_utils/src/abi.rs

+50-80
Original file line numberDiff line numberDiff line change
@@ -31,93 +31,66 @@ fn fn_sig_for_fn_abi<'tcx>(
3131
tcx: TyCtxt<'tcx>,
3232
instance: ty::Instance<'tcx>,
3333
typing_env: ty::TypingEnv<'tcx>,
34-
) -> ty::PolyFnSig<'tcx> {
34+
) -> ty::FnSig<'tcx> {
3535
if let InstanceKind::ThreadLocalShim(..) = instance.def {
36-
return ty::Binder::dummy(tcx.mk_fn_sig(
36+
return tcx.mk_fn_sig(
3737
[],
3838
tcx.thread_local_ptr_ty(instance.def_id()),
3939
false,
4040
hir::Safety::Safe,
4141
rustc_abi::ExternAbi::Unadjusted,
42-
));
42+
);
4343
}
4444

4545
let ty = instance.ty(tcx, typing_env);
4646
match *ty.kind() {
47-
ty::FnDef(..) => {
47+
ty::FnDef(def_id, args) => {
4848
// HACK(davidtwco,eddyb): This is a workaround for polymorphization considering
4949
// parameters unused if they show up in the signature, but not in the `mir::Body`
5050
// (i.e. due to being inside a projection that got normalized, see
5151
// `tests/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
5252
// track of a polymorphization `ParamEnv` to allow normalizing later.
5353
//
5454
// We normalize the `fn_sig` again after instantiating at a later point.
55-
let mut sig = match *ty.kind() {
56-
ty::FnDef(def_id, args) => tcx
57-
.fn_sig(def_id)
55+
let mut sig = tcx.instantiate_bound_regions_with_erased(
56+
tcx.fn_sig(def_id)
5857
.map_bound(|fn_sig| {
5958
tcx.normalize_erasing_regions(
6059
ty::TypingEnv::non_body_analysis(tcx, def_id),
6160
fn_sig,
6261
)
6362
})
6463
.instantiate(tcx, args),
65-
_ => unreachable!(),
66-
};
64+
);
6765

6866
if let ty::InstanceKind::VTableShim(..) = instance.def {
69-
// Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
70-
sig = sig.map_bound(|mut sig| {
71-
let mut inputs_and_output = sig.inputs_and_output.to_vec();
72-
inputs_and_output[0] = Ty::new_mut_ptr(tcx, inputs_and_output[0]);
73-
sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
74-
sig
75-
});
67+
let mut inputs_and_output = sig.inputs_and_output.to_vec();
68+
inputs_and_output[0] = Ty::new_mut_ptr(tcx, inputs_and_output[0]);
69+
sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
7670
}
71+
7772
sig
7873
}
7974
ty::Closure(def_id, args) => {
80-
let sig = args.as_closure().sig();
81-
82-
let bound_vars =
83-
tcx.mk_bound_variable_kinds_from_iter(sig.bound_vars().iter().chain(iter::once(
84-
ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv),
85-
)));
86-
let br = ty::BoundRegion {
87-
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
88-
kind: ty::BoundRegionKind::ClosureEnv,
89-
};
90-
let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, br);
75+
let sig = tcx.instantiate_bound_regions_with_erased(args.as_closure().sig());
9176
let env_ty = tcx.closure_env_ty(
9277
Ty::new_closure(tcx, def_id, args),
9378
args.as_closure().kind(),
94-
env_region,
79+
tcx.lifetimes.re_erased,
9580
);
9681

97-
let sig = sig.skip_binder();
98-
ty::Binder::bind_with_vars(
99-
tcx.mk_fn_sig(
100-
iter::once(env_ty).chain(sig.inputs().iter().cloned()),
101-
sig.output(),
102-
sig.c_variadic,
103-
sig.safety,
104-
sig.abi,
105-
),
106-
bound_vars,
82+
tcx.mk_fn_sig(
83+
iter::once(env_ty).chain(sig.inputs().iter().cloned()),
84+
sig.output(),
85+
sig.c_variadic,
86+
sig.safety,
87+
sig.abi,
10788
)
10889
}
10990
ty::CoroutineClosure(def_id, args) => {
11091
let coroutine_ty = Ty::new_coroutine_closure(tcx, def_id, args);
11192
let sig = args.as_coroutine_closure().coroutine_closure_sig();
112-
let bound_vars =
113-
tcx.mk_bound_variable_kinds_from_iter(sig.bound_vars().iter().chain(iter::once(
114-
ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv),
115-
)));
116-
let br = ty::BoundRegion {
117-
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
118-
kind: ty::BoundRegionKind::ClosureEnv,
119-
};
120-
let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, br);
93+
12194
// When this `CoroutineClosure` comes from a `ConstructCoroutineInClosureShim`,
12295
// make sure we respect the `target_kind` in that shim.
12396
// FIXME(async_closures): This shouldn't be needed, and we should be populating
@@ -138,42 +111,32 @@ fn fn_sig_for_fn_abi<'tcx>(
138111
coroutine_ty
139112
}
140113
} else {
141-
tcx.closure_env_ty(coroutine_ty, coroutine_kind, env_region)
114+
tcx.closure_env_ty(coroutine_ty, coroutine_kind, tcx.lifetimes.re_erased)
142115
};
143116

144-
let sig = sig.skip_binder();
145-
ty::Binder::bind_with_vars(
146-
tcx.mk_fn_sig(
147-
iter::once(env_ty).chain([sig.tupled_inputs_ty]),
148-
sig.to_coroutine_given_kind_and_upvars(
149-
tcx,
150-
args.as_coroutine_closure().parent_args(),
151-
tcx.coroutine_for_closure(def_id),
152-
coroutine_kind,
153-
env_region,
154-
args.as_coroutine_closure().tupled_upvars_ty(),
155-
args.as_coroutine_closure().coroutine_captures_by_ref_ty(),
156-
),
157-
sig.c_variadic,
158-
sig.safety,
159-
sig.abi,
117+
let sig = tcx.instantiate_bound_regions_with_erased(sig);
118+
119+
tcx.mk_fn_sig(
120+
iter::once(env_ty).chain([sig.tupled_inputs_ty]),
121+
sig.to_coroutine_given_kind_and_upvars(
122+
tcx,
123+
args.as_coroutine_closure().parent_args(),
124+
tcx.coroutine_for_closure(def_id),
125+
coroutine_kind,
126+
tcx.lifetimes.re_erased,
127+
args.as_coroutine_closure().tupled_upvars_ty(),
128+
args.as_coroutine_closure().coroutine_captures_by_ref_ty(),
160129
),
161-
bound_vars,
130+
sig.c_variadic,
131+
sig.safety,
132+
sig.abi,
162133
)
163134
}
164135
ty::Coroutine(did, args) => {
165136
let coroutine_kind = tcx.coroutine_kind(did).unwrap();
166137
let sig = args.as_coroutine().sig();
167138

168-
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(iter::once(
169-
ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv),
170-
));
171-
let br = ty::BoundRegion {
172-
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
173-
kind: ty::BoundRegionKind::ClosureEnv,
174-
};
175-
176-
let env_ty = Ty::new_mut_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), ty);
139+
let env_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty);
177140

178141
let pin_did = tcx.require_lang_item(LangItem::Pin, None);
179142
let pin_adt_ref = tcx.adt_def(pin_did);
@@ -268,7 +231,7 @@ fn fn_sig_for_fn_abi<'tcx>(
268231
}
269232
};
270233

271-
let fn_sig = if let Some(resume_ty) = resume_ty {
234+
if let Some(resume_ty) = resume_ty {
272235
tcx.mk_fn_sig(
273236
[env_ty, resume_ty],
274237
ret_ty,
@@ -285,8 +248,7 @@ fn fn_sig_for_fn_abi<'tcx>(
285248
hir::Safety::Safe,
286249
rustc_abi::ExternAbi::Rust,
287250
)
288-
};
289-
ty::Binder::bind_with_vars(fn_sig, bound_vars)
251+
}
290252
}
291253
_ => bug!("unexpected type {:?} in Instance::fn_sig", ty),
292254
}
@@ -335,8 +297,16 @@ fn fn_abi_of_fn_ptr<'tcx>(
335297
query: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
336298
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
337299
let ty::PseudoCanonicalInput { typing_env, value: (sig, extra_args) } = query;
300+
338301
let cx = LayoutCx::new(tcx, typing_env);
339-
fn_abi_new_uncached(&cx, sig, extra_args, None, None, false)
302+
fn_abi_new_uncached(
303+
&cx,
304+
tcx.instantiate_bound_regions_with_erased(sig),
305+
extra_args,
306+
None,
307+
None,
308+
false,
309+
)
340310
}
341311

342312
fn fn_abi_of_instance<'tcx>(
@@ -567,15 +537,15 @@ fn fn_abi_sanity_check<'tcx>(
567537
#[tracing::instrument(level = "debug", skip(cx, caller_location, fn_def_id, force_thin_self_ptr))]
568538
fn fn_abi_new_uncached<'tcx>(
569539
cx: &LayoutCx<'tcx>,
570-
sig: ty::PolyFnSig<'tcx>,
540+
sig: ty::FnSig<'tcx>,
571541
extra_args: &[Ty<'tcx>],
572542
caller_location: Option<Ty<'tcx>>,
573543
fn_def_id: Option<DefId>,
574544
// FIXME(eddyb) replace this with something typed, like an `enum`.
575545
force_thin_self_ptr: bool,
576546
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
577547
let tcx = cx.tcx();
578-
let sig = tcx.normalize_erasing_late_bound_regions(cx.typing_env, sig);
548+
let sig = tcx.normalize_erasing_regions(cx.typing_env, sig);
579549

580550
let conv = conv_from_spec_abi(cx.tcx(), sig.abi, sig.c_variadic);
581551

0 commit comments

Comments
 (0)