Skip to content

Commit 6d08b08

Browse files
committed
Auto merge of rust-lang#128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors
Shrink `TyKind::FnPtr`. By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI. r? `@compiler-errors`
2 parents e36c2a4 + e785219 commit 6d08b08

12 files changed

+13
-13
lines changed

clippy_lints/src/casts/fn_to_numeric_cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
1515
}
1616

1717
match cast_from.kind() {
18-
ty::FnDef(..) | ty::FnPtr(_) => {
18+
ty::FnDef(..) | ty::FnPtr(..) => {
1919
let mut applicability = Applicability::MaybeIncorrect;
2020
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability);
2121
let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx);

clippy_lints/src/casts/fn_to_numeric_cast_any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
1414
_ => { /* continue to checks */ },
1515
}
1616

17-
if let ty::FnDef(..) | ty::FnPtr(_) = cast_from.kind() {
17+
if let ty::FnDef(..) | ty::FnPtr(..) = cast_from.kind() {
1818
let mut applicability = Applicability::MaybeIncorrect;
1919
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability);
2020

clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
1414
_ => return,
1515
}
1616
match cast_from.kind() {
17-
ty::FnDef(..) | ty::FnPtr(_) => {
17+
ty::FnDef(..) | ty::FnPtr(..) => {
1818
let mut applicability = Applicability::MaybeIncorrect;
1919
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability);
2020

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'
236236
// We can't use `Ty::fn_sig` because it automatically performs args, this may result in FNs.
237237
match node_ty.kind() {
238238
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).instantiate_identity()),
239-
ty::FnPtr(fn_sig) => Some(*fn_sig),
239+
ty::FnPtr(sig_tys, hdr) => Some(sig_tys.with(*hdr)),
240240
_ => None,
241241
}
242242
}

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ impl TyCoercionStability {
872872
| ty::Pat(..)
873873
| ty::Float(_)
874874
| ty::RawPtr(..)
875-
| ty::FnPtr(_)
875+
| ty::FnPtr(..)
876876
| ty::Str
877877
| ty::Slice(..)
878878
| ty::Adt(..)

clippy_lints/src/eta_reduction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn check_clousure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tc
158158

159159
cx.tcx.fn_sig(def).skip_binder().skip_binder()
160160
},
161-
ty::FnPtr(sig) => sig.skip_binder(),
161+
ty::FnPtr(sig_tys, hdr) => sig_tys.with(*hdr).skip_binder(),
162162
ty::Closure(_, subs) => cx
163163
.tcx
164164
.signature_unclosure(subs.as_closure().sig(), Safety::Safe)

clippy_lints/src/methods/map_flatten.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn try_get_caller_ty_name_and_method_name(
5858
fn is_map_to_option(cx: &LateContext<'_>, map_arg: &Expr<'_>) -> bool {
5959
let map_closure_ty = cx.typeck_results().expr_ty(map_arg);
6060
match map_closure_ty.kind() {
61-
ty::Closure(_, _) | ty::FnDef(_, _) | ty::FnPtr(_) => {
61+
ty::Closure(_, _) | ty::FnDef(_, _) | ty::FnPtr(..) => {
6262
let map_closure_sig = match map_closure_ty.kind() {
6363
ty::Closure(_, args) => args.as_closure().sig(),
6464
_ => map_closure_ty.fn_sig(cx.tcx),

clippy_lints/src/mixed_read_write_in_expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
166166
ExprKind::Call(func, _) => {
167167
let typ = self.cx.typeck_results().expr_ty(func);
168168
match typ.kind() {
169-
ty::FnDef(..) | ty::FnPtr(_) => {
169+
ty::FnDef(..) | ty::FnPtr(..) => {
170170
let sig = typ.fn_sig(self.cx.tcx);
171171
if self.cx.tcx.instantiate_bound_regions_with_erased(sig).output().kind() == &ty::Never {
172172
self.report_diverging_sub_expr(e);

clippy_lints/src/multiple_unsafe_ops_per_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn collect_unsafe_exprs<'tcx>(
130130
ExprKind::Call(path_expr, _) => {
131131
let sig = match *cx.typeck_results().expr_ty(path_expr).kind() {
132132
ty::FnDef(id, _) => cx.tcx.fn_sig(id).skip_binder(),
133-
ty::FnPtr(sig) => sig,
133+
ty::FnPtr(sig_tys, hdr) => sig_tys.with(hdr),
134134
_ => return Continue(Descend::Yes),
135135
};
136136
if sig.safety() == Safety::Unsafe {

clippy_lints/src/mut_reference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn check_arguments<'tcx>(
7979
fn_kind: &str,
8080
) {
8181
match type_definition.kind() {
82-
ty::FnDef(..) | ty::FnPtr(_) => {
82+
ty::FnDef(..) | ty::FnPtr(..) => {
8383
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
8484
for (argument, parameter) in iter::zip(arguments, parameters) {
8585
match parameter.kind() {

clippy_utils/src/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ pub fn peel_mid_ty_refs_is_mutable(ty: Ty<'_>) -> (Ty<'_>, usize, Mutability) {
541541
/// Returns `true` if the given type is an `unsafe` function.
542542
pub fn type_is_unsafe_function<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
543543
match ty.kind() {
544-
ty::FnDef(..) | ty::FnPtr(_) => ty.fn_sig(cx.tcx).safety() == Safety::Unsafe,
544+
ty::FnDef(..) | ty::FnPtr(..) => ty.fn_sig(cx.tcx).safety() == Safety::Unsafe,
545545
_ => false,
546546
}
547547
}
@@ -721,7 +721,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
721721
cx.tcx.item_super_predicates(def_id).iter_instantiated(cx.tcx, args),
722722
cx.tcx.opt_parent(def_id),
723723
),
724-
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
724+
ty::FnPtr(sig_tys, hdr) => Some(ExprFnSig::Sig(sig_tys.with(hdr), None)),
725725
ty::Dynamic(bounds, _, _) => {
726726
let lang_items = cx.tcx.lang_items();
727727
match bounds.principal() {

clippy_utils/src/visitors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
441441
ty::FnDef(id, _) if self.cx.tcx.fn_sig(id).skip_binder().safety() == Safety::Unsafe => {
442442
self.is_unsafe = true;
443443
},
444-
ty::FnPtr(sig) if sig.safety() == Safety::Unsafe => self.is_unsafe = true,
444+
ty::FnPtr(_, hdr) if hdr.safety == Safety::Unsafe => self.is_unsafe = true,
445445
_ => walk_expr(self, e),
446446
},
447447
ExprKind::Path(ref p)

0 commit comments

Comments
 (0)