1use std::{assert_matches, iter};
2
3use rustc_abi::Primitive::Pointer;
4use rustc_abi::{Align, BackendRepr, ExternAbi, PointerKind, Scalar, Size};
5use rustc_hir::attrs::lang_items::LangItem;
6use rustc_hir::{self as hir, find_attr};
7use rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs;
8use rustc_middle::query::Providers;
9use rustc_middle::ty::layout::{
10 FnAbiError, HasTyCtxt, HasTypingEnv, LayoutCx, LayoutOf, TyAndLayout, fn_can_unwind,
11};
12use rustc_middle::ty::{self, InstanceKind, ShimKind, Ty, TyCtxt, Unnormalized};
13use rustc_span::def_id::DefId;
14use rustc_span::{DUMMY_SP, bug};
15use rustc_target::callconv::{AbiMap, ArgAbi, ArgAttribute, ArgAttributes, FnAbi, PassMode};
16use tracing::debug;
17
18pub(crate) fn provide(providers: &mut Providers) {
19 *providers = Providers {
20 fn_abi_of_fn_ptr,
21 fn_abi_of_instance_no_deduced_attrs,
22 fn_abi_of_instance_raw,
23 ..*providers
24 };
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("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/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(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("instance")
}> =
::tracing::__macro_support::FieldName::new("instance");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instance)
as &dyn ::tracing::field::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::Shim(ShimKind::ThreadLocal(..)) =
instance.def {
return tcx.mk_fn_sig_safe_rust_abi([],
tcx.thread_local_ptr_ty(instance.def_id()));
}
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.no_bound_vars().unwrap()).skip_norm_wip());
if let ty::InstanceKind::Shim(ty::ShimKind::VTable(..)) =
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.fn_sig_kind)
}
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::Shim(ShimKind::ConstructCoroutineInClosure {
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.fn_sig_kind)
}
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_safe_rust_abi([env_ty, resume_ty], ret_ty)
} else { tcx.mk_fn_sig_safe_rust_abi([env_ty], ret_ty) }
}
_ =>
bug_impl(None,
format_args!("unexpected type {0:?} in Instance::fn_sig",
ty), Location::caller()),
}
}
}
}#[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::Shim(ShimKind::ThreadLocal(..)) = instance.def {
39 return tcx.mk_fn_sig_safe_rust_abi([], tcx.thread_local_ptr_ty(instance.def_id()));
40 }
41
42 let ty = instance.ty(tcx, typing_env);
43 match *ty.kind() {
44 ty::FnDef(def_id, args) => {
45 let mut sig = tcx.instantiate_bound_regions_with_erased(
46 tcx.fn_sig(def_id).instantiate(tcx, args.no_bound_vars().unwrap()).skip_norm_wip(),
47 );
48
49 if let ty::InstanceKind::Shim(ty::ShimKind::VTable(..)) = instance.def {
51 let mut inputs_and_output = sig.inputs_and_output.to_vec();
52 inputs_and_output[0] = Ty::new_mut_ptr(tcx, inputs_and_output[0]);
53 sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
54 }
55
56 sig
57 }
58 ty::Closure(def_id, args) => {
59 let sig = tcx.instantiate_bound_regions_with_erased(args.as_closure().sig());
60 let env_ty = tcx.closure_env_ty(
61 Ty::new_closure(tcx, def_id, args),
62 args.as_closure().kind(),
63 tcx.lifetimes.re_erased,
64 );
65
66 tcx.mk_fn_sig(
67 iter::once(env_ty).chain(sig.inputs().iter().cloned()),
68 sig.output(),
69 sig.fn_sig_kind,
70 )
71 }
72 ty::CoroutineClosure(def_id, args) => {
73 let coroutine_ty = Ty::new_coroutine_closure(tcx, def_id, args);
74 let sig = args.as_coroutine_closure().coroutine_closure_sig();
75
76 let mut coroutine_kind = args.as_coroutine_closure().kind();
81
82 let env_ty = if let InstanceKind::Shim(ShimKind::ConstructCoroutineInClosure {
83 receiver_by_ref,
84 ..
85 }) = instance.def
86 {
87 coroutine_kind = ty::ClosureKind::FnOnce;
88
89 if receiver_by_ref {
92 Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, coroutine_ty)
93 } else {
94 coroutine_ty
95 }
96 } else {
97 tcx.closure_env_ty(coroutine_ty, coroutine_kind, tcx.lifetimes.re_erased)
98 };
99
100 let sig = tcx.instantiate_bound_regions_with_erased(sig);
101
102 tcx.mk_fn_sig(
103 iter::once(env_ty).chain([sig.tupled_inputs_ty]),
104 sig.to_coroutine_given_kind_and_upvars(
105 tcx,
106 args.as_coroutine_closure().parent_args(),
107 tcx.coroutine_for_closure(def_id),
108 coroutine_kind,
109 tcx.lifetimes.re_erased,
110 args.as_coroutine_closure().tupled_upvars_ty(),
111 args.as_coroutine_closure().coroutine_captures_by_ref_ty(),
112 ),
113 sig.fn_sig_kind,
114 )
115 }
116 ty::Coroutine(did, args) => {
117 let coroutine_kind = tcx.coroutine_kind(did).unwrap();
118 let sig = args.as_coroutine().sig();
119
120 let env_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty);
121
122 let pin_did = tcx.require_lang_item(LangItem::Pin, DUMMY_SP);
123 let pin_adt_ref = tcx.adt_def(pin_did);
124 let pin_args = tcx.mk_args(&[env_ty.into()]);
125 let env_ty = match coroutine_kind {
126 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _) => {
127 env_ty
130 }
131 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
132 | hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)
133 | hir::CoroutineKind::Coroutine(_) => Ty::new_adt(tcx, pin_adt_ref, pin_args),
134 };
135
136 let (resume_ty, ret_ty) = match coroutine_kind {
143 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _) => {
144 assert_eq!(sig.yield_ty, tcx.types.unit);
146
147 let poll_did = tcx.require_lang_item(LangItem::Poll, DUMMY_SP);
148 let poll_adt_ref = tcx.adt_def(poll_did);
149 let poll_args = tcx.mk_args(&[sig.return_ty.into()]);
150 let ret_ty = Ty::new_adt(tcx, poll_adt_ref, poll_args);
151
152 #[cfg(debug_assertions)]
155 {
156 if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() {
157 let expected_adt =
158 tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, DUMMY_SP));
159 assert_eq!(*resume_ty_adt, expected_adt);
160 } else {
161 panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty);
162 };
163 }
164 let context_mut_ref = Ty::new_task_context(tcx);
165
166 (Some(context_mut_ref), ret_ty)
167 }
168 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _) => {
169 let option_did = tcx.require_lang_item(LangItem::Option, DUMMY_SP);
171 let option_adt_ref = tcx.adt_def(option_did);
172 let option_args = tcx.mk_args(&[sig.yield_ty.into()]);
173 let ret_ty = Ty::new_adt(tcx, option_adt_ref, option_args);
174
175 assert_eq!(sig.return_ty, tcx.types.unit);
176 assert_eq!(sig.resume_ty, tcx.types.unit);
177
178 (None, ret_ty)
179 }
180 hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
181 assert_eq!(sig.return_ty, tcx.types.unit);
184
185 let ret_ty = sig.yield_ty;
187
188 #[cfg(debug_assertions)]
191 {
192 if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() {
193 let expected_adt =
194 tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, DUMMY_SP));
195 assert_eq!(*resume_ty_adt, expected_adt);
196 } else {
197 panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty);
198 };
199 }
200 let context_mut_ref = Ty::new_task_context(tcx);
201
202 (Some(context_mut_ref), ret_ty)
203 }
204 hir::CoroutineKind::Coroutine(_) => {
205 let state_did = tcx.require_lang_item(LangItem::CoroutineState, DUMMY_SP);
207 let state_adt_ref = tcx.adt_def(state_did);
208 let state_args = tcx.mk_args(&[sig.yield_ty.into(), sig.return_ty.into()]);
209 let ret_ty = Ty::new_adt(tcx, state_adt_ref, state_args);
210
211 (Some(sig.resume_ty), ret_ty)
212 }
213 };
214
215 if let Some(resume_ty) = resume_ty {
216 tcx.mk_fn_sig_safe_rust_abi([env_ty, resume_ty], ret_ty)
217 } else {
218 tcx.mk_fn_sig_safe_rust_abi([env_ty], ret_ty)
220 }
221 }
222 _ => bug!("unexpected type {:?} in Instance::fn_sig", ty),
223 }
224}
225
226struct FnAbiDesc<'tcx> {
228 layout_cx: LayoutCx<'tcx>,
229 sig: ty::FnSig<'tcx>,
230
231 determined_fn_def_id: Option<DefId>,
233 caller_location: Option<Ty<'tcx>>,
234 is_virtual_call: bool,
235 extra_args: &'tcx [Ty<'tcx>],
236}
237
238impl<'tcx> FnAbiDesc<'tcx> {
239 fn for_fn_ptr(
240 tcx: TyCtxt<'tcx>,
241 query: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
242 ) -> Self {
243 let ty::PseudoCanonicalInput { typing_env, value: (sig, extra_args) } = query;
244 Self {
245 layout_cx: LayoutCx::new(tcx, typing_env),
246 sig: tcx.normalize_erasing_regions(
247 typing_env,
248 Unnormalized::new_wip(tcx.instantiate_bound_regions_with_erased(sig)),
249 ),
250 determined_fn_def_id: None,
253 caller_location: None,
254 is_virtual_call: false,
255 extra_args,
256 }
257 }
258
259 fn for_instance(
260 tcx: TyCtxt<'tcx>,
261 query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
262 ) -> Self {
263 let ty::PseudoCanonicalInput { typing_env, value: (instance, extra_args) } = query;
264 let is_virtual_call = #[allow(non_exhaustive_omitted_patterns)] match instance.def {
ty::InstanceKind::Virtual(..) => true,
_ => false,
}matches!(instance.def, ty::InstanceKind::Virtual(..));
265 let is_tls_shim_call =
266 #[allow(non_exhaustive_omitted_patterns)] match instance.def {
ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(_)) => true,
_ => false,
}matches!(instance.def, ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(_)));
267 Self {
268 layout_cx: LayoutCx::new(tcx, typing_env),
269 sig: tcx.normalize_erasing_regions(
270 typing_env,
271 Unnormalized::new_wip(fn_sig_for_fn_abi(tcx, instance, typing_env)),
272 ),
273 determined_fn_def_id: (!is_virtual_call && !is_tls_shim_call)
277 .then(|| instance.def_id()),
278 caller_location: instance
279 .def
280 .requires_caller_location(tcx)
281 .then(|| tcx.caller_location_ty()),
282 is_virtual_call,
283 extra_args,
284 }
285 }
286}
287
288fn fn_abi_of_fn_ptr<'tcx>(
289 tcx: TyCtxt<'tcx>,
290 query: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
291) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
292 let desc = FnAbiDesc::for_fn_ptr(tcx, query);
293 fn_abi_new_uncached(desc)
294}
295
296fn fn_abi_of_instance_no_deduced_attrs<'tcx>(
297 tcx: TyCtxt<'tcx>,
298 query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
299) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
300 let desc = FnAbiDesc::for_instance(tcx, query);
301 fn_abi_new_uncached(desc)
302}
303
304fn fn_abi_of_instance_raw<'tcx>(
305 tcx: TyCtxt<'tcx>,
306 query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
307) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
308 tcx.fn_abi_of_instance_no_deduced_attrs(query).map(|fn_abi| {
311 let params = FnAbiDesc::for_instance(tcx, query);
312 params.determined_fn_def_id.map_or(fn_abi, |fn_def_id| {
315 fn_abi_adjust_for_deduced_attrs(¶ms.layout_cx, fn_abi, params.sig.abi(), fn_def_id)
316 })
317 })
318}
319
320fn arg_attrs_for_rust_scalar<'tcx>(
322 cx: LayoutCx<'tcx>,
323 scalar: Scalar,
324 layout: TyAndLayout<'tcx>,
325 offset: Size,
326 is_return: bool,
327 determined_fn_def_id: Option<DefId>,
328) -> ArgAttributes {
329 let mut attrs = ArgAttributes::new();
330
331 if !scalar.is_uninit_valid() {
332 attrs.set(ArgAttribute::NoUndef);
333 }
334
335 let Scalar::Initialized { value: Pointer(_), valid_range } = scalar else { return attrs };
337
338 if !valid_range.contains(0) {
340 attrs.set(ArgAttribute::NonNull);
341 }
342
343 let tcx = cx.tcx();
344
345 if let Some(pointee) = layout.pointee_info_at(&cx, offset) {
346 if pointee.align > Align::ONE {
347 attrs.pointee_align =
348 Some(pointee.align.min(cx.tcx().sess.target.max_reliable_alignment()));
349 }
350
351 attrs.pointee_size = pointee.size;
352
353 if let Some(kind) = pointee.safe {
354 let noalias_for_box = tcx.sess.opts.unstable_opts.box_noalias;
358
359 let no_alias = match kind {
366 PointerKind::SharedRef { frozen } => frozen,
367 PointerKind::MutableRef { unpin } => unpin,
368 PointerKind::Box { unpin, global } => unpin && global && noalias_for_box,
369 };
370 if no_alias && !is_return {
373 attrs.set(ArgAttribute::NoAlias);
374 }
375
376 if tcx.sess.opts.unstable_opts.llvm_writable
378 && #[allow(non_exhaustive_omitted_patterns)] match kind {
PointerKind::MutableRef { unpin: true } => true,
_ => false,
}matches!(kind, PointerKind::MutableRef { unpin: true })
379 && !is_return
380 {
381 let rustc_no_writable = match determined_fn_def_id {
382 Some(def_id) => {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &tcx) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcNoWritable) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(tcx, def_id, RustcNoWritable),
383 None => true, };
385
386 if !rustc_no_writable {
387 attrs.set(ArgAttribute::Writable);
388 }
389 }
390
391 let no_free = !is_return
395 && match kind {
396 PointerKind::SharedRef { frozen } => frozen,
400 PointerKind::MutableRef { unpin } => unpin,
404 PointerKind::Box { .. } => false,
406 };
407 if no_free {
408 attrs.set(ArgAttribute::NoFree);
409 }
410
411 if #[allow(non_exhaustive_omitted_patterns)] match kind {
PointerKind::SharedRef { frozen: true } => true,
_ => false,
}matches!(kind, PointerKind::SharedRef { frozen: true }) && !is_return {
412 attrs.set(ArgAttribute::ReadOnly);
413 attrs.set(ArgAttribute::CapturesReadOnly);
414 }
415 }
416 }
417
418 attrs
419}
420
421fn fn_abi_sanity_check<'tcx>(
423 cx: &LayoutCx<'tcx>,
424 fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
425 spec_abi: ExternAbi,
426) {
427 fn fn_arg_attrs_sanity_check(attrs: &ArgAttributes, is_ret: bool) {
428 if attrs.regular.contains(ArgAttribute::NoFree) {
429 if !!is_ret {
{
::core::panicking::panic_fmt(format_args!("NoFree not valid on return values"));
}
};assert!(!is_ret, "NoFree not valid on return values");
430 }
431 }
432
433 fn fn_arg_sanity_check<'tcx>(
434 cx: &LayoutCx<'tcx>,
435 spec_abi: ExternAbi,
436 arg: &ArgAbi<'tcx, Ty<'tcx>>,
437 is_ret: bool,
438 ) {
439 let tcx = cx.tcx();
440
441 if spec_abi.is_rustic_abi() {
442 if arg.layout.is_zst() {
443 if !arg.is_ignore() {
::core::panicking::panic("assertion failed: arg.is_ignore()")
};assert!(arg.is_ignore());
446 }
447 if let PassMode::Indirect { on_stack, .. } = arg.mode
448 && spec_abi != ExternAbi::RustTail
449 {
450 if !!on_stack {
{
::core::panicking::panic_fmt(format_args!("rustic abi {0:?} shouldn\'t use on_stack",
spec_abi));
}
};assert!(!on_stack, "rustic abi {spec_abi:?} shouldn't use on_stack");
451 }
452 } else if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
453 {
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!(
454 arg.mode,
455 PassMode::Indirect { on_stack: false, .. },
456 "the {spec_abi} ABI does not implement `#[rustc_pass_indirectly_in_non_rustic_abis]`"
457 );
458 }
459
460 match &arg.mode {
461 PassMode::Ignore => {
462 if !arg.layout.is_zst() {
::core::panicking::panic("assertion failed: arg.layout.is_zst()")
};assert!(arg.layout.is_zst());
463 }
464 PassMode::Direct(attrs) => {
465 match arg.layout.backend_repr {
469 BackendRepr::Scalar(_)
470 | BackendRepr::SimdVector { .. }
471 | BackendRepr::SimdScalableVector { .. } => {}
472 BackendRepr::ScalarPair { .. } => {
473 {
::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)
474 }
475 BackendRepr::Memory { .. } => {
476 {
::core::panicking::panic_fmt(format_args!("`PassMode::Direct` for aggregates not allowed\nProblematic type: {0:#?}",
arg.layout));
};panic!(
477 "`PassMode::Direct` for aggregates not allowed\n\
478 Problematic type: {:#?}",
479 arg.layout,
480 );
481 }
482 }
483 fn_arg_attrs_sanity_check(attrs, is_ret);
484 }
485 PassMode::Pair(attrs1, attrs2) => {
486 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!(
489 matches!(arg.layout.backend_repr, BackendRepr::ScalarPair { .. }),
490 "PassMode::Pair for type {}",
491 arg.layout.ty
492 );
493 fn_arg_attrs_sanity_check(attrs1, is_ret);
494 fn_arg_attrs_sanity_check(attrs2, is_ret);
495 }
496 PassMode::Cast { .. } => {
497 if !arg.layout.is_sized() {
::core::panicking::panic("assertion failed: arg.layout.is_sized()")
};assert!(arg.layout.is_sized());
499 }
500 PassMode::Indirect { meta_attrs: None, attrs, .. } => {
501 if !arg.layout.is_sized() {
::core::panicking::panic("assertion failed: arg.layout.is_sized()")
};assert!(arg.layout.is_sized());
506 fn_arg_attrs_sanity_check(attrs, false);
508 }
509 PassMode::Indirect { meta_attrs: Some(meta_attrs), attrs, on_stack } => {
510 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);
512 let tail = tcx.struct_tail_for_codegen(arg.layout.ty, cx.typing_env);
514 if #[allow(non_exhaustive_omitted_patterns)] match tail.kind() {
ty::Foreign(..) => true,
_ => false,
}matches!(tail.kind(), ty::Foreign(..)) {
515 {
::core::panicking::panic_fmt(format_args!("unsized arguments must not be `extern` types"));
};panic!("unsized arguments must not be `extern` types");
520 }
521 fn_arg_attrs_sanity_check(attrs, false);
523 fn_arg_attrs_sanity_check(meta_attrs, false);
524 }
525 }
526 }
527
528 for arg in fn_abi.args.iter() {
529 fn_arg_sanity_check(cx, spec_abi, arg, false);
530 }
531 fn_arg_sanity_check(cx, spec_abi, &fn_abi.ret, true);
532}
533
534{}
#[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("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(534u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("sig")
}> =
::tracing::__macro_support::FieldName::new("sig");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("extra_args")
}> =
::tracing::__macro_support::FieldName::new("extra_args");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sig)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&extra_args)
as &dyn ::tracing::field::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 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 {
bug_impl(None,
format_args!("argument to function with \"rust-call\" ABI is not a tuple"),
Location::caller());
}
} else {
if !(sig.c_variadic() || extra_args.is_empty()) {
::core::panicking::panic("assertion failed: sig.c_variadic() || extra_args.is_empty()")
};
extra_args
};
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("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(574u32),
::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_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
let _entered = span.enter();
let is_return = arg_idx.is_none();
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(layout,
|scalar, offset|
{
arg_attrs_for_rust_scalar(*cx, scalar, layout, offset,
is_return, determined_fn_def_id)
}))
};
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());
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs:615",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(615u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("fn_abi_new_uncached = {0:?}",
fn_abi) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
fn_abi_sanity_check(cx, &fn_abi, sig.abi());
Ok(tcx.arena.alloc(fn_abi))
}
}
}#[tracing::instrument(
535 level = "debug",
536 skip(cx, caller_location, determined_fn_def_id, is_virtual_call)
537)]
538fn fn_abi_new_uncached<'tcx>(
539 FnAbiDesc {
540 layout_cx: ref cx,
541 sig,
542 determined_fn_def_id,
543 caller_location,
544 is_virtual_call,
545 extra_args,
546 }: FnAbiDesc<'tcx>,
547) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
548 let tcx = cx.tcx();
549
550 let abi_map = AbiMap::from_target(&tcx.sess.target);
551 let conv = abi_map.canonize_abi(sig.abi(), sig.c_variadic()).unwrap();
552
553 let mut inputs = sig.inputs();
554 let extra_args = if sig.abi() == ExternAbi::RustCall {
555 assert!(!sig.c_variadic() && extra_args.is_empty());
556
557 if let Some(input) = sig.inputs().last()
558 && let ty::Tuple(tupled_arguments) = input.kind()
559 {
560 inputs = &sig.inputs()[0..sig.inputs().len() - 1];
561 tupled_arguments
562 } else {
563 bug!(
564 "argument to function with \"rust-call\" ABI \
565 is not a tuple"
566 );
567 }
568 } else {
569 assert!(sig.c_variadic() || extra_args.is_empty());
570 extra_args
571 };
572
573 let arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| -> Result<_, &'tcx FnAbiError<'tcx>> {
574 let span = tracing::debug_span!("arg_of");
575 let _entered = span.enter();
576 let is_return = arg_idx.is_none();
577
578 let layout = cx.layout_of(ty).map_err(|err| &*tcx.arena.alloc(FnAbiError::Layout(*err)))?;
579 let layout = if is_virtual_call && arg_idx == Some(0) {
580 make_thin_self_ptr(cx, layout)
584 } else {
585 layout
586 };
587
588 Ok(ArgAbi::new(layout, |scalar, offset| {
589 arg_attrs_for_rust_scalar(*cx, scalar, layout, offset, is_return, determined_fn_def_id)
590 }))
591 };
592
593 let mut fn_abi = FnAbi {
594 ret: arg_of(sig.output(), None)?,
595 args: inputs
596 .iter()
597 .copied()
598 .chain(extra_args.iter().copied())
599 .chain(caller_location)
600 .enumerate()
601 .map(|(i, ty)| arg_of(ty, Some(i)))
602 .collect::<Result<_, _>>()?,
603 c_variadic: sig.c_variadic(),
604 fixed_count: inputs.len() as u32,
605 conv,
606 can_unwind: fn_can_unwind(
608 tcx,
609 determined_fn_def_id,
611 sig.abi(),
612 ),
613 };
614 fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi());
615 debug!("fn_abi_new_uncached = {:?}", fn_abi);
616 fn_abi_sanity_check(cx, &fn_abi, sig.abi());
617 Ok(tcx.arena.alloc(fn_abi))
618}
619
620{}
#[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("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(620u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_abi")
}> =
::tracing::__macro_support::FieldName::new("fn_abi");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("abi")
}> =
::tracing::__macro_support::FieldName::new("abi");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_abi)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&abi)
as &dyn ::tracing::field::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;
}
{
{
match (&(abi), &(ExternAbi::LlvmIntrinsic)) {
(left_val, right_val) => {
if *left_val == *right_val {
let kind = ::core::panicking::AssertKind::Ne;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("fn_abi_of_instance should not be called on LLVM intrinsics")));
}
}
}
};
if abi.is_rustic_abi() {
fn_abi.adjust_for_rust_abi(cx);
} else { fn_abi.adjust_for_foreign_abi(cx, abi); }
}
}
}#[tracing::instrument(level = "trace", skip(cx))]
621fn fn_abi_adjust_for_abi<'tcx>(
622 cx: &LayoutCx<'tcx>,
623 fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
624 abi: ExternAbi,
625) {
626 assert_ne!(
627 abi,
628 ExternAbi::LlvmIntrinsic,
629 "fn_abi_of_instance should not be called on LLVM intrinsics"
630 );
631
632 if abi.is_rustic_abi() {
633 fn_abi.adjust_for_rust_abi(cx);
634 } else {
635 fn_abi.adjust_for_foreign_abi(cx, abi);
636 }
637}
638
639{}
#[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_deduced_attrs",
"rustc_ty_utils::abi", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(639u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_abi")
}> =
::tracing::__macro_support::FieldName::new("fn_abi");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("abi")
}> =
::tracing::__macro_support::FieldName::new("abi");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_def_id")
}> =
::tracing::__macro_support::FieldName::new("fn_def_id");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_abi)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&abi)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_def_id)
as &dyn ::tracing::field::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: &'tcx FnAbi<'tcx, Ty<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
let tcx = cx.tcx();
let deduced =
if abi.is_rustic_abi() {
tcx.deduced_param_attrs(fn_def_id)
} else { &[] };
if deduced.is_empty() {
fn_abi
} else {
let mut fn_abi = fn_abi.clone();
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);
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs:658",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(658u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("fn_abi_adjust_for_deduced_attrs = {0:?}",
fn_abi) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
fn_abi_sanity_check(cx, &fn_abi, abi);
tcx.arena.alloc(fn_abi)
}
}
}
}#[tracing::instrument(level = "trace", skip(cx))]
640fn fn_abi_adjust_for_deduced_attrs<'tcx>(
641 cx: &LayoutCx<'tcx>,
642 fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
643 abi: ExternAbi,
644 fn_def_id: DefId,
645) -> &'tcx FnAbi<'tcx, Ty<'tcx>> {
646 let tcx = cx.tcx();
647 let deduced = if abi.is_rustic_abi() { tcx.deduced_param_attrs(fn_def_id) } else { &[] };
650 if deduced.is_empty() {
651 fn_abi
652 } else {
653 let mut fn_abi = fn_abi.clone();
654 apply_deduced_attributes(cx, deduced, 0, &mut fn_abi.ret);
655 for (arg_idx, arg) in fn_abi.args.iter_mut().enumerate() {
656 apply_deduced_attributes(cx, deduced, arg_idx + 1, arg);
657 }
658 debug!("fn_abi_adjust_for_deduced_attrs = {:?}", fn_abi);
659 fn_abi_sanity_check(cx, &fn_abi, abi);
660 tcx.arena.alloc(fn_abi)
661 }
662}
663
664fn apply_deduced_attributes<'tcx>(
669 cx: &LayoutCx<'tcx>,
670 deduced: &[DeducedParamAttrs],
671 idx: usize,
672 arg: &mut ArgAbi<'tcx, Ty<'tcx>>,
673) {
674 let PassMode::Indirect { ref mut attrs, .. } = arg.mode else {
676 return;
677 };
678 let Some(deduced) = deduced.get(idx) else {
680 return;
681 };
682 if deduced.read_only(cx.tcx(), cx.typing_env, arg.layout.ty) {
683 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs:683",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(683u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("added deduced ReadOnly attribute")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("added deduced ReadOnly attribute");
684 attrs.regular.insert(ArgAttribute::ReadOnly);
685 }
686 if deduced.captures_none(cx.tcx(), cx.typing_env, arg.layout.ty) {
687 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs:687",
"rustc_ty_utils::abi", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(687u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("added deduced CapturesNone attribute")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("added deduced CapturesNone attribute");
688 attrs.regular.insert(ArgAttribute::CapturesNone);
689 }
690}
691
692{}
#[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("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ty_utils/src/abi.rs"),
::tracing_core::__macro_support::Option::Some(692u32),
::tracing_core::__macro_support::Option::Some("rustc_ty_utils::abi"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("layout")
}> =
::tracing::__macro_support::FieldName::new("layout");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&layout)
as &dyn ::tracing::field::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(..) =>
(),
_ =>
bug_impl(None,
format_args!("receiver type has unsupported layout: {0:?}",
layout), Location::caller()),
}
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))]
693fn make_thin_self_ptr<'tcx>(
694 cx: &(impl HasTyCtxt<'tcx> + HasTypingEnv<'tcx>),
695 layout: TyAndLayout<'tcx>,
696) -> TyAndLayout<'tcx> {
697 let tcx = cx.tcx();
698 let wide_pointer_ty = if layout.is_unsized() {
699 Ty::new_mut_ptr(tcx, layout.ty)
702 } else {
703 match layout.backend_repr {
704 BackendRepr::ScalarPair { .. } | BackendRepr::Scalar(..) => (),
705 _ => bug!("receiver type has unsupported layout: {:?}", layout),
706 }
707
708 let mut wide_pointer_layout = layout;
714 while !wide_pointer_layout.ty.is_raw_ptr() && !wide_pointer_layout.ty.is_ref() {
715 wide_pointer_layout = wide_pointer_layout
716 .non_1zst_field(cx)
717 .expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type")
718 .1
719 }
720
721 wide_pointer_layout.ty
722 };
723
724 let unit_ptr_ty = Ty::new_mut_ptr(tcx, tcx.types.unit);
728
729 TyAndLayout {
730 ty: wide_pointer_ty,
731
732 ..tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(unit_ptr_ty)).unwrap()
735 }
736}