12 if (
auto app = def->isa<
App>()) {
13 if (
auto lam = app->callee()->isa_mut<
Lam>()) {
14 world().DLOG(
"encountered lam app");
15 auto new_lam = rewrite_lam(lam);
16 world().DLOG(
"new lam: {} : {}", new_lam, new_lam->type());
17 world().DLOG(
"arg: {} : {}", app->arg(), app->arg()->type());
18 auto new_app =
world().
app(new_lam, app->arg());
19 world().DLOG(
"new app: {} : {}", new_app, new_app->type());
28const Def* DS2CPS::rewrite_lam(
Lam* lam) {
29 if (
auto i = rewritten_.find(lam); i != rewritten_.end())
return i->second;
41 world().DLOG(
"rewrite DS function {} : {}", lam, lam->
type());
43 auto ty = lam->
type();
46 auto codom = ty->codom();
53 world().DLOG(
"original codom: {}", codom);
54 world().DLOG(
"rewritten codom: {}", rw_codom);
62 auto new_ops = lam->
reduce(cps_lam->var(0_n));
63 auto filter = new_ops[0];
64 auto cps_body = new_ops[1];
66 world().DLOG(
"cps body: {} : {}", cps_body, cps_body->type());
68 cps_lam->
app(filter, cps_lam->vars().back(), cps_body);
71 world().DLOG(
"replace {} : {}", lam, lam->
type());
72 world().DLOG(
"with {} : {}", rewritten_[lam], rewritten_[lam]->type());
74 return rewritten_[lam];
Def * set(size_t i, const Def *)
Successively set from left to right.
DefVec reduce(const Def *arg) const
Rewrites Def::ops by substituting this mutable's Var with arg.
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
const Var * has_var()
Only returns not nullptr, if Var of this mutable has ever been created.
static const Lam * isa_cn(const Def *d)
Lam * set(Filter filter, const Def *body)
A dependent function type.
const Def * codom() const
virtual const Def * rewrite(const Def *)
const Def * app(const Def *callee, const Def *arg)
Lam * mut_con(const Def *dom)
Sigma * mut_sigma(const Def *type, size_t size)
const Def * rewrite(const Def *) override
const Def * op_cps2ds_dep(const Def *k)