Skip to content

Commit 32304d1

Browse files
committed
Use Box'es to reduce the size of hir_def::expr::Pat from 112 to 64 bytes on 64bit
1 parent fb1f544 commit 32304d1

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

crates/hir_def/src/body/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ impl ExprCollector<'_> {
759759
}
760760
}
761761
ast::Pat::TupleStructPat(p) => {
762-
let path = p.path().and_then(|path| self.expander.parse_path(path));
762+
let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
763763
let (args, ellipsis) = self.collect_tuple_pat(p.fields());
764764
Pat::TupleStruct { path, args, ellipsis }
765765
}
@@ -769,7 +769,7 @@ impl ExprCollector<'_> {
769769
Pat::Ref { pat, mutability }
770770
}
771771
ast::Pat::PathPat(p) => {
772-
let path = p.path().and_then(|path| self.expander.parse_path(path));
772+
let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
773773
path.map(Pat::Path).unwrap_or(Pat::Missing)
774774
}
775775
ast::Pat::OrPat(p) => {
@@ -783,7 +783,7 @@ impl ExprCollector<'_> {
783783
}
784784
ast::Pat::WildcardPat(_) => Pat::Wild,
785785
ast::Pat::RecordPat(p) => {
786-
let path = p.path().and_then(|path| self.expander.parse_path(path));
786+
let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
787787
let args: Vec<_> = p
788788
.record_pat_field_list()
789789
.expect("every struct should have a field list")

crates/hir_def/src/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,13 @@ pub enum Pat {
412412
Wild,
413413
Tuple { args: Vec<PatId>, ellipsis: Option<usize> },
414414
Or(Vec<PatId>),
415-
Record { path: Option<Path>, args: Vec<RecordFieldPat>, ellipsis: bool },
415+
Record { path: Option<Box<Path>>, args: Vec<RecordFieldPat>, ellipsis: bool },
416416
Range { start: ExprId, end: ExprId },
417417
Slice { prefix: Vec<PatId>, slice: Option<PatId>, suffix: Vec<PatId> },
418-
Path(Path),
418+
Path(Box<Path>),
419419
Lit(ExprId),
420420
Bind { mode: BindingAnnotation, name: Name, subpat: Option<PatId> },
421-
TupleStruct { path: Option<Path>, args: Vec<PatId>, ellipsis: Option<usize> },
421+
TupleStruct { path: Option<Box<Path>>, args: Vec<PatId>, ellipsis: Option<usize> },
422422
Ref { pat: PatId, mutability: Mutability },
423423
Box { inner: PatId },
424424
ConstBlock(ExprId),

crates/hir_def/src/path.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ impl From<Name> for Path {
289289
}
290290
}
291291

292+
impl From<Name> for Box<Path> {
293+
fn from(name: Name) -> Box<Path> {
294+
Box::new(Path::from(name))
295+
}
296+
}
297+
292298
impl From<Name> for ModPath {
293299
fn from(name: Name) -> ModPath {
294300
ModPath::from_segments(PathKind::Plain, iter::once(name))

crates/hir_ty/src/infer/pat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ impl<'a> InferenceContext<'a> {
174174
TyKind::Ref(mutability, subty).intern(&Interner)
175175
}
176176
Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat(
177-
p.as_ref(),
177+
p.as_deref(),
178178
subpats,
179179
expected,
180180
default_bm,
181181
pat,
182182
*ellipsis,
183183
),
184184
Pat::Record { path: p, args: fields, ellipsis: _ } => {
185-
self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat)
185+
self.infer_record_pat(p.as_deref(), fields, expected, default_bm, pat)
186186
}
187187
Pat::Path(path) => {
188188
// FIXME use correct resolver for the surrounding expression

0 commit comments

Comments
 (0)