aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/body/lower.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-06 14:43:37 +0100
committerGitHub <[email protected]>2021-04-06 14:43:37 +0100
commit7d39b13996e312a8a738ed0dfccab45978fc42f8 (patch)
tree91761b9bf78d9015fbb6083b9245eb9f6133e234 /crates/hir_def/src/body/lower.rs
parent12e86433ab57ee8b1c96b8da0480fd311752487b (diff)
parent4e2a6ac7eae3ff193962421cc3c86e5d8f9a7e31 (diff)
Merge #8364
8364: Memory usage improvements r=jonas-schievink a=alexmaco These are mostly focused on splitting up enum variants with large size differences between variants by `Box`-ing things up. In my testing this reduces the memory usage somewhere in the low percentages, even though the measurements are quite noisy. Co-authored-by: Alexandru Macovei <[email protected]>
Diffstat (limited to 'crates/hir_def/src/body/lower.rs')
-rw-r--r--crates/hir_def/src/body/lower.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index 63e89a1f4..1e743e5d5 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -322,8 +322,10 @@ impl ExprCollector<'_> {
322 Vec::new() 322 Vec::new()
323 }; 323 };
324 let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); 324 let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
325 let generic_args = 325 let generic_args = e
326 e.generic_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx(), it)); 326 .generic_arg_list()
327 .and_then(|it| GenericArgs::from_ast(&self.ctx(), it))
328 .map(Box::new);
327 self.alloc_expr( 329 self.alloc_expr(
328 Expr::MethodCall { receiver, method_name, args, generic_args }, 330 Expr::MethodCall { receiver, method_name, args, generic_args },
329 syntax_ptr, 331 syntax_ptr,
@@ -385,7 +387,7 @@ impl ExprCollector<'_> {
385 self.alloc_expr(Expr::Yield { expr }, syntax_ptr) 387 self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
386 } 388 }
387 ast::Expr::RecordExpr(e) => { 389 ast::Expr::RecordExpr(e) => {
388 let path = e.path().and_then(|path| self.expander.parse_path(path)); 390 let path = e.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
389 let record_lit = if let Some(nfl) = e.record_expr_field_list() { 391 let record_lit = if let Some(nfl) = e.record_expr_field_list() {
390 let fields = nfl 392 let fields = nfl
391 .fields() 393 .fields()
@@ -430,7 +432,7 @@ impl ExprCollector<'_> {
430 } 432 }
431 ast::Expr::CastExpr(e) => { 433 ast::Expr::CastExpr(e) => {
432 let expr = self.collect_expr_opt(e.expr()); 434 let expr = self.collect_expr_opt(e.expr());
433 let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty()); 435 let type_ref = Box::new(TypeRef::from_ast_opt(&self.ctx(), e.ty()));
434 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) 436 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
435 } 437 }
436 ast::Expr::RefExpr(e) => { 438 ast::Expr::RefExpr(e) => {
@@ -469,8 +471,10 @@ impl ExprCollector<'_> {
469 arg_types.push(type_ref); 471 arg_types.push(type_ref);
470 } 472 }
471 } 473 }
472 let ret_type = 474 let ret_type = e
473 e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&self.ctx(), it)); 475 .ret_type()
476 .and_then(|r| r.ty())
477 .map(|it| Box::new(TypeRef::from_ast(&self.ctx(), it)));
474 let body = self.collect_expr_opt(e.body()); 478 let body = self.collect_expr_opt(e.body());
475 self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) 479 self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr)
476 } 480 }
@@ -755,7 +759,7 @@ impl ExprCollector<'_> {
755 } 759 }
756 } 760 }
757 ast::Pat::TupleStructPat(p) => { 761 ast::Pat::TupleStructPat(p) => {
758 let path = p.path().and_then(|path| self.expander.parse_path(path)); 762 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
759 let (args, ellipsis) = self.collect_tuple_pat(p.fields()); 763 let (args, ellipsis) = self.collect_tuple_pat(p.fields());
760 Pat::TupleStruct { path, args, ellipsis } 764 Pat::TupleStruct { path, args, ellipsis }
761 } 765 }
@@ -765,7 +769,7 @@ impl ExprCollector<'_> {
765 Pat::Ref { pat, mutability } 769 Pat::Ref { pat, mutability }
766 } 770 }
767 ast::Pat::PathPat(p) => { 771 ast::Pat::PathPat(p) => {
768 let path = p.path().and_then(|path| self.expander.parse_path(path)); 772 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
769 path.map(Pat::Path).unwrap_or(Pat::Missing) 773 path.map(Pat::Path).unwrap_or(Pat::Missing)
770 } 774 }
771 ast::Pat::OrPat(p) => { 775 ast::Pat::OrPat(p) => {
@@ -779,7 +783,7 @@ impl ExprCollector<'_> {
779 } 783 }
780 ast::Pat::WildcardPat(_) => Pat::Wild, 784 ast::Pat::WildcardPat(_) => Pat::Wild,
781 ast::Pat::RecordPat(p) => { 785 ast::Pat::RecordPat(p) => {
782 let path = p.path().and_then(|path| self.expander.parse_path(path)); 786 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
783 let args: Vec<_> = p 787 let args: Vec<_> = p
784 .record_pat_field_list() 788 .record_pat_field_list()
785 .expect("every struct should have a field list") 789 .expect("every struct should have a field list")