42 return f->isa_mut<
Lam>();
54 if (!fn_isa_lam ||
fnc->isa<
Lam>())
return ClosLit(tpl);
56 return ClosLit(
nullptr);
62 auto& w = env->
world();
63 auto pi = fn->
type()->as<
Pi>();
65 assert(env->
type() == pi->dom(ep));
67 return w.tuple(ct, {env->
type(), fn, env})->as<Tuple>();
72 auto [env_type, fn, env] = c->projs<3>();
73 return {env_type, fn, env};
77 auto& w = closure->
world();
79 auto pi = fn->type()->as<
Pi>();
81 return w.app(fn,
DefVec(pi->num_doms(), [&](
auto i) { return clos_insert_env(ep, i, env, args); }));
89 auto& w = def->
world();
91 if (!sig || sig->num_ops() < 3 || sig->op(0_u64) != w.type())
return nullptr;
92 auto var = sig->
var(0_u64);
93 if (sig->op(2_u64) != var)
return nullptr;
94 auto pi = sig->
op(1_u64)->isa<
Pi>();
95 if (!pi || !
Pi::isa_cn(pi) || pi->num_ops() <= 1_u64)
return nullptr;
96 return (pi->dom(
env_param(pi)) == var) ? sig :
nullptr;
100 auto& w = pi->
world();
101 auto doms = pi->doms();
107 auto& w = ct->
world();
108 auto pi = ct->
op(1_u64)->as<
Pi>();
111 return w.cn(new_dom);
119 return (i == ep) ? env : f(
shift_env(ep, i));
127 auto sigma = w.mut_sigma(w.type(), 3_u64)->set(
"Clos");
128 sigma->set(0_u64, w.type());
129 sigma->set(1_u64,
ctype(w, doms, sigma->var(0_u64)));
130 sigma->set(2_u64, sigma->var(0_u64));
133 return w.cn(
DefVec(doms.size() + 1,
134 [&](
auto i) { return clos_insert_env(ep, i, env_type, [&](auto j) { return doms[j]; }); }));
void reg_phases(Flags2Phases &phases)
static auto isa(const Def *def)
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
World & world() const noexcept
T * isa_mut() const
If this is mutable, it will cast constness away and perform a dynamic_cast to T.
const Def * op(size_t i) const noexcept
const Def * var(nat_t a, nat_t i) noexcept
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
static void hook(Flags2Phases &phases)
A dependent function type.
static const Pi * isa_cn(const Def *d)
Is this a continuation - i.e. is the Pi::codom mim::Bottom?
Data constructor for a Sigma.
The World represents the whole program and manages creation of MimIR nodes (Defs).
const Def * env_var() const
void reg_phases(Flags2Phases &phases)
ClosLit isa_clos_lit(const Def *def, bool fn_isa_lam=true)
Tries to match a closure literal.
void register_normalizers(Normalizers &normalizers)
const Def * clos_sub_env(size_t ep, const Def *tup_or_sig, const Def *new_env)
const Def * clos_remove_env(size_t ep, size_t i, std::function< const Def *(size_t)> f)
Sigma * clos_type(const Pi *pi)
Creates a typed closure type from pi.
size_t shift_env(size_t ep, size_t i)
Adjust the index of an argument to account for the env param.
const Def * ctype(World &w, Defs doms, const Def *env_type=nullptr)
Builds a closure type from the domains doms of a Cn.
const Def * clos_insert_env(size_t ep, size_t i, const Def *env, std::function< const Def *(size_t)> f)
const Pi * clos_type_to_pi(const Def *ct, const Def *new_env_type=nullptr)
Convert a closure type to a Pi, where the environment type has been removed or replaced by new_env_ty...
std::tuple< const Def *, const Def *, const Def * > clos_unpack(const Def *c)
Deconstruct a closure into (env_type, function, env).
size_t skip_env(size_t ep, size_t i)
Same as shift_env, but skips the env param instead.
const Def * clos_pack(const Def *env, const Def *fn, const Def *ct=nullptr)
Pack a typed closure.
const Def * clos_apply(const Def *closure, const Def *args)
Apply a closure to arguments.
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
absl::flat_hash_map< flags_t, std::function< std::unique_ptr< Phase >(World &)> > Flags2Phases
Maps an axiom of a Phase to a function that creates one.
mim::Plugin mim_get_plugin()
Basic info and registration function pointer to be returned from a specific plugin.