From fb1f544e2479addd5957688e297ea04ddf0cf249 Mon Sep 17 00:00:00 2001 From: Alexandru Macovei Date: Tue, 30 Mar 2021 23:06:57 +0300 Subject: Use Box'es to reduce size of hir_def::expr::Expr from 128 to 72 bytes (on 64bit systems) Rationale: only a minority of variants used almost half the size. By keeping large members (especially in Option) behind a box the memory cost is only payed when the large variants are needed. This reduces the size Vec needs to allocate. --- crates/hir_ty/src/infer/expr.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'crates/hir_ty/src/infer') diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index ff564106b..2fcc7c549 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -317,7 +317,13 @@ impl<'a> InferenceContext<'a> { self.normalize_associated_types_in(ret_ty) } Expr::MethodCall { receiver, args, method_name, generic_args } => self - .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()), + .infer_method_call( + tgt_expr, + *receiver, + &args, + &method_name, + generic_args.as_deref(), + ), Expr::Match { expr, arms } => { let input_ty = self.infer_expr(*expr, &Expectation::none()); @@ -398,7 +404,7 @@ impl<'a> InferenceContext<'a> { TyKind::Never.intern(&Interner) } Expr::RecordLit { path, fields, spread } => { - let (ty, def_id) = self.resolve_variant(path.as_ref()); + let (ty, def_id) = self.resolve_variant(path.as_deref()); if let Some(variant) = def_id { self.write_variant_resolution(tgt_expr.into(), variant); } -- cgit v1.2.3 From 32304d14a1a5e316615028ffd7bcfcff682fbe56 Mon Sep 17 00:00:00 2001 From: Alexandru Macovei Date: Wed, 31 Mar 2021 00:55:18 +0300 Subject: Use Box'es to reduce the size of hir_def::expr::Pat from 112 to 64 bytes on 64bit --- crates/hir_ty/src/infer/pat.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/hir_ty/src/infer') diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 252ae914a..afaf6b28b 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -174,7 +174,7 @@ impl<'a> InferenceContext<'a> { TyKind::Ref(mutability, subty).intern(&Interner) } Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( - p.as_ref(), + p.as_deref(), subpats, expected, default_bm, @@ -182,7 +182,7 @@ impl<'a> InferenceContext<'a> { *ellipsis, ), Pat::Record { path: p, args: fields, ellipsis: _ } => { - self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat) + self.infer_record_pat(p.as_deref(), fields, expected, default_bm, pat) } Pat::Path(path) => { // FIXME use correct resolver for the surrounding expression -- cgit v1.2.3