Skip to content

Commit b46775a

Browse files
committed
Combine pat_hyigene and expr_hygiene
1 parent a91b571 commit b46775a

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/tools/rust-analyzer/crates/hir-def/src/body.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
mod lower;
44
mod pretty;
55
pub mod scope;
6+
67
#[cfg(test)]
78
mod tests;
89

@@ -92,11 +93,9 @@ pub struct Body {
9293
binding_hygiene: FxHashMap<BindingId, HygieneId>,
9394
/// A map from an variable usages to their hygiene ID.
9495
///
95-
/// Expressions that can be recorded here are single segment path, although not all single segments path refer
96+
/// Expressions (and destructuing patterns) that can be recorded here are single segment path, although not all single segments path refer
9697
/// to variables and have hygiene (some refer to items, we don't know at this stage).
97-
expr_hygiene: FxHashMap<ExprId, HygieneId>,
98-
/// A map from a destructuring assignment possible variable usages to their hygiene ID.
99-
pat_hygiene: FxHashMap<PatId, HygieneId>,
98+
ident_hygiene: FxHashMap<ExprOrPatId, HygieneId>,
10099
}
101100

102101
pub type ExprPtr = AstPtr<ast::Expr>;
@@ -317,8 +316,7 @@ impl Body {
317316
bindings,
318317
binding_owners,
319318
binding_hygiene,
320-
expr_hygiene,
321-
pat_hygiene,
319+
ident_hygiene,
322320
types,
323321
} = self;
324322
block_scopes.shrink_to_fit();
@@ -328,8 +326,7 @@ impl Body {
328326
bindings.shrink_to_fit();
329327
binding_owners.shrink_to_fit();
330328
binding_hygiene.shrink_to_fit();
331-
expr_hygiene.shrink_to_fit();
332-
pat_hygiene.shrink_to_fit();
329+
ident_hygiene.shrink_to_fit();
333330
types.shrink_to_fit();
334331
}
335332

@@ -658,11 +655,11 @@ impl Body {
658655
}
659656

660657
pub fn expr_path_hygiene(&self, expr: ExprId) -> HygieneId {
661-
self.expr_hygiene.get(&expr).copied().unwrap_or(HygieneId::ROOT)
658+
self.ident_hygiene.get(&expr.into()).copied().unwrap_or(HygieneId::ROOT)
662659
}
663660

664661
pub fn pat_path_hygiene(&self, pat: PatId) -> HygieneId {
665-
self.pat_hygiene.get(&pat).copied().unwrap_or(HygieneId::ROOT)
662+
self.ident_hygiene.get(&pat.into()).copied().unwrap_or(HygieneId::ROOT)
666663
}
667664

668665
pub fn expr_or_pat_path_hygiene(&self, id: ExprOrPatId) -> HygieneId {
@@ -686,8 +683,7 @@ impl Default for Body {
686683
binding_owners: Default::default(),
687684
self_param: Default::default(),
688685
binding_hygiene: Default::default(),
689-
expr_hygiene: Default::default(),
690-
pat_hygiene: Default::default(),
686+
ident_hygiene: Default::default(),
691687
types: Default::default(),
692688
}
693689
}

src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl ExprCollector<'_> {
480480
.unwrap_or((Expr::Missing, HygieneId::ROOT));
481481
let expr_id = self.alloc_expr(path, syntax_ptr);
482482
if !hygiene.is_root() {
483-
self.body.expr_hygiene.insert(expr_id, hygiene);
483+
self.body.ident_hygiene.insert(expr_id.into(), hygiene);
484484
}
485485
expr_id
486486
}
@@ -835,7 +835,7 @@ impl ExprCollector<'_> {
835835
.unwrap_or((Pat::Missing, HygieneId::ROOT));
836836
let pat_id = self.alloc_pat_from_expr(path, syntax_ptr);
837837
if !hygiene.is_root() {
838-
self.body.pat_hygiene.insert(pat_id, hygiene);
838+
self.body.ident_hygiene.insert(pat_id.into(), hygiene);
839839
}
840840
pat_id
841841
}
@@ -2023,7 +2023,7 @@ impl ExprCollector<'_> {
20232023
);
20242024
}
20252025
if !hygiene.is_root() {
2026-
self.body.expr_hygiene.insert(expr_id, hygiene);
2026+
self.body.ident_hygiene.insert(expr_id.into(), hygiene);
20272027
}
20282028
expr_id
20292029
},

src/tools/rust-analyzer/crates/hir-def/src/hir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub(crate) fn dummy_expr_id() -> ExprId {
4444

4545
pub type PatId = Idx<Pat>;
4646

47+
// FIXME: Encode this as a single u32, we won't ever reach all 32 bits especially given these counts
48+
// are local to the body.
4749
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
4850
pub enum ExprOrPatId {
4951
ExprId(ExprId),

0 commit comments

Comments
 (0)