minor: Remove dead code

This commit is contained in:
Lukas Wirth 2023-03-09 15:40:51 +01:00
parent 3427d36d0e
commit 879cac4b28
3 changed files with 7 additions and 51 deletions

View file

@ -271,7 +271,6 @@ pub struct Body {
pub exprs: Arena<Expr>, pub exprs: Arena<Expr>,
pub pats: Arena<Pat>, pub pats: Arena<Pat>,
pub bindings: Arena<Binding>, pub bindings: Arena<Binding>,
pub or_pats: FxHashMap<PatId, Arc<[PatId]>>,
pub labels: Arena<Label>, pub labels: Arena<Label>,
/// The patterns for the function's parameters. While the parameter types are /// The patterns for the function's parameters. While the parameter types are
/// part of the function signature, the patterns are not (they don't change /// part of the function signature, the patterns are not (they don't change
@ -410,18 +409,6 @@ impl Body {
.map(move |&block| (block, db.block_def_map(block).expect("block ID without DefMap"))) .map(move |&block| (block, db.block_def_map(block).expect("block ID without DefMap")))
} }
pub fn pattern_representative(&self, pat: PatId) -> PatId {
self.or_pats.get(&pat).and_then(|pats| pats.first().copied()).unwrap_or(pat)
}
/// Retrieves all ident patterns this pattern shares the ident with.
pub fn ident_patterns_for<'slf>(&'slf self, pat: &'slf PatId) -> &'slf [PatId] {
match self.or_pats.get(pat) {
Some(pats) => pats,
None => std::slice::from_ref(pat),
}
}
pub fn pretty_print(&self, db: &dyn DefDatabase, owner: DefWithBodyId) -> String { pub fn pretty_print(&self, db: &dyn DefDatabase, owner: DefWithBodyId) -> String {
pretty::print_body_hir(db, self, owner) pretty::print_body_hir(db, self, owner)
} }
@ -436,19 +423,9 @@ impl Body {
} }
fn shrink_to_fit(&mut self) { fn shrink_to_fit(&mut self) {
let Self { let Self { _c: _, body_expr: _, block_scopes, exprs, labels, params, pats, bindings } =
_c: _, self;
body_expr: _,
block_scopes,
or_pats,
exprs,
labels,
params,
pats,
bindings,
} = self;
block_scopes.shrink_to_fit(); block_scopes.shrink_to_fit();
or_pats.shrink_to_fit();
exprs.shrink_to_fit(); exprs.shrink_to_fit();
labels.shrink_to_fit(); labels.shrink_to_fit();
params.shrink_to_fit(); params.shrink_to_fit();
@ -464,7 +441,6 @@ impl Default for Body {
exprs: Default::default(), exprs: Default::default(),
pats: Default::default(), pats: Default::default(),
bindings: Default::default(), bindings: Default::default(),
or_pats: Default::default(),
labels: Default::default(), labels: Default::default(),
params: Default::default(), params: Default::default(),
block_scopes: Default::default(), block_scopes: Default::default(),

View file

@ -94,11 +94,8 @@ pub(super) fn lower(
body_expr: dummy_expr_id(), body_expr: dummy_expr_id(),
block_scopes: Vec::new(), block_scopes: Vec::new(),
_c: Count::new(), _c: Count::new(),
or_pats: Default::default(),
}, },
expander, expander,
name_to_pat_grouping: Default::default(),
is_lowering_inside_or_pat: false,
is_lowering_assignee_expr: false, is_lowering_assignee_expr: false,
is_lowering_generator: false, is_lowering_generator: false,
} }
@ -111,9 +108,6 @@ struct ExprCollector<'a> {
ast_id_map: Arc<AstIdMap>, ast_id_map: Arc<AstIdMap>,
body: Body, body: Body,
source_map: BodySourceMap, source_map: BodySourceMap,
// a poor-mans union-find?
name_to_pat_grouping: FxHashMap<Name, Vec<PatId>>,
is_lowering_inside_or_pat: bool,
is_lowering_assignee_expr: bool, is_lowering_assignee_expr: bool,
is_lowering_generator: bool, is_lowering_generator: bool,
} }
@ -824,13 +818,7 @@ impl ExprCollector<'_> {
} }
fn collect_pat(&mut self, pat: ast::Pat) -> PatId { fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
let pat_id = self.collect_pat_(pat, &mut BindingList::default()); self.collect_pat_(pat, &mut BindingList::default())
for (_, pats) in self.name_to_pat_grouping.drain() {
let pats = Arc::<[_]>::from(pats);
self.body.or_pats.extend(pats.iter().map(|&pat| (pat, pats.clone())));
}
self.is_lowering_inside_or_pat = false;
pat_id
} }
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId { fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
@ -845,13 +833,13 @@ impl ExprCollector<'_> {
ast::Pat::IdentPat(bp) => { ast::Pat::IdentPat(bp) => {
let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
let key = self.is_lowering_inside_or_pat.then(|| name.clone());
let annotation = let annotation =
BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some()); BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some());
let subpat = bp.pat().map(|subpat| self.collect_pat_(subpat, binding_list)); let subpat = bp.pat().map(|subpat| self.collect_pat_(subpat, binding_list));
let (binding, pattern) = if annotation == BindingAnnotation::Unannotated
&& subpat.is_none() let is_simple_ident_pat =
{ annotation == BindingAnnotation::Unannotated && subpat.is_none();
let (binding, pattern) = if is_simple_ident_pat {
// This could also be a single-segment path pattern. To // This could also be a single-segment path pattern. To
// decide that, we need to try resolving the name. // decide that, we need to try resolving the name.
let (resolved, _) = self.expander.def_map.resolve_path( let (resolved, _) = self.expander.def_map.resolve_path(
@ -892,9 +880,6 @@ impl ExprCollector<'_> {
if let Some(binding_id) = binding { if let Some(binding_id) = binding {
self.add_definition_to_binding(binding_id, pat); self.add_definition_to_binding(binding_id, pat);
} }
if let Some(key) = key {
self.name_to_pat_grouping.entry(key).or_default().push(pat);
}
return pat; return pat;
} }
ast::Pat::TupleStructPat(p) => { ast::Pat::TupleStructPat(p) => {
@ -914,7 +899,6 @@ impl ExprCollector<'_> {
path.map(Pat::Path).unwrap_or(Pat::Missing) path.map(Pat::Path).unwrap_or(Pat::Missing)
} }
ast::Pat::OrPat(p) => { ast::Pat::OrPat(p) => {
self.is_lowering_inside_or_pat = true;
let pats = p.pats().map(|p| self.collect_pat_(p, binding_list)).collect(); let pats = p.pats().map(|p| self.collect_pat_(p, binding_list)).collect();
Pat::Or(pats) Pat::Or(pats)
} }

View file

@ -2501,10 +2501,6 @@ impl GenericDef {
} }
/// A single local definition. /// A single local definition.
///
/// If the definition of this is part of a "MultiLocal", that is a local that has multiple declarations due to or-patterns
/// then this only references a single one of those.
/// To retrieve the other locals you should use [`Local::associated_locals`]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Local { pub struct Local {
pub(crate) parent: DefWithBodyId, pub(crate) parent: DefWithBodyId,