Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e9c965d

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 e5b3e68 + bbd1c3a commit e9c965d

File tree

89 files changed

+315
-231
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

+315
-231
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;
@@ -2411,7 +2411,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24112411
let ty_left = left.ty(body, tcx);
24122412
match ty_left.kind() {
24132413
// Types with regions are comparable if they have a common super-type.
2414-
ty::RawPtr(_, _) | ty::FnPtr(_) => {
2414+
ty::RawPtr(_, _) | ty::FnPtr(..) => {
24152415
let ty_right = right.ty(body, tcx);
24162416
let common_ty = self.infcx.next_ty_var(body.source_info(location).span);
24172417
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
@@ -874,7 +874,7 @@ pub(crate) fn assert_assignable<'tcx>(
874874
(ty::Ref(_, a, _), ty::RawPtr(b, _)) | (ty::RawPtr(a, _), ty::Ref(_, b, _)) => {
875875
assert_assignable(fx, *a, *b, limit - 1);
876876
}
877-
(ty::FnPtr(_), ty::FnPtr(_)) => {
877+
(ty::FnPtr(..), ty::FnPtr(..)) => {
878878
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
879879
ParamEnv::reveal_all(),
880880
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
@@ -171,7 +171,7 @@ struct LocalReturnTyVisitor<'ck, 'mir, 'tcx> {
171171
impl<'ck, 'mir, 'tcx> TypeVisitor<TyCtxt<'tcx>> for LocalReturnTyVisitor<'ck, 'mir, 'tcx> {
172172
fn visit_ty(&mut self, t: Ty<'tcx>) {
173173
match t.kind() {
174-
ty::FnPtr(_) => {}
174+
ty::FnPtr(..) => {}
175175
ty::Ref(_, _, hir::Mutability::Mut) => {
176176
self.checker.check_op(ops::mut_ref::MutRef(self.kind));
177177
t.super_visit_with(self)
@@ -726,7 +726,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
726726
let (mut callee, mut fn_args) = match *fn_ty.kind() {
727727
ty::FnDef(def_id, fn_args) => (def_id, fn_args),
728728

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

0 commit comments

Comments
 (0)