13 if (
auto app = def->isa<
App>()) {
14 if (
auto lam = app->callee()->isa_mut<
Lam>()) {
15 world.DLOG(
"encountered lam app");
16 auto new_lam = rewrite_lam(lam);
17 world.DLOG(
"new lam: {} : {}", new_lam, new_lam->type());
18 world.DLOG(
"arg: {} : {}", app->arg(), app->arg()->type());
19 auto new_app =
world.
app(new_lam, app->arg());
20 world.DLOG(
"new app: {} : {}", new_app, new_app->type());
29Ref DS2CPS::rewrite_lam(
Lam* lam) {
30 if (
auto i = rewritten_.find(lam); i != rewritten_.end())
return i->second;
42 world().DLOG(
"rewrite DS function {} : {}", lam, lam->
type());
44 auto ty = lam->
type();
47 auto codom = ty->codom();
54 world().DLOG(
"original codom: {}", codom);
55 world().DLOG(
"rewritten codom: {}", rw_codom);
64 auto filter = new_ops[0];
65 auto cps_body = new_ops[1];
67 world().DLOG(
"cps body: {} : {}", cps_body, cps_body->type());
69 cps_lam->
app(filter, cps_lam->vars().back(), cps_body);
72 world().DLOG(
"replace {} : {}", lam, lam->
type());
73 world().DLOG(
"with {} : {}", rewritten_[lam], rewritten_[lam]->type());
75 return rewritten_[lam];
Def * set(size_t i, const Def *def)
Successively set from left to right.
const Var * has_var()
Only returns not nullptr, if Var of this mutable has ever been created.
Lam * set(Filter filter, const Def *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
const Def * op_cps2ds_dep(const Def *f)
DefVec rewrite(Def *mut, Ref arg)