9std::tuple<Vector<ClosLit>,
const Def*> isa_branch(
const Def* 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())) {
14 for (
auto op : inner_proj->tuple()->ops())
16 branches.emplace_back(c);
19 return {branches, inner_proj->index()};
31 if (
auto [branches, index] = isa_branch(app->
callee()); index) {
33 auto ep =
env_param(branches[0].fnc_type());
34 auto new_branches = w.tuple(
DefVec(branches.size(), [&](
size_t i) ->
const Def* {
36 if (auto it = branch2dropped_.find(c); it != branch2dropped_.end()) return it->second;
41 auto dropped_lam = w.mut_lam(rewrite(clos_type_to_pi(c.type()))->as<Pi>())->set(c.fnc_as_lam()->dbg());
42 branch2dropped_[c] = dropped_lam;
43 auto clam = rewrite(c.fnc_as_lam())->as_mut<Lam>();
44 dropped_lam->set(clam->reduce(clos_insert_env(ep, rewrite(c.env()), dropped_lam->var())));
50 return RWPhase::rewrite_imm_App(app);
const Pi * callee_type() const
const Def * callee() const
static const Pi * isa_cn(const Def *d)
Is this a continuation - i.e. is the Pi::codom mim::Bottom?
World & new_world()
Create new Defs into this.
bool is_bootstrapping() const
Returns whether we are currently bootstrapping (rewriting annexes).
virtual const Def * rewrite(const Def *)
const Def * rewrite_imm_App(const App *) final
#define DLOG(...)
Vaporizes to nothingness in Debug build.
ClosLit isa_clos_lit(const Def *def, bool fn_isa_lam=true)
Tries to match a closure literal.
const Def * clos_remove_env(size_t ep, size_t i, std::function< const Def *(size_t)> f)
const Sigma * isa_clos_type(const Def *def)
size_t env_param(Defs doms)
Describes where the environment is placed in the argument list: right after a leading mem....
Vector< const Def * > DefVec
Vector(I, I, A=A()) -> Vector< typename std::iterator_traits< I >::value_type, Default_Inlined_Size< typename std::iterator_traits< I >::value_type >, A >