33 auto bb = app->as<
App>()->arg();
35 builder.add_pass<
EtaRed>(app, bb_only);
60 return f->isa_mut<
Lam>();
66 auto tpl = def->isa<
Tuple>();
74 if (!lambda_or_branch ||
fnc->isa<
Lam>())
return ClosLit(tpl, a);
82 auto& w = env->
world();
83 auto pi = lam->
type()->as<
Pi>();
86 return w.tuple(ct, {env->
type(), lam, env})->isa<Tuple>();
97 auto [ty, pi, env] = c->projs<3>();
102 auto& w = closure->
world();
104 auto pi = fn->type()->as<
Pi>();
105 return w.app(fn,
DefVec(pi->num_doms(), [&](
auto i) { return clos_insert_env(i, env, args); }));
113 auto& w = def->
world();
115 if (!sig || sig->num_ops() < 3 || sig->op(0_u64) != w.type())
return nullptr;
116 auto var = sig->
var(0_u64);
117 if (sig->op(2_u64) != var)
return nullptr;
118 auto pi = sig->
op(1_u64)->isa<
Pi>();
123 auto& w = pi->
world();
124 auto doms = pi->doms();
130 auto& w = ct->
world();
131 auto pi = ct->
op(1_u64)->as<
Pi>();
133 return w.cn(new_dom);
148 auto sigma = w.mut_sigma(w.type(), 3_u64)->set(
"Clos");
149 sigma->set(0_u64, w.type());
150 sigma->set(1_u64,
ctype(w, doms, sigma->var(0_u64)));
151 sigma->set(2_u64, sigma->var(0_u64));
155 DefVec(doms.size() + 1, [&](
auto i) { return clos_insert_env(i, env_type, [&](auto j) { return doms[j]; }); }));
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 *mut*able, 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).
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).
ClosLit isa_clos_lit(const Def *def, bool fn_isa_lam=true)
Tries to match a closure literal.
void register_normalizers(Normalizers &normalizers)
Sigma * clos_type(const Pi *pi)
Creates a typed closure type from pi.
size_t shift_env(size_t i)
const Def * clos_remove_env(size_t i, std::function< const Def *(size_t)> f)
const Def * clos_insert_env(size_t i, const Def *env, std::function< const Def *(size_t)> f)
const Def * ctype(World &w, Defs doms, const Def *env_type=nullptr)
static constexpr size_t Clos_Env_Param
Describes where the environment is placed in the argument list.
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).
const Def * clos_sub_env(const Def *tup_or_sig, const Def *new_env)
size_t skip_env(size_t i)
const Def * clos_pack(const Def *env, const Def *fn, const Def *ct=nullptr)
Pack a typed closure. This assumes that fn expects the environment as its Clos_Env_Paramth argument.
const Def * clos_apply(const Def *closure, const Def *args)
Apply a closure to arguments.
const Sigma * isa_clos_type(const Def *def)
Vector< const Def * > DefVec
absl::flat_hash_map< flags_t, std::function< void(World &, PipelineBuilder &, const Def *)> > Passes
axiom ↦ (pipeline part) × (axiom application) → () The function should inspect Application to const...
mim::Plugin mim_get_plugin()
void register_pass(Passes &passes, CArgs &&... args)
constexpr decltype(auto) get(Span< T, N > span) noexcept
void register_phase(Passes &passes, CArgs &&... args)
auto match(const Def *def)
absl::flat_hash_map< flags_t, NormalizeFn > Normalizers
static constexpr flags_t Base
Basic info and registration function pointer to be returned from a specific plugin.