7 visit(def, Lattice::Known);
12 if (
auto [_, ins] = analyzed_.emplace(def); !ins)
return;
14 if (
auto app = def->isa<
App>()) {
15 visit(app->type(), Lattice::Unknown_1);
16 visit(app->callee(), Lattice::Known);
17 visit(app->arg(), Lattice::Unknown_1);
19 for (
auto d : def->
deps())
20 visit(d, Lattice::Unknown_1);
24void EtaConv::visit(
const Def* def, Lattice l) {
25 if (
auto lam = def->isa_mut<
Lam>()) {
28 if (
auto f = lam->eta_reduce())
return visit(f, l);
39 auto new_mut = rewrite_no_eta(old_mut)->
as_mut();
44 if (
auto lam = old_def->isa<
Lam>()) {
45 if (
auto f = lam->eta_reduce()) {
47 if (!keep_wrapper(f)) {
49 DLOG(
"eta-reduce: `{}` → `{}`", lam, f);
56 }
else if (eta_expand(lam)) {
60 DLOG(
"eta-expand: `{}` → `{}`", lam, eta);
69const Def* EtaConv::rewrite_no_exp(
const Def* old_def) {
70 if (
auto lam = old_def->isa<
Lam>())
71 if (
auto f = lam->eta_reduce(); f && !keep_wrapper(f)) {
72 DLOG(
"eta-reduce: `{}` → `{}`", lam, f);
74 return rewrite_no_exp(f);
80 auto callee = rewrite_no_exp(app->
callee());
const Def * callee() const
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
Defs deps() const noexcept
bool is_external() const noexcept
const Def * rewrite_imm_Var(const Var *) final
const Def * rewrite(const Def *) final
void rewrite_annex(flags_t, Sym, const Def *) final
void rewrite_external(Def *) final
const Def * rewrite_imm_App(const App *) final
bool analyze() final
Runs the optional pre-analysis on RWPhase::old_world(), typically to a fixed point,...
static Lam * eta_expand(Filter, const Def *f)
void invalidate(bool todo=true)
Signals that another round of fixed-point iteration is required, either as part of.
void profile_count(std::string_view key, uint64_t n=1)
Adds n to the custom Profiler counter key of the current run; no-op unless profiling is enabled.
World & new_world()
Create new Defs into this.
World & old_world()
Get old Defs from here.
virtual const Def * rewrite(const Def *)
A variable introduced by a binder (mutable).
Def * binder() const
The binder of this Var.
const Def * attach(flags_t, Sym, const Def *)
const Def * app(const Def *callee, const Def *arg)
const Def * var(Def *mut)
#define DLOG(...)
Vaporizes to nothingness in Debug build.