diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-06 15:08:20 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-06 15:08:20 +0100 |
commit | 8e768a5a1f83bd0531835687d703ddec85446f8c (patch) | |
tree | 6d98f5afbbcc8f694621b6bed167fc027b3242a1 /crates/hir_def/src/body/lower.rs | |
parent | 7d39b13996e312a8a738ed0dfccab45978fc42f8 (diff) | |
parent | a25fbdb30a708cfecbd7aa4343e32c24bd692f20 (diff) |
Merge #8374
8374: Intern TypeRefs stored in Body r=jonas-schievink a=jonas-schievink
Minor improvement to memory usage (1 MB or so)
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/body/lower.rs')
-rw-r--r-- | crates/hir_def/src/body/lower.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 1e743e5d5..bfb75a8a5 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs | |||
@@ -30,6 +30,7 @@ use crate::{ | |||
30 | LabelId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, | 30 | LabelId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, |
31 | Statement, | 31 | Statement, |
32 | }, | 32 | }, |
33 | intern::Interned, | ||
33 | item_scope::BuiltinShadowMode, | 34 | item_scope::BuiltinShadowMode, |
34 | path::{GenericArgs, Path}, | 35 | path::{GenericArgs, Path}, |
35 | type_ref::{Mutability, Rawness, TypeRef}, | 36 | type_ref::{Mutability, Rawness, TypeRef}, |
@@ -432,7 +433,7 @@ impl ExprCollector<'_> { | |||
432 | } | 433 | } |
433 | ast::Expr::CastExpr(e) => { | 434 | ast::Expr::CastExpr(e) => { |
434 | let expr = self.collect_expr_opt(e.expr()); | 435 | let expr = self.collect_expr_opt(e.expr()); |
435 | let type_ref = Box::new(TypeRef::from_ast_opt(&self.ctx(), e.ty())); | 436 | let type_ref = Interned::new(TypeRef::from_ast_opt(&self.ctx(), e.ty())); |
436 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) | 437 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) |
437 | } | 438 | } |
438 | ast::Expr::RefExpr(e) => { | 439 | ast::Expr::RefExpr(e) => { |
@@ -466,7 +467,8 @@ impl ExprCollector<'_> { | |||
466 | if let Some(pl) = e.param_list() { | 467 | if let Some(pl) = e.param_list() { |
467 | for param in pl.params() { | 468 | for param in pl.params() { |
468 | let pat = self.collect_pat_opt(param.pat()); | 469 | let pat = self.collect_pat_opt(param.pat()); |
469 | let type_ref = param.ty().map(|it| TypeRef::from_ast(&self.ctx(), it)); | 470 | let type_ref = |
471 | param.ty().map(|it| Interned::new(TypeRef::from_ast(&self.ctx(), it))); | ||
470 | args.push(pat); | 472 | args.push(pat); |
471 | arg_types.push(type_ref); | 473 | arg_types.push(type_ref); |
472 | } | 474 | } |
@@ -474,7 +476,7 @@ impl ExprCollector<'_> { | |||
474 | let ret_type = e | 476 | let ret_type = e |
475 | .ret_type() | 477 | .ret_type() |
476 | .and_then(|r| r.ty()) | 478 | .and_then(|r| r.ty()) |
477 | .map(|it| Box::new(TypeRef::from_ast(&self.ctx(), it))); | 479 | .map(|it| Interned::new(TypeRef::from_ast(&self.ctx(), it))); |
478 | let body = self.collect_expr_opt(e.body()); | 480 | let body = self.collect_expr_opt(e.body()); |
479 | self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) | 481 | self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) |
480 | } | 482 | } |
@@ -629,7 +631,8 @@ impl ExprCollector<'_> { | |||
629 | return; | 631 | return; |
630 | } | 632 | } |
631 | let pat = self.collect_pat_opt(stmt.pat()); | 633 | let pat = self.collect_pat_opt(stmt.pat()); |
632 | let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it)); | 634 | let type_ref = |
635 | stmt.ty().map(|it| Interned::new(TypeRef::from_ast(&self.ctx(), it))); | ||
633 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); | 636 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); |
634 | self.statements_in_scope.push(Statement::Let { pat, type_ref, initializer }); | 637 | self.statements_in_scope.push(Statement::Let { pat, type_ref, initializer }); |
635 | } | 638 | } |