5using namespace std::literals;
15 if (
auto old =
lookup(new2old_, new_lam)) {
17 assert(root != new_lam);
18 new2old_[new_lam] = root;
26 if (std::ranges::none_of(def->
ops(), [](
const Def* def) { return def->isa<Lam>(); }))
return def;
29 auto [i, ins] = def2new_ops_.emplace(def,
DefVec{});
30 auto& new_ops = i->second;
31 if (ins) new_ops.assign(def->
ops().begin(), def->
ops().end());
33 for (
size_t i = 0, e = def->
num_ops(); i != e; ++i) {
36 if (
auto orig =
lookup(exp2orig_, lam)) new_ops[i] = orig;
37 }
else if (expand_.contains(lam)) {
38 if (new_ops[i] == lam) new_ops[i] = eta_exp(lam);
39 }
else if (
auto orig =
lookup(exp2orig_, lam)) {
40 if (new_ops[i] == lam) new_ops[i] = eta_exp(orig);
46 return old2new()[new_def] = new_def;
49Lam* EtaExp::eta_exp(
Lam* lam) {
51 exp2orig_.emplace(exp, lam);
52 exp->debug_suffix(
"eta_"s + lam->
sym().str());
53 exp->app(
false, lam, exp->var());
60 auto lam =
proxy->op(0)->as_mut<
Lam>();
61 if (expand_.emplace(lam).second)
return undo_visit(lam);
67 for (
size_t i = 0, e = def->
num_ops(); i != e; ++i) {
70 if (expand_.contains(lam) || exp2orig_.contains(lam))
continue;
74 DLOG(
"Callee: Callee -> Expand: '{}'", lam);
78 DLOG(
"Callee: Bot/Callee -> Callee: '{}'", lam);
84 DLOG(
"Non_Callee: Bot -> Non_Callee_1: '{}'", lam);
86 DLOG(
"Non_Callee: {} -> Expand: '{}'",
pos2str(it->second), lam);
bool is_set() const
Yields true if empty or the last op is set.
constexpr auto ops() const noexcept
T * isa_mut() const
If this is mutable, it will cast constness away and perform a dynamic_cast to T.
const Def * op(size_t i) const noexcept
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
const Def * rebuild(World &w, const Def *type, Defs ops) const
Def::rebuilds this Def while using new_op as substitute for its i'th Def::op.
constexpr size_t num_ops() const noexcept
void new2old(Lam *new_lam, Lam *old_lam)
undo_t analyze(const Proxy *) override
void init(PassMan *) final
const Def * rewrite(const Def *) 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
Lam * stub(const Def *type)
An optimizer that combines several optimizations in an optimal way.
virtual void init(PassMan *)
#define DLOG(...)
Vaporizes to nothingness in Debug build.
Vector< const Def * > DefVec
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