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 <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-04-06 14:08:20 +00:00 committed by GitHub
commit 8e768a5a1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View file

@ -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 });
}

View file

@ -18,6 +18,7 @@ use syntax::ast::RangeOp;
use crate::{
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
intern::Interned,
path::{GenericArgs, Path},
type_ref::{Mutability, Rawness, TypeRef},
BlockId,
@ -131,7 +132,7 @@ pub enum Expr {
},
Cast {
expr: ExprId,
type_ref: Box<TypeRef>,
type_ref: Interned<TypeRef>,
},
Ref {
expr: ExprId,
@ -161,8 +162,8 @@ pub enum Expr {
},
Lambda {
args: Vec<PatId>,
arg_types: Vec<Option<TypeRef>>,
ret_type: Option<Box<TypeRef>>,
arg_types: Vec<Option<Interned<TypeRef>>>,
ret_type: Option<Interned<TypeRef>>,
body: ExprId,
},
Tuple {
@ -240,7 +241,7 @@ pub struct RecordLitField {
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Statement {
Let { pat: PatId, type_ref: Option<TypeRef>, initializer: Option<ExprId> },
Let { pat: PatId, type_ref: Option<Interned<TypeRef>>, initializer: Option<ExprId> },
Expr(ExprId),
}