9std::tuple<std::vector<ClosLit>, Ref> isa_branch(Ref callee) {
10 if (
auto closure_proj = callee->isa<Extract>()) {
11 auto inner_proj = closure_proj->tuple()->isa<
Extract>();
12 if (inner_proj && inner_proj->tuple()->isa<Tuple>() &&
isa_clos_type(inner_proj->type())) {
13 auto branches = std::vector<ClosLit>();
14 for (
auto op : inner_proj->tuple()->ops())
16 branches.push_back(std::move(c));
19 return {branches, inner_proj->index()};
29 auto app = def->isa<
App>();
30 if (!app || !
Pi::isa_cn(app->callee_type()))
return def;
32 if (
auto [branches,
index] = isa_branch(app->callee());
index) {
33 w.DLOG(
"FLATTEN BRANCH {}", app->callee());
34 auto new_branches = w.tuple(
DefVec(branches.size(), [&](
auto i) {
36 auto [entry, inserted] = branch2dropped_.emplace(c, nullptr);
37 auto& dropped_lam = entry->second;
38 if (inserted || !dropped_lam) {
39 auto clam = c.fnc_as_lam();
40 dropped_lam = clam->stub(clos_type_to_pi(c.type()));
41 auto new_vars = clos_insert_env(c.env(), dropped_lam->var());
42 dropped_lam->set(clam->reduce(new_vars));
static const Pi * isa_cn(Ref d)
Is this a continuation - i.e. is the Pi::codom mim::Bottom?
Helper class to retrieve Infer::arg if present.
Ref rewrite(Ref) override
ClosLit isa_clos_lit(Ref def, bool fn_isa_lam=true)
Tries to match a closure literal.
Ref clos_remove_env(size_t i, std::function< Ref(size_t)> f)
const Sigma * isa_clos_type(Ref def)
Vector< const Def * > DefVec