Skip to content

Commit 14f4700

Browse files
committed
Add InterpCx::fn_abi_of_instance/_fn_ptr with tracing, shadowing FnAbiOf
1 parent a9fb610 commit 14f4700

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::borrow::Cow;
66
use either::{Left, Right};
77
use rustc_abi::{self as abi, ExternAbi, FieldIdx, Integer, VariantIdx};
88
use rustc_hir::def_id::DefId;
9-
use rustc_middle::ty::layout::{FnAbiOf, IntegerExt, TyAndLayout};
9+
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
1010
use rustc_middle::ty::{self, AdtDef, Instance, Ty, VariantDef};
1111
use rustc_middle::{bug, mir, span_bug};
1212
use rustc_span::sym;

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_hir::def_id::DefId;
77
use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo};
88
use rustc_middle::query::TyCtxtAt;
99
use rustc_middle::ty::layout::{
10-
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf, LayoutOfHelpers,
11-
TyAndLayout,
10+
self, FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf,
11+
LayoutOfHelpers, TyAndLayout,
1212
};
1313
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv, Variance};
1414
use rustc_middle::{mir, span_bug};
@@ -92,20 +92,6 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
9292
}
9393
}
9494

95-
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
96-
/// This inherent method takes priority over the trait method with the same name in LayoutOf,
97-
/// and allows wrapping the actual [LayoutOf::layout_of] with a tracing span.
98-
/// See [LayoutOf::layout_of] for the original documentation.
99-
#[inline(always)]
100-
pub fn layout_of(
101-
&self,
102-
ty: Ty<'tcx>,
103-
) -> <InterpCx<'tcx, M> as LayoutOfHelpers<'tcx>>::LayoutOfResult {
104-
let _span = enter_trace_span!(M, "InterpCx::layout_of", "ty = {:?}", ty.kind());
105-
LayoutOf::layout_of(self, ty)
106-
}
107-
}
108-
10995
impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
11096
type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpErrorKind<'tcx>>;
11197

@@ -121,6 +107,43 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
121107
}
122108
}
123109

110+
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
111+
/// This inherent method takes priority over the trait method with the same name in LayoutOf,
112+
/// and allows wrapping the actual [LayoutOf::layout_of] with a tracing span.
113+
/// See [LayoutOf::layout_of] for the original documentation.
114+
#[inline(always)]
115+
pub fn layout_of(&self, ty: Ty<'tcx>) -> <Self as LayoutOfHelpers<'tcx>>::LayoutOfResult {
116+
let _span = enter_trace_span!(M, "InterpCx::layout_of", ty = ?ty.kind());
117+
LayoutOf::layout_of(self, ty)
118+
}
119+
120+
/// This inherent method takes priority over the trait method with the same name in FnAbiOf,
121+
/// and allows wrapping the actual [FnAbiOf::fn_abi_of_fn_ptr] with a tracing span.
122+
/// See [FnAbiOf::fn_abi_of_fn_ptr] for the original documentation.
123+
#[inline(always)]
124+
pub fn fn_abi_of_fn_ptr(
125+
&self,
126+
sig: ty::PolyFnSig<'tcx>,
127+
extra_args: &'tcx ty::List<Ty<'tcx>>,
128+
) -> <Self as FnAbiOfHelpers<'tcx>>::FnAbiOfResult {
129+
let _span = enter_trace_span!(M, "InterpCx::fn_abi_of_fn_ptr", ?sig, ?extra_args);
130+
FnAbiOf::fn_abi_of_fn_ptr(self, sig, extra_args)
131+
}
132+
133+
/// This inherent method takes priority over the trait method with the same name in FnAbiOf,
134+
/// and allows wrapping the actual [FnAbiOf::fn_abi_of_instance] with a tracing span.
135+
/// See [FnAbiOf::fn_abi_of_instance] for the original documentation.
136+
#[inline(always)]
137+
pub fn fn_abi_of_instance(
138+
&self,
139+
instance: ty::Instance<'tcx>,
140+
extra_args: &'tcx ty::List<Ty<'tcx>>,
141+
) -> <Self as FnAbiOfHelpers<'tcx>>::FnAbiOfResult {
142+
let _span = enter_trace_span!(M, "InterpCx::fn_abi_of_instance", ?instance, ?extra_args);
143+
FnAbiOf::fn_abi_of_instance(self, instance, extra_args)
144+
}
145+
}
146+
124147
/// Test if it is valid for a MIR assignment to assign `src`-typed place to `dest`-typed value.
125148
/// This test should be symmetric, as it is primarily about layout compatibility.
126149
pub(super) fn mir_assign_valid_types<'tcx>(

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use either::Either;
66
use rustc_abi::{FIRST_VARIANT, FieldIdx};
77
use rustc_index::IndexSlice;
8-
use rustc_middle::ty::layout::FnAbiOf;
98
use rustc_middle::ty::{self, Instance, Ty};
109
use rustc_middle::{bug, mir, span_bug};
1110
use rustc_span::source_map::Spanned;

src/tools/miri/src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_index::IndexVec;
1313
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1414
use rustc_middle::middle::dependency_format::Linkage;
1515
use rustc_middle::middle::exported_symbols::ExportedSymbol;
16-
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
16+
use rustc_middle::ty::layout::{LayoutOf, MaybeResult, TyAndLayout};
1717
use rustc_middle::ty::{self, Binder, FloatTy, FnSig, IntTy, Ty, TyCtxt, UintTy};
1818
use rustc_session::config::CrateType;
1919
use rustc_span::{Span, Symbol};

0 commit comments

Comments
 (0)