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());
28Ref 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, Ref)
Successively set from left to right.
DefVec reduce(Ref arg) const
Rewrites Def::ops by substituting this mutable's Var with arg.
const Var * has_var()
Only returns not nullptr, if Var of this mutable has ever been created.
Lam * set(Filter filter, Ref body)
static const Lam * isa_cn(Ref d)
A dependent function type.
Helper class to retrieve Infer::arg if present.
Sigma * mut_sigma(Ref type, size_t size)
Ref app(Ref callee, Ref arg)
Ref rewrite(Ref) override