5using namespace std::literals;
10 if (
auto old =
lookup(new2old_, new_lam)) {
12 assert(root != new_lam);
13 new2old_[new_lam] = root;
21 if (std::ranges::none_of(def->
ops(), [](
Ref def) { return def->isa<Lam>(); }))
return def;
24 auto [i, ins] = def2new_ops_.emplace(def,
DefVec{});
25 auto& new_ops = i->second;
26 if (ins) new_ops.assign(def->
ops().begin(), def->
ops().end());
28 for (
size_t i = 0, e = def->
num_ops(); i != e; ++i) {
31 if (
auto orig =
lookup(exp2orig_, lam)) new_ops[i] = orig;
32 }
else if (expand_.contains(lam)) {
33 if (new_ops[i] == lam) new_ops[i] = eta_exp(lam);
34 }
else if (
auto orig =
lookup(exp2orig_, lam)) {
35 if (new_ops[i] == lam) new_ops[i] = eta_exp(orig);
41 return old2new()[new_def] = new_def;
44Lam* EtaExp::eta_exp(
Lam* lam) {
46 exp2orig_.emplace(exp, lam);
47 exp->debug_suffix(
"eta_"s + lam->
sym().str());
48 exp->app(
false, lam, exp->var());
56 if (expand_.emplace(lam).second)
return undo_visit(lam);
62 for (
size_t i = 0, e = def->
num_ops(); i != e; ++i) {
65 if (expand_.contains(lam) || exp2orig_.contains(lam))
continue;
69 world().DLOG(
"Callee: Callee -> Expand: '{}'", lam);
73 world().DLOG(
"Callee: Bot/Callee -> Callee: '{}'", lam);
79 world().DLOG(
"Non_Callee: Bot -> Non_Callee_1: '{}'", lam);
81 world().DLOG(
"Non_Callee: {} -> Expand: '{}'",
pos2str(it->second), lam);
bool is_set() const
Yields true if empty or the last op is set.
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
const Def * op(size_t i) const
T * isa_mut() const
If this is *mut*able, it will cast constness away and perform a dynamic_cast to T.
Ref rebuild(World &w, Ref type, Defs ops) const
Def::rebuilds this Def while using new_op as substitute for its i'th Def::op.
Ref rewrite(Ref) override
void new2old(Lam *new_lam, Lam *old_lam)
undo_t analyze(const Proxy *) override
static std::string_view pos2str(Pos pos)
const Proxy * proxy(Lam *lam)
void mark_irreducible(Lam *lam)
undo_t undo_visit(Def *mut) const
Helper class to retrieve Infer::arg if present.
auto lookup(const C &container, const K &key)
Yields pointer to element (or the element itself if it is already a pointer), if found and nullptr ot...
const App * isa_callee(const Def *def, size_t i)
static constexpr undo_t No_Undo