Skip to content

Commit c4717cc

Browse files
committed
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.
1 parent 8640998 commit c4717cc

File tree

89 files changed

+298
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+298
-201
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3989,7 +3989,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
39893989
} else {
39903990
let ty = self.infcx.tcx.type_of(self.mir_def_id()).instantiate_identity();
39913991
match ty.kind() {
3992-
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
3992+
ty::FnDef(_, _) | ty::FnPtr(..) => self.annotate_fn_sig(
39933993
self.mir_def_id(),
39943994
self.infcx.tcx.fn_sig(self.mir_def_id()).instantiate_identity(),
39953995
),

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
16441644
| ty::Pat(_, _)
16451645
| ty::Slice(_)
16461646
| ty::FnDef(_, _)
1647-
| ty::FnPtr(_)
1647+
| ty::FnPtr(..)
16481648
| ty::Dynamic(_, _, _)
16491649
| ty::Closure(_, _)
16501650
| ty::CoroutineClosure(_, _)
@@ -1689,7 +1689,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
16891689
| ty::RawPtr(_, _)
16901690
| ty::Ref(_, _, _)
16911691
| ty::FnDef(_, _)
1692-
| ty::FnPtr(_)
1692+
| ty::FnPtr(..)
16931693
| ty::Dynamic(_, _, _)
16941694
| ty::CoroutineWitness(..)
16951695
| ty::Never

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13641364
debug!("func_ty.kind: {:?}", func_ty.kind());
13651365

13661366
let sig = match func_ty.kind() {
1367-
ty::FnDef(..) | ty::FnPtr(_) => func_ty.fn_sig(tcx),
1367+
ty::FnDef(..) | ty::FnPtr(..) => func_ty.fn_sig(tcx),
13681368
_ => {
13691369
span_mirbug!(self, term, "call to non-function {:?}", func_ty);
13701370
return;
@@ -2420,7 +2420,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24202420
let ty_left = left.ty(body, tcx);
24212421
match ty_left.kind() {
24222422
// Types with regions are comparable if they have a common super-type.
2423-
ty::RawPtr(_, _) | ty::FnPtr(_) => {
2423+
ty::RawPtr(_, _) | ty::FnPtr(..) => {
24242424
let ty_right = right.ty(body, tcx);
24252425
let common_ty = self.infcx.next_ty_var(body.source_info(location).span);
24262426
self.sub_types(

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Typ
6969
FloatTy::F64 => types::F64,
7070
FloatTy::F128 => unimplemented!("f16_f128"),
7171
},
72-
ty::FnPtr(_) => pointer_ty(tcx),
72+
ty::FnPtr(..) => pointer_ty(tcx),
7373
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
7474
if has_ptr_meta(tcx, *pointee_ty) {
7575
return None;

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ pub(crate) fn assert_assignable<'tcx>(
872872
(ty::Ref(_, a, _), ty::RawPtr(b, _)) | (ty::RawPtr(a, _), ty::Ref(_, b, _)) => {
873873
assert_assignable(fx, *a, *b, limit - 1);
874874
}
875-
(ty::FnPtr(_), ty::FnPtr(_)) => {
875+
(ty::FnPtr(..), ty::FnPtr(..)) => {
876876
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
877877
ParamEnv::reveal_all(),
878878
from_ty.fn_sig(fx.tcx),

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
213213
// NOTE: we cannot remove this match like in the LLVM codegen because the call
214214
// to fn_ptr_backend_type handle the on-stack attribute.
215215
// TODO(antoyo): find a less hackish way to hande the on-stack attribute.
216-
ty::FnPtr(sig) => {
217-
cx.fn_ptr_backend_type(cx.fn_abi_of_fn_ptr(sig, ty::List::empty()))
218-
}
216+
ty::FnPtr(sig_tys, hdr) => cx
217+
.fn_ptr_backend_type(cx.fn_abi_of_fn_ptr(sig_tys.with(hdr), ty::List::empty())),
219218
_ => self.scalar_gcc_type_at(cx, scalar, Size::ZERO),
220219
};
221220
cx.scalar_types.borrow_mut().insert(self.ty, ty);

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
456456
{
457457
build_pointer_or_reference_di_node(cx, t, t.boxed_ty(), unique_type_id)
458458
}
459-
ty::FnDef(..) | ty::FnPtr(_) => build_subroutine_type_di_node(cx, unique_type_id),
459+
ty::FnDef(..) | ty::FnPtr(..) => build_subroutine_type_di_node(cx, unique_type_id),
460460
ty::Closure(..) => build_closure_env_di_node(cx, unique_type_id),
461461
ty::CoroutineClosure(..) => build_closure_env_di_node(cx, unique_type_id),
462462
ty::Coroutine(..) => enums::build_coroutine_di_node(cx, unique_type_id),

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ fn push_debuginfo_type_name<'tcx>(
331331
output.push(')');
332332
}
333333
}
334-
ty::FnDef(..) | ty::FnPtr(_) => {
334+
ty::FnDef(..) | ty::FnPtr(..) => {
335335
// We've encountered a weird 'recursive type'
336336
// Currently, the only way to generate such a type
337337
// is by using 'impl trait':

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
846846
),
847847
None,
848848
),
849-
ty::FnPtr(_) => (None, Some(callee.immediate())),
849+
ty::FnPtr(..) => (None, Some(callee.immediate())),
850850
_ => bug!("{} is not callable", callee.layout.ty),
851851
};
852852

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct LocalReturnTyVisitor<'ck, 'mir, 'tcx> {
170170
impl<'ck, 'mir, 'tcx> TypeVisitor<TyCtxt<'tcx>> for LocalReturnTyVisitor<'ck, 'mir, 'tcx> {
171171
fn visit_ty(&mut self, t: Ty<'tcx>) {
172172
match t.kind() {
173-
ty::FnPtr(_) => {}
173+
ty::FnPtr(..) => {}
174174
ty::Ref(_, _, hir::Mutability::Mut) => {
175175
self.checker.check_op(ops::mut_ref::MutRef(self.kind));
176176
t.super_visit_with(self)
@@ -725,7 +725,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
725725
let (mut callee, mut fn_args) = match *fn_ty.kind() {
726726
ty::FnDef(def_id, fn_args) => (def_id, fn_args),
727727

728-
ty::FnPtr(_) => {
728+
ty::FnPtr(..) => {
729729
self.check_op(ops::FnCallIndirect);
730730
return;
731731
}

0 commit comments

Comments
 (0)