aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-06 15:07:45 +0100
committerJonas Schievink <[email protected]>2021-04-06 15:07:45 +0100
commita25fbdb30a708cfecbd7aa4343e32c24bd692f20 (patch)
tree6d98f5afbbcc8f694621b6bed167fc027b3242a1 /crates/hir_def
parent7d39b13996e312a8a738ed0dfccab45978fc42f8 (diff)
Intern TypeRefs stored in Body
Minor improvement to memory usage (1 MB or so)
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/body/lower.rs11
-rw-r--r--crates/hir_def/src/expr.rs9
2 files changed, 12 insertions, 8 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 }
diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs
index 62a28bdba..b4ad984bd 100644
--- a/crates/hir_def/src/expr.rs
+++ b/crates/hir_def/src/expr.rs
@@ -18,6 +18,7 @@ use syntax::ast::RangeOp;
18 18
19use crate::{ 19use crate::{
20 builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint}, 20 builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
21 intern::Interned,
21 path::{GenericArgs, Path}, 22 path::{GenericArgs, Path},
22 type_ref::{Mutability, Rawness, TypeRef}, 23 type_ref::{Mutability, Rawness, TypeRef},
23 BlockId, 24 BlockId,
@@ -131,7 +132,7 @@ pub enum Expr {
131 }, 132 },
132 Cast { 133 Cast {
133 expr: ExprId, 134 expr: ExprId,
134 type_ref: Box<TypeRef>, 135 type_ref: Interned<TypeRef>,
135 }, 136 },
136 Ref { 137 Ref {
137 expr: ExprId, 138 expr: ExprId,
@@ -161,8 +162,8 @@ pub enum Expr {
161 }, 162 },
162 Lambda { 163 Lambda {
163 args: Vec<PatId>, 164 args: Vec<PatId>,
164 arg_types: Vec<Option<TypeRef>>, 165 arg_types: Vec<Option<Interned<TypeRef>>>,
165 ret_type: Option<Box<TypeRef>>, 166 ret_type: Option<Interned<TypeRef>>,
166 body: ExprId, 167 body: ExprId,
167 }, 168 },
168 Tuple { 169 Tuple {
@@ -240,7 +241,7 @@ pub struct RecordLitField {
240 241
241#[derive(Debug, Clone, Eq, PartialEq)] 242#[derive(Debug, Clone, Eq, PartialEq)]
242pub enum Statement { 243pub enum Statement {
243 Let { pat: PatId, type_ref: Option<TypeRef>, initializer: Option<ExprId> }, 244 Let { pat: PatId, type_ref: Option<Interned<TypeRef>>, initializer: Option<ExprId> },
244 Expr(ExprId), 245 Expr(ExprId),
245} 246}
246 247