34 explicit operator bool()
const {
return def_ !=
nullptr; }
35 operator const Tuple*()
const {
return def_; }
62std::tuple<const Def*, const Def*, const Def*>
clos_unpack(
const Def* c);
74 if (
auto proj = def->isa<
Extract>())
75 if (
auto var = proj->tuple()->isa<
Var>(); var && var->
binder()->isa<N>())
return {proj, var->binder()->as<N>()};
76 return {
nullptr,
nullptr};
82 return pi && pi->dom()->isa_binder<
Sigma>().second;
111inline size_t shift_env(
size_t ep,
size_t i) {
return (i < ep) ? i : i - 1_u64; }
114inline size_t skip_env(
size_t ep,
size_t i) {
return (i < ep) ? i : i + 1_u64; }
123 return clos_insert_env(ep, i, env, [&, n = a->num_projs()](
auto i) { return a->proj(n, i); });
127 auto& w = tup_or_sig->
world();
128 auto new_ops =
DefVec(tup_or_sig->
num_projs() + 1, [&](
auto i) { return clos_insert_env(ep, i, env, tup_or_sig); });
129 return (tup_or_sig->isa<
Sigma>()) ? w.sigma(new_ops) : w.tuple(new_ops);
137 auto& w = tup_or_sig->
world();
138 auto new_ops =
DefVec(tup_or_sig->
num_projs() - 1, [&](
auto i) { return clos_remove_env(ep, i, tup_or_sig); });
139 return (tup_or_sig->isa<
Sigma>()) ? w.sigma(new_ops) : w.tuple(new_ops);
143 auto& w = tup_or_sig->
world();
145 auto new_ops =
DefVec(n, [&](
auto i) {
return i == ep ? new_env : tup_or_sig->
proj(n, i); });
146 return (tup_or_sig->isa<
Sigma>()) ? w.sigma(new_ops) : w.tuple(new_ops);
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 * 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.
auto doms(Projector auto f) const noexcept
static const Pi * isa_cn(const Def *d)
static const Pi * isa_basicblock(const Def *d)
static const Pi * isa_returning(const Def *d)
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)
bool is_telescope_cn(const Def *def)
Inserting the environment would shift the indices a telescope's Var refers to, so ClosConv leaves suc...
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....
fe::View< const Def * > Defs
fe::Vector< const Def * > DefVec