33 explicit operator bool()
const {
return def_ !=
nullptr; }
34 operator const Tuple*()
const {
return def_; }
61std::tuple<const Def*, const Def*, const Def*>
clos_unpack(
const Def* c);
73 if (
auto proj = def->isa<
Extract>())
74 if (
auto var = proj->tuple()->isa<
Var>(); var && var->
binder()->isa<N>())
return {proj, var->binder()->as<N>()};
75 return {
nullptr,
nullptr};
104inline size_t shift_env(
size_t ep,
size_t i) {
return (i < ep) ? i : i - 1_u64; }
107inline size_t skip_env(
size_t ep,
size_t i) {
return (i < ep) ? i : i + 1_u64; }
116 return clos_insert_env(ep, i, env, [&](
auto i) {
return a->proj(i); });
120 auto& w = tup_or_sig->
world();
121 auto new_ops =
DefVec(tup_or_sig->
num_projs() + 1, [&](
auto i) { return clos_insert_env(ep, i, env, tup_or_sig); });
122 return (tup_or_sig->isa<
Sigma>()) ? w.sigma(new_ops) : w.tuple(new_ops);
130 auto& w = tup_or_sig->
world();
131 auto new_ops =
DefVec(tup_or_sig->
num_projs() - 1, [&](
auto i) { return clos_remove_env(ep, i, tup_or_sig); });
132 return (tup_or_sig->isa<
Sigma>()) ? w.sigma(new_ops) : w.tuple(new_ops);
136 return tup_or_sig->
refine(ep, new_env);
static auto isa(const Def *def)
const Def * proj(nat_t a, nat_t i) const
Similar to World::extract while assuming an arity of a, but also works on Sigmas and Arrays.
World & world() const noexcept
const Def * refine(size_t i, const Def *new_op) const
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
nat_t num_projs() const
Yields Def::arity(), if it is a Lit, or 1 otherwise.
const Def * ret_var()
Yields the Lam::var of the Lam::ret_pi.
A dependent function type.
static const Pi * isa_basicblock(const Def *d)
Is this a continuation (Pi::isa_cn) that is not Pi::isa_returning?
static const Pi * isa_returning(const Def *d)
Is this a continuation (Pi::isa_cn) which has a Pi::ret_pi?
Data constructor for a Sigma.
A variable introduced by a binder (mutable).
Def * binder() const
The binder of this Var.
The World represents the whole program and manages creation of MimIR nodes (Defs).
const Def * tuple(Defs ops)
Lightweight, non-owning view onto a closure literal (env_type, fn, env); see isa_clos_lit.
const Sigma * type() const
const Def * ret_var() const
const Def * env_type() const
const Pi * fnc_type() const
const Tuple * operator->() const
bool is_basicblock() const
const Def * env_var() const
bool is_returning() const
friend ClosLit isa_clos_lit(const Def *, bool)
Tries to match a closure literal.
ClosLit isa_clos_lit(const Def *def, bool fn_isa_lam=true)
Tries to match a closure literal.
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...
const Def * apply_closure(const Def *closure, Defs args)
std::tuple< const Def *, const Def *, const Def * > clos_unpack(const Def *c)
Deconstruct a closure into (env_type, function, env).
std::tuple< const Extract *, N * > isa_var_proj(const Def *def)
If def is a projection var#i of the Var of some mutable of type N, returns (projection,...
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