Use Box'es to reduce the size of hir_def::expr::Pat from 112 to 64 bytes on 64bit

This commit is contained in:
Alexandru Macovei 2021-03-31 00:55:18 +03:00
parent fb1f544e24
commit 32304d14a1
4 changed files with 14 additions and 8 deletions

View File

@ -759,7 +759,7 @@ impl ExprCollector<'_> {
}
}
ast::Pat::TupleStructPat(p) => {
let path = p.path().and_then(|path| self.expander.parse_path(path));
let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
let (args, ellipsis) = self.collect_tuple_pat(p.fields());
Pat::TupleStruct { path, args, ellipsis }
}
@ -769,7 +769,7 @@ impl ExprCollector<'_> {
Pat::Ref { pat, mutability }
}
ast::Pat::PathPat(p) => {
let path = p.path().and_then(|path| self.expander.parse_path(path));
let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
path.map(Pat::Path).unwrap_or(Pat::Missing)
}
ast::Pat::OrPat(p) => {
@ -783,7 +783,7 @@ impl ExprCollector<'_> {
}
ast::Pat::WildcardPat(_) => Pat::Wild,
ast::Pat::RecordPat(p) => {
let path = p.path().and_then(|path| self.expander.parse_path(path));
let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
let args: Vec<_> = p
.record_pat_field_list()
.expect("every struct should have a field list")

View File

@ -412,13 +412,13 @@ pub enum Pat {
Wild,
Tuple { args: Vec<PatId>, ellipsis: Option<usize> },
Or(Vec<PatId>),
Record { path: Option<Path>, args: Vec<RecordFieldPat>, ellipsis: bool },
Record { path: Option<Box<Path>>, args: Vec<RecordFieldPat>, ellipsis: bool },
Range { start: ExprId, end: ExprId },
Slice { prefix: Vec<PatId>, slice: Option<PatId>, suffix: Vec<PatId> },
Path(Path),
Path(Box<Path>),
Lit(ExprId),
Bind { mode: BindingAnnotation, name: Name, subpat: Option<PatId> },
TupleStruct { path: Option<Path>, args: Vec<PatId>, ellipsis: Option<usize> },
TupleStruct { path: Option<Box<Path>>, args: Vec<PatId>, ellipsis: Option<usize> },
Ref { pat: PatId, mutability: Mutability },
Box { inner: PatId },
ConstBlock(ExprId),

View File

@ -289,6 +289,12 @@ impl From<Name> for Path {
}
}
impl From<Name> for Box<Path> {
fn from(name: Name) -> Box<Path> {
Box::new(Path::from(name))
}
}
impl From<Name> for ModPath {
fn from(name: Name) -> ModPath {
ModPath::from_segments(PathKind::Plain, iter::once(name))

View File

@ -174,7 +174,7 @@ impl<'a> InferenceContext<'a> {
TyKind::Ref(mutability, subty).intern(&Interner)
}
Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat(
p.as_ref(),
p.as_deref(),
subpats,
expected,
default_bm,
@ -182,7 +182,7 @@ impl<'a> InferenceContext<'a> {
*ellipsis,
),
Pat::Record { path: p, args: fields, ellipsis: _ } => {
self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat)
self.infer_record_pat(p.as_deref(), fields, expected, default_bm, pat)
}
Pat::Path(path) => {
// FIXME use correct resolver for the surrounding expression