Skip to content

Commit 02fbfbf

Browse files
committed
Add a path-compressing Env::lit_repr
This makes a commonly needed operation less verbose and more efficient.
1 parent fbd16f8 commit 02fbfbf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ir/src/env.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ impl Env {
382382
let Some(VarDef::Node(node_id)) = self.var_defs().var_def(var) else { return None };
383383
Some((node_id, self.nodes().get_dyn(node_id).unwrap()))
384384
}
385+
386+
/// Returns the canonical representative literal equivalent to the given literal.
387+
///
388+
/// This will perform path compression on the internal union-find data structure used to keep
389+
/// track of equivalent literals. To look up a canonical representative with a read-only
390+
/// environment reference (and thus without performing path-compression) [`VarDefs::lit_repr`]
391+
/// can be used via [`var_defs`][`Self::var_defs`].
392+
pub fn lit_repr(&mut self, lit: Lit) -> Lit {
393+
self.var_defs.update_lit_repr(lit)
394+
}
385395
}
386396

387397
mod node_builders;

0 commit comments

Comments
 (0)