33 explicit operator bool()
const {
return def_ !=
nullptr; }
34 operator const Tuple*() {
return def_; }
73 auto& w = closure->
world();
80 if (
auto proj = def->isa<
Extract>()) {
81 if (
auto var = proj->tuple()->isa<
Var>(); var && var->
mut()->isa<N>())
82 return std::tuple(proj, var->mut()->as<N>());
84 return {
nullptr,
nullptr};
124 auto& w = tup_or_sig->
world();
125 auto new_ops =
DefVec(tup_or_sig->
num_projs() + 1, [&](
auto i) { return clos_insert_env(i, env, tup_or_sig); });
126 return (tup_or_sig->isa<
Sigma>()) ? w.sigma(new_ops) : w.tuple(new_ops);
134 auto& w = tup_or_sig->
world();
135 auto new_ops =
DefVec(tup_or_sig->
num_projs() - 1, [&](
auto i) { return clos_remove_env(i, tup_or_sig); });
136 return (tup_or_sig->isa<
Sigma>()) ? w.sigma(new_ops) : w.tuple(new_ops);
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.
const Def * refine(size_t i, const Def *new_op) const
Ref ret_var()
Yields the Lam::var of the Lam::ret_pi.
A dependent function type.
static const Pi * isa_returning(Ref d)
Is this a continuation (Pi::isa_cn) which has a Pi::ret_pi?
static const Pi * isa_basicblock(Ref d)
Is this a continuation (Pi::isa_cn) that is not Pi::isa_returning?
Helper class to retrieve Infer::arg if present.
This is a thin wrapper for std::span<T, N> with the following additional features:
Data constructor for a Sigma.
The World represents the whole program and manages creation of MimIR nodes (Defs).
Wrapper around a Def that can be used to match closures (see isa_clos_lit).
friend ClosLit isa_clos_lit(Ref, bool)
Tries to match a closure literal.
const Tuple * operator->()
attr get()
Clos annotation. These should appear in front of the code-part.
ClosLit isa_clos_lit(Ref def, bool fn_isa_lam=true)
Tries to match a closure literal.
Ref clos_sub_env(Ref tup_or_sig, Ref new_env)
Sigma * clos_type(const Pi *pi)
Creates a typed closure type from pi.
std::tuple< Ref, Ref, Ref > clos_unpack(Ref c)
Deconstruct a closure into (env_type, function, env).
const Pi * clos_type_to_pi(Ref ct, Ref new_env_type=nullptr)
Convert a closure type to a Pi, where the environment type has been removed or replaced by new_env_ty...
Ref clos_apply(Ref closure, Ref args)
Apply a closure to arguments.
size_t shift_env(size_t i)
Ref clos_remove_env(size_t i, std::function< Ref(size_t)> f)
static constexpr size_t Clos_Env_Param
Describes where the environment is placed in the argument list.
const Sigma * isa_clos_type(Ref def)
Ref apply_closure(Ref closure, Defs args)
std::tuple< const Extract *, N * > ca_isa_var(Ref def)
Checks is def is the variable of a mut of type N.
Ref ctype(World &w, Defs doms, Ref env_type=nullptr)
size_t skip_env(size_t i)
Ref clos_pack(Ref env, Ref fn, Ref ct=nullptr)
Pack a typed closure. This assumes that fn expects the environment as its Clos_Env_Paramth argument.
Ref clos_insert_env(size_t i, Ref env, std::function< Ref(size_t)> f)
Vector< const Def * > DefVec