From a25fbdb30a708cfecbd7aa4343e32c24bd692f20 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 6 Apr 2021 16:07:45 +0200 Subject: Intern TypeRefs stored in Body Minor improvement to memory usage (1 MB or so) --- crates/hir_def/src/body/lower.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'crates/hir_def/src/body/lower.rs') 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::{ LabelId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, }, + intern::Interned, item_scope::BuiltinShadowMode, path::{GenericArgs, Path}, type_ref::{Mutability, Rawness, TypeRef}, @@ -432,7 +433,7 @@ impl ExprCollector<'_> { } ast::Expr::CastExpr(e) => { let expr = self.collect_expr_opt(e.expr()); - let type_ref = Box::new(TypeRef::from_ast_opt(&self.ctx(), e.ty())); + let type_ref = Interned::new(TypeRef::from_ast_opt(&self.ctx(), e.ty())); self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) } ast::Expr::RefExpr(e) => { @@ -466,7 +467,8 @@ impl ExprCollector<'_> { if let Some(pl) = e.param_list() { for param in pl.params() { let pat = self.collect_pat_opt(param.pat()); - let type_ref = param.ty().map(|it| TypeRef::from_ast(&self.ctx(), it)); + let type_ref = + param.ty().map(|it| Interned::new(TypeRef::from_ast(&self.ctx(), it))); args.push(pat); arg_types.push(type_ref); } @@ -474,7 +476,7 @@ impl ExprCollector<'_> { let ret_type = e .ret_type() .and_then(|r| r.ty()) - .map(|it| Box::new(TypeRef::from_ast(&self.ctx(), it))); + .map(|it| Interned::new(TypeRef::from_ast(&self.ctx(), it))); let body = self.collect_expr_opt(e.body()); self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) } @@ -629,7 +631,8 @@ impl ExprCollector<'_> { return; } let pat = self.collect_pat_opt(stmt.pat()); - let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it)); + let type_ref = + stmt.ty().map(|it| Interned::new(TypeRef::from_ast(&self.ctx(), it))); let initializer = stmt.initializer().map(|e| self.collect_expr(e)); self.statements_in_scope.push(Statement::Let { pat, type_ref, initializer }); } -- cgit v1.2.3