67 for (
const auto& scope :
scopes_ | std::views::reverse)
68 if (
auto new_def = fe::lookup(scope.old2new, old_def))
return new_def;
86#define CODE_IMM(N) virtual const Def* rewrite_imm_##N(const N*);
87#define CODE_MUT(N) virtual const Def* rewrite_mut_##N(N*);
97 template<
class D = Def>
99 return curr_mut_ ? curr_mut_->template isa<D>() :
nullptr;
109 for (
const auto& scope :
scopes_ | std::views::reverse)
115 [[nodiscard]]
auto enter(
Def* new_mut) {
return fe::Restore(curr_mut_, new_mut); }
131 Def* curr_mut_ =
nullptr;
135 swap(rw1.scopes_, rw2.scopes_);
bool has_free_vars_in(Vars) const
Same as vars.has_intersection(free_vars()).
const Def * rewrite(const Def *) final
friend void swap(Importer &i1, Importer &i2) noexcept
fe::Vector< Scope > scopes_
friend void swap(Rewriter &rw1, Rewriter &rw2) noexcept
bool has_intersection(const Def *old_def)
Does old_def depend on the old Vars of any scope?
void bind_old(const Var *var)
Adds the old var - if any - to the innermost scope.
virtual const Def * rewrite_imm_Seq(const Seq *seq)
virtual const Def * rewrite_mut_Seq(Seq *seq)
Vars old_vars
Only mappings depending on these go here; the root's are VarRewriter's substitutions.
virtual const Def * rewrite_mut(Def *)
void bind(const Var *old_var, const Var *new_var)
virtual const Def * rewrite_stub(Def *, Def *)
const Def * map(const Def *old_def, const Def *new_def)
void bind_new(const Var *var)
Adds the new var - if any - to the innermost scope.
const Def * seal(Def *old_mut, Def *new_mut)
The tail of rewrite_stub: immutabilizes new_mut in hindsight, as rewriting may have made it vacuous.
virtual const Def * rewrite_imm(const Def *)
virtual const Def * rewrite(const Def *)
auto enter(Def *new_mut)
Updates curr_mut() to new_mut and restores it at the end of the scope.
void push(Vars old_vars={}, Vars new_vars={})
Def2Def & old2new()
The map of the innermost push() scope.
virtual const Def * lookup(const Def *old_def)
Lookup old_def by searching in reverse through the stack of maps.
Base class for Arr and Pack.
VarRewriter & add(const Var *var, const Def *arg)
Substitutes arg for var.
const Def * rewrite_mut(Def *) final
VarRewriter(World &world)
friend void swap(VarRewriter &vrw1, VarRewriter &vrw2) noexcept
const Def * rewrite(const Def *) final
VarRewriter(const Var *var, const Def *arg)
A variable introduced by a binder (mutable).
The World represents the whole program and manages creation of MimIR nodes (Defs).
const Def * rewire_mut(Def *)
friend void swap(Zonker &z1, Zonker &z2) noexcept
const Def * lookup(const Def *old_def) final
Lookup old_def by searching in reverse through the stack of maps.
const Def * rewrite(const Def *) final
const Def * rewrite_mut(Def *mut) final
DefMap< const Def * > Def2Def
fe::View< const Def * > Defs
fe::Vector< const Def * > DefVec
fe::Patricia< const Var, DefKey >::Set Vars