1use std::iter;
2
3use rustc_abi::Primitive::Pointer;
4use rustc_abi::{BackendRepr, ExternAbi, PointerKind, Scalar, Size};
5use rustc_data_structures::assert_matches;
6use rustc_hir as hir;
7use rustc_hir::lang_items::LangItem;
8use rustc_middle::bug;
9use rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs;
10use rustc_middle::query::Providers;
11use rustc_middle::ty::layout::{
12 FnAbiError, HasTyCtxt, HasTypingEnv, LayoutCx, LayoutOf, TyAndLayout, fn_can_unwind,
13};
14use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt};
15use rustc_session::config::OptLevel;
16use rustc_span::DUMMY_SP;
17use rustc_span::def_id::DefId;
18use rustc_target::callconv::{
19 AbiMap, ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, FnAbi, PassMode,
20};
21use tracing::debug;
22
23pub(crate) fn provide(providers: &mut Providers) {
24 *providers = Providers { fn_abi_of_fn_ptr, fn_abi_of_instance, ..*providers };
25}
26
27#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("fn_sig_for_fn_abi",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(32u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&["instance"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instance)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::FnSig<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
if let InstanceKind::ThreadLocalShim(..) = instance.def {
return tcx.mk_fn_sig([],
tcx.thread_local_ptr_ty(instance.def_id()), false,
hir::Safety::Safe, rustc_abi::ExternAbi::Rust);
}
let ty = instance.ty(tcx, typing_env);
match *ty.kind() {
ty::FnDef(def_id, args) => {
let mut sig =
tcx.instantiate_bound_regions_with_erased(tcx.fn_sig(def_id).instantiate(tcx,
args));
if let ty::InstanceKind::VTableShim(..) = instance.def {
let mut inputs_and_output = sig.inputs_and_output.to_vec();
inputs_and_output[0] =
Ty::new_mut_ptr(tcx, inputs_and_output[0]);
sig.inputs_and_output =
tcx.mk_type_list(&inputs_and_output);
}
sig
}
ty::Closure(def_id, args) => {
let sig =
tcx.instantiate_bound_regions_with_erased(args.as_closure().sig());
let env_ty =
tcx.closure_env_ty(Ty::new_closure(tcx, def_id, args),
args.as_closure().kind(), tcx.lifetimes.re_erased);
tcx.mk_fn_sig(iter::once(env_ty).chain(sig.inputs().iter().cloned()),
sig.output(), sig.c_variadic, sig.safety, sig.abi)
}
ty::CoroutineClosure(def_id, args) => {
let coroutine_ty =
Ty::new_coroutine_closure(tcx, def_id, args);
let sig =
args.as_coroutine_closure().coroutine_closure_sig();
let mut coroutine_kind = args.as_coroutine_closure().kind();
let env_ty =
if let InstanceKind::ConstructCoroutineInClosureShim {
receiver_by_ref, .. } = instance.def {
coroutine_kind = ty::ClosureKind::FnOnce;
if receiver_by_ref {
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, coroutine_ty)
} else { coroutine_ty }
} else {
tcx.closure_env_ty(coroutine_ty, coroutine_kind,
tcx.lifetimes.re_erased)
};
let sig = tcx.instantiate_bound_regions_with_erased(sig);
tcx.mk_fn_sig(iter::once(env_ty).chain([sig.tupled_inputs_ty]),
sig.to_coroutine_given_kind_and_upvars(tcx,
args.as_coroutine_closure().parent_args(),
tcx.coroutine_for_closure(def_id), coroutine_kind,
tcx.lifetimes.re_erased,
args.as_coroutine_closure().tupled_upvars_ty(),
args.as_coroutine_closure().coroutine_captures_by_ref_ty()),
sig.c_variadic, sig.safety, sig.abi)
}
ty::Coroutine(did, args) => {
let coroutine_kind = tcx.coroutine_kind(did).unwrap();
let sig = args.as_coroutine().sig();
let env_ty =
Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty);
let pin_did =
tcx.require_lang_item(LangItem::Pin, DUMMY_SP);
let pin_adt_ref = tcx.adt_def(pin_did);
let pin_args = tcx.mk_args(&[env_ty.into()]);
let env_ty =
match coroutine_kind {
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen,
_) => {
env_ty
}
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async,
_) |
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen,
_) | hir::CoroutineKind::Coroutine(_) =>
Ty::new_adt(tcx, pin_adt_ref, pin_args),
};
let (resume_ty, ret_ty) =
match coroutine_kind {
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async,
_) => {
match (&sig.yield_ty, &tcx.types.unit) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
let poll_did =
tcx.require_lang_item(LangItem::Poll, DUMMY_SP);
let poll_adt_ref = tcx.adt_def(poll_did);
let poll_args = tcx.mk_args(&[sig.return_ty.into()]);
let ret_ty = Ty::new_adt(tcx, poll_adt_ref, poll_args);
{
if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() {
let expected_adt =
tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy,
DUMMY_SP));
match (&*resume_ty_adt, &expected_adt) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
} else {
{
::core::panicking::panic_fmt(format_args!("expected `ResumeTy`, found `{0:?}`",
sig.resume_ty));
};
};
}
let context_mut_ref = Ty::new_task_context(tcx);
(Some(context_mut_ref), ret_ty)
}
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen,
_) => {
let option_did =
tcx.require_lang_item(LangItem::Option, DUMMY_SP);
let option_adt_ref = tcx.adt_def(option_did);
let option_args = tcx.mk_args(&[sig.yield_ty.into()]);
let ret_ty = Ty::new_adt(tcx, option_adt_ref, option_args);
match (&sig.return_ty, &tcx.types.unit) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
match (&sig.resume_ty, &tcx.types.unit) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
(None, ret_ty)
}
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen,
_) => {
match (&sig.return_ty, &tcx.types.unit) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
let ret_ty = sig.yield_ty;
{
if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() {
let expected_adt =
tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy,
DUMMY_SP));
match (&*resume_ty_adt, &expected_adt) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
} else {
{
::core::panicking::panic_fmt(format_args!("expected `ResumeTy`, found `{0:?}`",
sig.resume_ty));
};
};
}
let context_mut_ref = Ty::new_task_context(tcx);
(Some(context_mut_ref), ret_ty)
}
hir::CoroutineKind::Coroutine(_) => {
let state_did =
tcx.require_lang_item(LangItem::CoroutineState, DUMMY_SP);
let state_adt_ref = tcx.adt_def(state_did);
let state_args =
tcx.mk_args(&[sig.yield_ty.into(), sig.return_ty.into()]);
let ret_ty = Ty::new_adt(tcx, state_adt_ref, state_args);
(Some(sig.resume_ty), ret_ty)
}
};
if let Some(resume_ty) = resume_ty {
tcx.mk_fn_sig([env_ty, resume_ty], ret_ty, false,
hir::Safety::Safe, rustc_abi::ExternAbi::Rust)
} else {
tcx.mk_fn_sig([env_ty], ret_ty, false, hir::Safety::Safe,
rustc_abi::ExternAbi::Rust)
}
}
_ =>
::rustc_middle::util::bug::bug_fmt(format_args!("unexpected type {0:?} in Instance::fn_sig",
ty)),
}
}
}
}#[tracing::instrument(level = "debug", skip(tcx, typing_env))]
33fn fn_sig_for_fn_abi<'tcx>(
34 tcx: TyCtxt<'tcx>,
35 instance: ty::Instance<'tcx>,
36 typing_env: ty::TypingEnv<'tcx>,
37) -> ty::FnSig<'tcx> {
38 if let InstanceKind::ThreadLocalShim(..) = instance.def {
39 return tcx.mk_fn_sig(
40 [],
41 tcx.thread_local_ptr_ty(instance.def_id()),
42 false,
43 hir::Safety::Safe,
44 rustc_abi::ExternAbi::Rust,
45 );
46 }
47
48 let ty = instance.ty(tcx, typing_env);
49 match *ty.kind() {
50 ty::FnDef(def_id, args) => {
51 let mut sig = tcx
52 .instantiate_bound_regions_with_erased(tcx.fn_sig(def_id).instantiate(tcx, args));
53
54 if let ty::InstanceKind::VTableShim(..) = instance.def {
56 let mut inputs_and_output = sig.inputs_and_output.to_vec();
57 inputs_and_output[0] = Ty::new_mut_ptr(tcx, inputs_and_output[0]);
58 sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
59 }
60
61 sig
62 }
63 ty::Closure(def_id, args) => {
64 let sig = tcx.instantiate_bound_regions_with_erased(args.as_closure().sig());
65 let env_ty = tcx.closure_env_ty(
66 Ty::new_closure(tcx, def_id, args),
67 args.as_closure().kind(),
68 tcx.lifetimes.re_erased,
69 );
70
71 tcx.mk_fn_sig(
72 iter::once(env_ty).chain(sig.inputs().iter().cloned()),
73 sig.output(),
74 sig.c_variadic,
75 sig.safety,
76 sig.abi,
77 )
78 }
79 ty::CoroutineClosure(def_id, args) => {
80 let coroutine_ty = Ty::new_coroutine_closure(tcx, def_id, args);
81 let sig = args.as_coroutine_closure().coroutine_closure_sig();
82
83 let mut coroutine_kind = args.as_coroutine_closure().kind();
88
89 let env_ty =
90 if let InstanceKind::ConstructCoroutineInClosureShim { receiver_by_ref, .. } =
91 instance.def
92 {
93 coroutine_kind = ty::ClosureKind::FnOnce;
94
95 if receiver_by_ref {
98 Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, coroutine_ty)
99 } else {
100 coroutine_ty
101 }
102 } else {
103 tcx.closure_env_ty(coroutine_ty, coroutine_kind, tcx.lifetimes.re_erased)
104 };
105
106 let sig = tcx.instantiate_bound_regions_with_erased(sig);
107
108 tcx.mk_fn_sig(
109 iter::once(env_ty).chain([sig.tupled_inputs_ty]),
110 sig.to_coroutine_given_kind_and_upvars(
111 tcx,
112 args.as_coroutine_closure().parent_args(),
113 tcx.coroutine_for_closure(def_id),
114 coroutine_kind,
115 tcx.lifetimes.re_erased,
116 args.as_coroutine_closure().tupled_upvars_ty(),
117 args.as_coroutine_closure().coroutine_captures_by_ref_ty(),
118 ),
119 sig.c_variadic,
120 sig.safety,
121 sig.abi,
122 )
123 }
124 ty::Coroutine(did, args) => {
125 let coroutine_kind = tcx.coroutine_kind(did).unwrap();
126 let sig = args.as_coroutine().sig();
127
128 let env_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty);
129
130 let pin_did = tcx.require_lang_item(LangItem::Pin, DUMMY_SP);
131 let pin_adt_ref = tcx.adt_def(pin_did);
132 let pin_args = tcx.mk_args(&[env_ty.into()]);
133 let env_ty = match coroutine_kind {
134 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _) => {
135 env_ty
138 }
139 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
140 | hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)
141 | hir::CoroutineKind::Coroutine(_) => Ty::new_adt(tcx, pin_adt_ref, pin_args),
142 };
143
144 let (resume_ty, ret_ty) = match coroutine_kind {
151 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _) => {
152 assert_eq!(sig.yield_ty, tcx.types.unit);
154
155 let poll_did = tcx.require_lang_item(LangItem::Poll, DUMMY_SP);
156 let poll_adt_ref = tcx.adt_def(poll_did);
157 let poll_args = tcx.mk_args(&[sig.return_ty.into()]);
158 let ret_ty = Ty::new_adt(tcx, poll_adt_ref, poll_args);
159
160 #[cfg(debug_assertions)]
163 {
164 if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() {
165 let expected_adt =
166 tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, DUMMY_SP));
167 assert_eq!(*resume_ty_adt, expected_adt);
168 } else {
169 panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty);
170 };
171 }
172 let context_mut_ref = Ty::new_task_context(tcx);
173
174 (Some(context_mut_ref), ret_ty)
175 }
176 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _) => {
177 let option_did = tcx.require_lang_item(LangItem::Option, DUMMY_SP);
179 let option_adt_ref = tcx.adt_def(option_did);
180 let option_args = tcx.mk_args(&[sig.yield_ty.into()]);
181 let ret_ty = Ty::new_adt(tcx, option_adt_ref, option_args);
182
183 assert_eq!(sig.return_ty, tcx.types.unit);
184 assert_eq!(sig.resume_ty, tcx.types.unit);
185
186 (None, ret_ty)
187 }
188 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
189 assert_eq!(sig.return_ty, tcx.types.unit);
192
193 let ret_ty = sig.yield_ty;
195
196 #[cfg(debug_assertions)]
199 {
200 if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() {
201 let expected_adt =
202 tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, DUMMY_SP));
203 assert_eq!(*resume_ty_adt, expected_adt);
204 } else {
205 panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty);
206 };
207 }
208 let context_mut_ref = Ty::new_task_context(tcx);
209
210 (Some(context_mut_ref), ret_ty)
211 }
212 hir::CoroutineKind::Coroutine(_) => {
213 let state_did = tcx.require_lang_item(LangItem::CoroutineState, DUMMY_SP);
215 let state_adt_ref = tcx.adt_def(state_did);
216 let state_args = tcx.mk_args(&[sig.yield_ty.into(), sig.return_ty.into()]);
217 let ret_ty = Ty::new_adt(tcx, state_adt_ref, state_args);
218
219 (Some(sig.resume_ty), ret_ty)
220 }
221 };
222
223 if let Some(resume_ty) = resume_ty {
224 tcx.mk_fn_sig(
225 [env_ty, resume_ty],
226 ret_ty,
227 false,
228 hir::Safety::Safe,
229 rustc_abi::ExternAbi::Rust,
230 )
231 } else {
232 tcx.mk_fn_sig(
234 [env_ty],
235 ret_ty,
236 false,
237 hir::Safety::Safe,
238 rustc_abi::ExternAbi::Rust,
239 )
240 }
241 }
242 _ => bug!("unexpected type {:?} in Instance::fn_sig", ty),
243 }
244}
245
246fn fn_abi_of_fn_ptr<'tcx>(
247 tcx: TyCtxt<'tcx>,
248 query: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
249) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
250 let ty::PseudoCanonicalInput { typing_env, value: (sig, extra_args) } = query;
251 fn_abi_new_uncached(
252 &LayoutCx::new(tcx, typing_env),
253 tcx.instantiate_bound_regions_with_erased(sig),
254 extra_args,
255 None,
256 )
257}
258
259fn fn_abi_of_instance<'tcx>(
260 tcx: TyCtxt<'tcx>,
261 query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
262) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
263 let ty::PseudoCanonicalInput { typing_env, value: (instance, extra_args) } = query;
264 fn_abi_new_uncached(
265 &LayoutCx::new(tcx, typing_env),
266 fn_sig_for_fn_abi(tcx, instance, typing_env),
267 extra_args,
268 Some(instance),
269 )
270}
271
272fn arg_attrs_for_rust_scalar<'tcx>(
274 cx: LayoutCx<'tcx>,
275 scalar: Scalar,
276 layout: TyAndLayout<'tcx>,
277 offset: Size,
278 is_return: bool,
279 drop_target_pointee: Option<Ty<'tcx>>,
280) -> ArgAttributes {
281 let mut attrs = ArgAttributes::new();
282
283 if scalar.is_bool() {
285 attrs.ext(ArgExtension::Zext);
286 attrs.set(ArgAttribute::NoUndef);
287 return attrs;
288 }
289
290 if !scalar.is_uninit_valid() {
291 attrs.set(ArgAttribute::NoUndef);
292 }
293
294 let Scalar::Initialized { value: Pointer(_), valid_range } = scalar else { return attrs };
296
297 if !valid_range.contains(0) || drop_target_pointee.is_some() {
300 attrs.set(ArgAttribute::NonNull);
301 }
302
303 let tcx = cx.tcx();
304
305 if let Some(pointee) = layout.pointee_info_at(&cx, offset) {
306 let kind = if let Some(kind) = pointee.safe {
307 Some(kind)
308 } else if let Some(pointee) = drop_target_pointee {
309 match (&pointee, &layout.ty.builtin_deref(true).unwrap()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(pointee, layout.ty.builtin_deref(true).unwrap());
310 match (&offset, &Size::ZERO) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(offset, Size::ZERO);
311 let mutref = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, pointee);
313 let layout = cx.layout_of(mutref).unwrap();
314 layout.pointee_info_at(&cx, offset).and_then(|pi| pi.safe)
315 } else {
316 None
317 };
318 if let Some(kind) = kind {
319 attrs.pointee_align =
320 Some(pointee.align.min(cx.tcx().sess.target.max_reliable_alignment()));
321
322 attrs.pointee_size = match kind {
323 _ if is_return => Size::ZERO,
328 PointerKind::Box { .. }
335 | PointerKind::SharedRef { frozen: false }
336 | PointerKind::MutableRef { unpin: false } => Size::ZERO,
337 PointerKind::SharedRef { frozen: true }
338 | PointerKind::MutableRef { unpin: true } => pointee.size,
339 };
340
341 let noalias_for_box = tcx.sess.opts.unstable_opts.box_noalias;
345
346 let noalias_mut_ref = tcx.sess.opts.unstable_opts.mutable_noalias;
350
351 let no_alias = match kind {
358 PointerKind::SharedRef { frozen } => frozen,
359 PointerKind::MutableRef { unpin } => unpin && noalias_mut_ref,
360 PointerKind::Box { unpin, global } => unpin && global && noalias_for_box,
361 };
362 if no_alias && !is_return {
365 attrs.set(ArgAttribute::NoAlias);
366 }
367
368 if #[allow(non_exhaustive_omitted_patterns)] match kind {
PointerKind::SharedRef { frozen: true } => true,
_ => false,
}matches!(kind, PointerKind::SharedRef { frozen: true }) && !is_return {
369 attrs.set(ArgAttribute::ReadOnly);
370 attrs.set(ArgAttribute::CapturesReadOnly);
371 }
372 }
373 }
374
375 attrs
376}
377
378fn fn_abi_sanity_check<'tcx>(
380 cx: &LayoutCx<'tcx>,
381 fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
382 spec_abi: ExternAbi,
383) {
384 fn fn_arg_sanity_check<'tcx>(
385 cx: &LayoutCx<'tcx>,
386 fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
387 spec_abi: ExternAbi,
388 arg: &ArgAbi<'tcx, Ty<'tcx>>,
389 ) {
390 let tcx = cx.tcx();
391
392 if spec_abi.is_rustic_abi() {
393 if arg.layout.is_zst() {
394 if !arg.is_ignore() {
::core::panicking::panic("assertion failed: arg.is_ignore()")
};assert!(arg.is_ignore());
397 }
398 if let PassMode::Indirect { on_stack, .. } = arg.mode {
399 if !!on_stack {
{
::core::panicking::panic_fmt(format_args!("rust abi shouldn\'t use on_stack"));
}
};assert!(!on_stack, "rust abi shouldn't use on_stack");
400 }
401 } else if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
402 match arg.mode {
PassMode::Indirect { on_stack: false, .. } => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"PassMode::Indirect { on_stack: false, .. }",
::core::option::Option::Some(format_args!("the {0} ABI does not implement `#[rustc_pass_indirectly_in_non_rustic_abis]`",
spec_abi)));
}
};assert_matches!(
403 arg.mode,
404 PassMode::Indirect { on_stack: false, .. },
405 "the {spec_abi} ABI does not implement `#[rustc_pass_indirectly_in_non_rustic_abis]`"
406 );
407 }
408
409 match &arg.mode {
410 PassMode::Ignore => {
411 if !arg.layout.is_zst() {
::core::panicking::panic("assertion failed: arg.layout.is_zst()")
};assert!(arg.layout.is_zst());
412 }
413 PassMode::Direct(_) => {
414 match arg.layout.backend_repr {
419 BackendRepr::Scalar(_)
420 | BackendRepr::SimdVector { .. }
421 | BackendRepr::ScalableVector { .. } => {}
422 BackendRepr::ScalarPair(..) => {
423 {
::core::panicking::panic_fmt(format_args!("`PassMode::Direct` used for ScalarPair type {0}",
arg.layout.ty));
}panic!("`PassMode::Direct` used for ScalarPair type {}", arg.layout.ty)
424 }
425 BackendRepr::Memory { sized } => {
426 if !sized {
{
::core::panicking::panic_fmt(format_args!("`PassMode::Direct` for unsized type in ABI: {0:#?}",
fn_abi));
}
};assert!(sized, "`PassMode::Direct` for unsized type in ABI: {:#?}", fn_abi);
429
430 if !#[allow(non_exhaustive_omitted_patterns)] match spec_abi {
ExternAbi::Unadjusted => true,
_ => false,
} {
{
::core::panicking::panic_fmt(format_args!("`PassMode::Direct` for aggregates only allowed for \"unadjusted\"\nProblematic type: {0:#?}",
arg.layout));
}
};assert!(
436 matches!(spec_abi, ExternAbi::Unadjusted),
437 "`PassMode::Direct` for aggregates only allowed for \"unadjusted\"\n\
438 Problematic type: {:#?}",
439 arg.layout,
440 );
441 }
442 }
443 }
444 PassMode::Pair(_, _) => {
445 if !#[allow(non_exhaustive_omitted_patterns)] match arg.layout.backend_repr {
BackendRepr::ScalarPair(..) => true,
_ => false,
} {
{
::core::panicking::panic_fmt(format_args!("PassMode::Pair for type {0}",
arg.layout.ty));
}
};assert!(
448 matches!(arg.layout.backend_repr, BackendRepr::ScalarPair(..)),
449 "PassMode::Pair for type {}",
450 arg.layout.ty
451 );
452 }
453 PassMode::Cast { .. } => {
454 if !arg.layout.is_sized() {
::core::panicking::panic("assertion failed: arg.layout.is_sized()")
};assert!(arg.layout.is_sized());
456 }
457 PassMode::Indirect { meta_attrs: None, .. } => {
458 if !arg.layout.is_sized() {
::core::panicking::panic("assertion failed: arg.layout.is_sized()")
};assert!(arg.layout.is_sized());
463 }
464 PassMode::Indirect { meta_attrs: Some(_), on_stack, .. } => {
465 if !(arg.layout.is_unsized() && !on_stack) {
::core::panicking::panic("assertion failed: arg.layout.is_unsized() && !on_stack")
};assert!(arg.layout.is_unsized() && !on_stack);
467 let tail = tcx.struct_tail_for_codegen(arg.layout.ty, cx.typing_env);
469 if #[allow(non_exhaustive_omitted_patterns)] match tail.kind() {
ty::Foreign(..) => true,
_ => false,
}matches!(tail.kind(), ty::Foreign(..)) {
470 {
::core::panicking::panic_fmt(format_args!("unsized arguments must not be `extern` types"));
};panic!("unsized arguments must not be `extern` types");
475 }
476 }
477 }
478 }
479
480 for arg in fn_abi.args.iter() {
481 fn_arg_sanity_check(cx, fn_abi, spec_abi, arg);
482 }
483 fn_arg_sanity_check(cx, fn_abi, spec_abi, &fn_abi.ret);
484}
485
486#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("fn_abi_new_uncached",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(486u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&["sig", "extra_args"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sig)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&extra_args)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<&'tcx FnAbi<'tcx, Ty<'tcx>>,
&'tcx FnAbiError<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = cx.tcx();
let (caller_location, determined_fn_def_id, is_virtual_call) =
if let Some(instance) = instance {
let is_virtual_call =
#[allow(non_exhaustive_omitted_patterns)] match instance.def
{
ty::InstanceKind::Virtual(..) => true,
_ => false,
};
let is_tls_shim_call =
#[allow(non_exhaustive_omitted_patterns)] match instance.def
{
ty::InstanceKind::ThreadLocalShim(_) => true,
_ => false,
};
(instance.def.requires_caller_location(tcx).then(||
tcx.caller_location_ty()),
if is_virtual_call || is_tls_shim_call {
None
} else { Some(instance.def_id()) }, is_virtual_call)
} else { (None, None, false) };
let sig = tcx.normalize_erasing_regions(cx.typing_env, sig);
let abi_map = AbiMap::from_target(&tcx.sess.target);
let conv = abi_map.canonize_abi(sig.abi, sig.c_variadic).unwrap();
let mut inputs = sig.inputs();
let extra_args =
if sig.abi == ExternAbi::RustCall {
if !(!sig.c_variadic && extra_args.is_empty()) {
::core::panicking::panic("assertion failed: !sig.c_variadic && extra_args.is_empty()")
};
if let Some(input) = sig.inputs().last() &&
let ty::Tuple(tupled_arguments) = input.kind() {
inputs = &sig.inputs()[0..sig.inputs().len() - 1];
tupled_arguments
} else {
::rustc_middle::util::bug::bug_fmt(format_args!("argument to function with \"rust-call\" ABI is not a tuple"));
}
} else {
if !(sig.c_variadic || extra_args.is_empty()) {
::core::panicking::panic("assertion failed: sig.c_variadic || extra_args.is_empty()")
};
extra_args
};
let is_drop_in_place =
determined_fn_def_id.is_some_and(|def_id|
{
tcx.is_lang_item(def_id, LangItem::DropInPlace) ||
tcx.is_lang_item(def_id, LangItem::AsyncDropInPlace)
});
let arg_of =
|ty: Ty<'tcx>, arg_idx: Option<usize>|
-> Result<_, &'tcx FnAbiError<'tcx>>
{
let span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("arg_of",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(537u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
let _entered = span.enter();
let is_return = arg_idx.is_none();
let is_drop_target = is_drop_in_place && arg_idx == Some(0);
let drop_target_pointee =
is_drop_target.then(||
match ty.kind() {
ty::RawPtr(ty, _) => *ty,
_ =>
::rustc_middle::util::bug::bug_fmt(format_args!("argument to drop_in_place is not a raw ptr: {0:?}",
ty)),
});
let layout =
cx.layout_of(ty).map_err(|err|
&*tcx.arena.alloc(FnAbiError::Layout(*err)))?;
let layout =
if is_virtual_call && arg_idx == Some(0) {
make_thin_self_ptr(cx, layout)
} else { layout };
Ok(ArgAbi::new(cx, layout,
|scalar, offset|
{
arg_attrs_for_rust_scalar(*cx, scalar, layout, offset,
is_return, drop_target_pointee)
}))
};
let mut fn_abi =
FnAbi {
ret: arg_of(sig.output(), None)?,
args: inputs.iter().copied().chain(extra_args.iter().copied()).chain(caller_location).enumerate().map(|(i,
ty)| arg_of(ty, Some(i))).collect::<Result<_, _>>()?,
c_variadic: sig.c_variadic,
fixed_count: inputs.len() as u32,
conv,
can_unwind: fn_can_unwind(tcx, determined_fn_def_id,
sig.abi),
};
fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi,
determined_fn_def_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ty_utils/src/abi.rs:592",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(592u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("fn_abi_new_uncached = {0:?}",
fn_abi) as &dyn Value))])
});
} else { ; }
};
fn_abi_sanity_check(cx, &fn_abi, sig.abi);
Ok(tcx.arena.alloc(fn_abi))
}
}
}#[tracing::instrument(level = "debug", skip(cx, instance))]
487fn fn_abi_new_uncached<'tcx>(
488 cx: &LayoutCx<'tcx>,
489 sig: ty::FnSig<'tcx>,
490 extra_args: &[Ty<'tcx>],
491 instance: Option<ty::Instance<'tcx>>,
492) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
493 let tcx = cx.tcx();
494 let (caller_location, determined_fn_def_id, is_virtual_call) = if let Some(instance) = instance
495 {
496 let is_virtual_call = matches!(instance.def, ty::InstanceKind::Virtual(..));
497 let is_tls_shim_call = matches!(instance.def, ty::InstanceKind::ThreadLocalShim(_));
498 (
499 instance.def.requires_caller_location(tcx).then(|| tcx.caller_location_ty()),
500 if is_virtual_call || is_tls_shim_call { None } else { Some(instance.def_id()) },
501 is_virtual_call,
502 )
503 } else {
504 (None, None, false)
505 };
506 let sig = tcx.normalize_erasing_regions(cx.typing_env, sig);
507
508 let abi_map = AbiMap::from_target(&tcx.sess.target);
509 let conv = abi_map.canonize_abi(sig.abi, sig.c_variadic).unwrap();
510
511 let mut inputs = sig.inputs();
512 let extra_args = if sig.abi == ExternAbi::RustCall {
513 assert!(!sig.c_variadic && extra_args.is_empty());
514
515 if let Some(input) = sig.inputs().last()
516 && let ty::Tuple(tupled_arguments) = input.kind()
517 {
518 inputs = &sig.inputs()[0..sig.inputs().len() - 1];
519 tupled_arguments
520 } else {
521 bug!(
522 "argument to function with \"rust-call\" ABI \
523 is not a tuple"
524 );
525 }
526 } else {
527 assert!(sig.c_variadic || extra_args.is_empty());
528 extra_args
529 };
530
531 let is_drop_in_place = determined_fn_def_id.is_some_and(|def_id| {
532 tcx.is_lang_item(def_id, LangItem::DropInPlace)
533 || tcx.is_lang_item(def_id, LangItem::AsyncDropInPlace)
534 });
535
536 let arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| -> Result<_, &'tcx FnAbiError<'tcx>> {
537 let span = tracing::debug_span!("arg_of");
538 let _entered = span.enter();
539 let is_return = arg_idx.is_none();
540 let is_drop_target = is_drop_in_place && arg_idx == Some(0);
541 let drop_target_pointee = is_drop_target.then(|| match ty.kind() {
542 ty::RawPtr(ty, _) => *ty,
543 _ => bug!("argument to drop_in_place is not a raw ptr: {:?}", ty),
544 });
545
546 let layout = cx.layout_of(ty).map_err(|err| &*tcx.arena.alloc(FnAbiError::Layout(*err)))?;
547 let layout = if is_virtual_call && arg_idx == Some(0) {
548 make_thin_self_ptr(cx, layout)
552 } else {
553 layout
554 };
555
556 Ok(ArgAbi::new(cx, layout, |scalar, offset| {
557 arg_attrs_for_rust_scalar(*cx, scalar, layout, offset, is_return, drop_target_pointee)
558 }))
559 };
560
561 let mut fn_abi = FnAbi {
562 ret: arg_of(sig.output(), None)?,
563 args: inputs
564 .iter()
565 .copied()
566 .chain(extra_args.iter().copied())
567 .chain(caller_location)
568 .enumerate()
569 .map(|(i, ty)| arg_of(ty, Some(i)))
570 .collect::<Result<_, _>>()?,
571 c_variadic: sig.c_variadic,
572 fixed_count: inputs.len() as u32,
573 conv,
574 can_unwind: fn_can_unwind(
576 tcx,
577 determined_fn_def_id,
579 sig.abi,
580 ),
581 };
582 fn_abi_adjust_for_abi(
583 cx,
584 &mut fn_abi,
585 sig.abi,
586 determined_fn_def_id,
591 );
592 debug!("fn_abi_new_uncached = {:?}", fn_abi);
593 fn_abi_sanity_check(cx, &fn_abi, sig.abi);
594 Ok(tcx.arena.alloc(fn_abi))
595}
596
597#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("fn_abi_adjust_for_abi",
"rustc_ty_utils::abi", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(597u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&["fn_abi", "abi",
"fn_def_id"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_abi)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&abi)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_def_id)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if abi == ExternAbi::Unadjusted {
fn unadjust<'tcx>(arg: &mut ArgAbi<'tcx, Ty<'tcx>>) {
if #[allow(non_exhaustive_omitted_patterns)] match arg.layout.backend_repr
{
BackendRepr::Memory { .. } => true,
_ => false,
} {
if !arg.layout.backend_repr.is_sized() {
{
::core::panicking::panic_fmt(format_args!("\'unadjusted\' ABI does not support unsized arguments"));
}
};
}
arg.make_direct_deprecated();
}
unadjust(&mut fn_abi.ret);
for arg in fn_abi.args.iter_mut() { unadjust(arg); }
return;
}
let tcx = cx.tcx();
if abi.is_rustic_abi() {
fn_abi.adjust_for_rust_abi(cx);
let deduced =
if tcx.sess.opts.optimize != OptLevel::No &&
tcx.sess.opts.incremental.is_none() {
fn_def_id.map(|fn_def_id|
tcx.deduced_param_attrs(fn_def_id)).unwrap_or_default()
} else { &[] };
if !deduced.is_empty() {
apply_deduced_attributes(cx, deduced, 0, &mut fn_abi.ret);
for (arg_idx, arg) in fn_abi.args.iter_mut().enumerate() {
apply_deduced_attributes(cx, deduced, arg_idx + 1, arg);
}
}
} else { fn_abi.adjust_for_foreign_abi(cx, abi); }
}
}
}#[tracing::instrument(level = "trace", skip(cx))]
598fn fn_abi_adjust_for_abi<'tcx>(
599 cx: &LayoutCx<'tcx>,
600 fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
601 abi: ExternAbi,
602 fn_def_id: Option<DefId>,
603) {
604 if abi == ExternAbi::Unadjusted {
605 fn unadjust<'tcx>(arg: &mut ArgAbi<'tcx, Ty<'tcx>>) {
608 if matches!(arg.layout.backend_repr, BackendRepr::Memory { .. }) {
611 assert!(
612 arg.layout.backend_repr.is_sized(),
613 "'unadjusted' ABI does not support unsized arguments"
614 );
615 }
616 arg.make_direct_deprecated();
617 }
618
619 unadjust(&mut fn_abi.ret);
620 for arg in fn_abi.args.iter_mut() {
621 unadjust(arg);
622 }
623 return;
624 }
625
626 let tcx = cx.tcx();
627
628 if abi.is_rustic_abi() {
629 fn_abi.adjust_for_rust_abi(cx);
630 let deduced =
634 if tcx.sess.opts.optimize != OptLevel::No && tcx.sess.opts.incremental.is_none() {
635 fn_def_id.map(|fn_def_id| tcx.deduced_param_attrs(fn_def_id)).unwrap_or_default()
636 } else {
637 &[]
638 };
639 if !deduced.is_empty() {
640 apply_deduced_attributes(cx, deduced, 0, &mut fn_abi.ret);
641 for (arg_idx, arg) in fn_abi.args.iter_mut().enumerate() {
642 apply_deduced_attributes(cx, deduced, arg_idx + 1, arg);
643 }
644 }
645 } else {
646 fn_abi.adjust_for_foreign_abi(cx, abi);
647 }
648}
649
650fn apply_deduced_attributes<'tcx>(
655 cx: &LayoutCx<'tcx>,
656 deduced: &[DeducedParamAttrs],
657 idx: usize,
658 arg: &mut ArgAbi<'tcx, Ty<'tcx>>,
659) {
660 let PassMode::Indirect { ref mut attrs, .. } = arg.mode else {
662 return;
663 };
664 let Some(deduced) = deduced.get(idx) else {
666 return;
667 };
668 if deduced.read_only(cx.tcx(), cx.typing_env, arg.layout.ty) {
669 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ty_utils/src/abi.rs:669",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(669u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("added deduced ReadOnly attribute")
as &dyn Value))])
});
} else { ; }
};debug!("added deduced ReadOnly attribute");
670 attrs.regular.insert(ArgAttribute::ReadOnly);
671 }
672 if deduced.captures_none(cx.tcx(), cx.typing_env, arg.layout.ty) {
673 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ty_utils/src/abi.rs:673",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(673u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("added deduced CapturesNone attribute")
as &dyn Value))])
});
} else { ; }
};debug!("added deduced CapturesNone attribute");
674 attrs.regular.insert(ArgAttribute::CapturesNone);
675 }
676}
677
678#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("make_thin_self_ptr",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(678u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&["layout"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&layout)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: TyAndLayout<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = cx.tcx();
let wide_pointer_ty =
if layout.is_unsized() {
Ty::new_mut_ptr(tcx, layout.ty)
} else {
match layout.backend_repr {
BackendRepr::ScalarPair(..) | BackendRepr::Scalar(..) => (),
_ =>
::rustc_middle::util::bug::bug_fmt(format_args!("receiver type has unsupported layout: {0:?}",
layout)),
}
let mut wide_pointer_layout = layout;
while !wide_pointer_layout.ty.is_raw_ptr() &&
!wide_pointer_layout.ty.is_ref() {
wide_pointer_layout =
wide_pointer_layout.non_1zst_field(cx).expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type").1
}
wide_pointer_layout.ty
};
let unit_ptr_ty = Ty::new_mut_ptr(tcx, tcx.types.unit);
TyAndLayout {
ty: wide_pointer_ty,
..tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(unit_ptr_ty)).unwrap()
}
}
}
}#[tracing::instrument(level = "debug", skip(cx))]
679fn make_thin_self_ptr<'tcx>(
680 cx: &(impl HasTyCtxt<'tcx> + HasTypingEnv<'tcx>),
681 layout: TyAndLayout<'tcx>,
682) -> TyAndLayout<'tcx> {
683 let tcx = cx.tcx();
684 let wide_pointer_ty = if layout.is_unsized() {
685 Ty::new_mut_ptr(tcx, layout.ty)
688 } else {
689 match layout.backend_repr {
690 BackendRepr::ScalarPair(..) | BackendRepr::Scalar(..) => (),
691 _ => bug!("receiver type has unsupported layout: {:?}", layout),
692 }
693
694 let mut wide_pointer_layout = layout;
700 while !wide_pointer_layout.ty.is_raw_ptr() && !wide_pointer_layout.ty.is_ref() {
701 wide_pointer_layout = wide_pointer_layout
702 .non_1zst_field(cx)
703 .expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type")
704 .1
705 }
706
707 wide_pointer_layout.ty
708 };
709
710 let unit_ptr_ty = Ty::new_mut_ptr(tcx, tcx.types.unit);
714
715 TyAndLayout {
716 ty: wide_pointer_ty,
717
718 ..tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(unit_ptr_ty)).unwrap()
721 }
722}