mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Intern TypeRefs stored in Body
Minor improvement to memory usage (1 MB or so)
This commit is contained in:
parent
7d39b13996
commit
a25fbdb30a
2 changed files with 12 additions and 8 deletions
|
@ -30,6 +30,7 @@ use crate::{
|
||||||
LabelId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField,
|
LabelId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField,
|
||||||
Statement,
|
Statement,
|
||||||
},
|
},
|
||||||
|
intern::Interned,
|
||||||
item_scope::BuiltinShadowMode,
|
item_scope::BuiltinShadowMode,
|
||||||
path::{GenericArgs, Path},
|
path::{GenericArgs, Path},
|
||||||
type_ref::{Mutability, Rawness, TypeRef},
|
type_ref::{Mutability, Rawness, TypeRef},
|
||||||
|
@ -432,7 +433,7 @@ impl ExprCollector<'_> {
|
||||||
}
|
}
|
||||||
ast::Expr::CastExpr(e) => {
|
ast::Expr::CastExpr(e) => {
|
||||||
let expr = self.collect_expr_opt(e.expr());
|
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)
|
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::Expr::RefExpr(e) => {
|
ast::Expr::RefExpr(e) => {
|
||||||
|
@ -466,7 +467,8 @@ impl ExprCollector<'_> {
|
||||||
if let Some(pl) = e.param_list() {
|
if let Some(pl) = e.param_list() {
|
||||||
for param in pl.params() {
|
for param in pl.params() {
|
||||||
let pat = self.collect_pat_opt(param.pat());
|
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);
|
args.push(pat);
|
||||||
arg_types.push(type_ref);
|
arg_types.push(type_ref);
|
||||||
}
|
}
|
||||||
|
@ -474,7 +476,7 @@ impl ExprCollector<'_> {
|
||||||
let ret_type = e
|
let ret_type = e
|
||||||
.ret_type()
|
.ret_type()
|
||||||
.and_then(|r| r.ty())
|
.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());
|
let body = self.collect_expr_opt(e.body());
|
||||||
self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr)
|
self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr)
|
||||||
}
|
}
|
||||||
|
@ -629,7 +631,8 @@ impl ExprCollector<'_> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let pat = self.collect_pat_opt(stmt.pat());
|
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));
|
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
|
||||||
self.statements_in_scope.push(Statement::Let { pat, type_ref, initializer });
|
self.statements_in_scope.push(Statement::Let { pat, type_ref, initializer });
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ use syntax::ast::RangeOp;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
|
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
|
||||||
|
intern::Interned,
|
||||||
path::{GenericArgs, Path},
|
path::{GenericArgs, Path},
|
||||||
type_ref::{Mutability, Rawness, TypeRef},
|
type_ref::{Mutability, Rawness, TypeRef},
|
||||||
BlockId,
|
BlockId,
|
||||||
|
@ -131,7 +132,7 @@ pub enum Expr {
|
||||||
},
|
},
|
||||||
Cast {
|
Cast {
|
||||||
expr: ExprId,
|
expr: ExprId,
|
||||||
type_ref: Box<TypeRef>,
|
type_ref: Interned<TypeRef>,
|
||||||
},
|
},
|
||||||
Ref {
|
Ref {
|
||||||
expr: ExprId,
|
expr: ExprId,
|
||||||
|
@ -161,8 +162,8 @@ pub enum Expr {
|
||||||
},
|
},
|
||||||
Lambda {
|
Lambda {
|
||||||
args: Vec<PatId>,
|
args: Vec<PatId>,
|
||||||
arg_types: Vec<Option<TypeRef>>,
|
arg_types: Vec<Option<Interned<TypeRef>>>,
|
||||||
ret_type: Option<Box<TypeRef>>,
|
ret_type: Option<Interned<TypeRef>>,
|
||||||
body: ExprId,
|
body: ExprId,
|
||||||
},
|
},
|
||||||
Tuple {
|
Tuple {
|
||||||
|
@ -240,7 +241,7 @@ pub struct RecordLitField {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum Statement {
|
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),
|
Expr(ExprId),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue