MimIR 0.1
MimIR is my Intermediate Representation
|
A dependent function type. More...
#include <mim/lam.h>
Public Member Functions | |
Get/Set implicit | |
bool | is_implicit () const |
Pi * | make_implicit () |
Pi * | make_explicit () |
dom & codom | |
| |
const Def * | dom () const |
const Def * | codom () const |
Return Continuation | |
const Pi * | ret_pi () const |
Yields the last Pi::dom, if Pi::isa_basicblock. | |
const Def * | ret_dom () const |
Pi::domain of Pi::ret_pi. | |
Setters | |
| |
Pi * | set (const Def *dom, const Def *codom) |
Pi * | set_dom (const Def *dom) |
Pi * | set_dom (Defs doms) |
Pi * | set_codom (const Def *codom) |
Pi * | unset () |
Rebuild | |
const Def * | reduce (const Def *arg) const |
Pi * | stub (const Def *type) |
const Pi * | immutabilize () override |
Tries to make an immutable from a mutable. | |
![]() | |
World & | world () const noexcept |
constexpr flags_t | flags () const noexcept |
constexpr u32 | gid () const noexcept |
Global id - unique number for this Def. | |
constexpr u32 | tid () const noexcept |
Trie id - only used in Trie. | |
constexpr u32 | mark () const noexcept |
Used internally by free_vars(). | |
constexpr size_t | hash () const noexcept |
constexpr Node | node () const noexcept |
std::string_view | node_name () const |
u32 | judge () const noexcept |
bool | is_form () const noexcept |
bool | is_intro () const noexcept |
bool | is_elim () const noexcept |
bool | is_meta () const noexcept |
const Def * | type () const noexcept |
Yields the "raw" type of this Def (maybe nullptr ). | |
const Def * | unfold_type () const |
Yields the type of this Def and builds a new Type (UInc n) if necessary. | |
bool | is_term () const |
const Def * | arity () const |
std::optional< nat_t > | isa_lit_arity () const |
nat_t | as_lit_arity () const |
template<size_t N = std::dynamic_extent> | |
constexpr auto | ops () const noexcept |
const Def * | op (size_t i) const noexcept |
constexpr size_t | num_ops () const noexcept |
Def * | set (size_t i, const Def *) |
Successively set from left to right. | |
Def * | reset (size_t i, const Def *def) |
Successively reset from left to right. | |
Def * | set (Defs ops) |
Def::set ops all at once. | |
Def * | reset (Defs ops) |
Def::reset ops all at once. | |
Def * | unset () |
Unsets all Def::ops; works even, if not set at all or partially. | |
bool | is_set () const |
Yields true if empty or the last op is set. | |
Defs | deps () const noexcept |
const Def * | dep (size_t i) const noexcept |
size_t | num_deps () const noexcept |
bool | has_dep () const |
bool | has_dep (Dep d) const |
bool | has_dep (unsigned u) const |
nat_t | num_projs () const |
Yields Def::as_lit_arity(), if it is in fact a Lit, or 1 otherwise. | |
nat_t | num_tprojs () const |
As above but yields 1, if Flags::scalarize_threshold is exceeded. | |
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 * | proj (nat_t i) const |
As above but takes Def::num_projs as arity. | |
const Def * | tproj (nat_t i) const |
As above but takes Def::num_tprojs. | |
template<nat_t A = std::dynamic_extent, class F> | |
auto | projs (F f) const |
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent ) or std::array (otherwise). | |
template<class F> | |
auto | tprojs (F f) const |
template<class F> | |
auto | projs (nat_t a, F f) const |
template<nat_t A = std::dynamic_extent> | |
auto | projs () const |
auto | tprojs () const |
auto | projs (nat_t a) const |
nat_t | num_vars () noexcept |
nat_t | num_tvars () noexcept |
const Def * | var (nat_t a, nat_t i) noexcept |
const Def * | var (nat_t i) noexcept |
const Def * | tvar (nat_t i) noexcept |
template<nat_t A = std::dynamic_extent, class F> | |
auto | vars (F f) noexcept |
template<class F> | |
auto | tvars (F f) noexcept |
template<nat_t A = std::dynamic_extent> | |
auto | vars () noexcept |
auto | tvars () noexcept |
template<class F> | |
auto | vars (nat_t a, F f) noexcept |
auto | vars (nat_t a) noexcept |
const Def * | var () |
Not necessarily a Var: E.g., if the return type is [] , this will yield () . | |
const Var * | has_var () |
Only returns not nullptr , if Var of this mutable has ever been created. | |
const Var * | has_var () const |
As above if this is a mutable. | |
Muts | local_muts () const |
Mutables reachable by following immutable deps(); mut->local_muts() is by definition the set { mut } . | |
Vars | local_vars () const |
Vars reachable by following immutable deps(). | |
Vars | free_vars () const |
Compute a global solution by transitively following mutables as well. | |
Vars | free_vars () |
Muts | users () |
Set of mutables where this mutable is locally referenced. | |
bool | is_open () const |
Has free_vars()? | |
bool | is_closed () const |
Has no free_vars()? | |
bool | is_external () const |
void | make_external () |
void | make_internal () |
void | transfer_external (Def *to) |
template<class T = Def> | |
const T * | isa_imm () const |
template<class T = Def> | |
const T * | as_imm () const |
template<class T = Def, class R> | |
const T * | isa_imm (R(T::*f)() const) const |
template<class T = Def, bool invert = false> | |
T * | isa_mut () const |
If this is *mut*able, it will cast const ness away and perform a dynamic_cast to T . | |
template<class T = Def, bool invert = false> | |
T * | as_mut () const |
Asserts that this is a mutable, casts const ness away and performs a static_cast to T . | |
Dbg | dbg () const |
Loc | loc () const |
Sym | sym () const |
std::string | unique_name () const |
name + "_" + Def::gid | |
template<bool Ow = false> | |
const Def * | set (Loc l) const |
template<bool Ow = false> | |
Def * | set (Loc l) |
template<bool Ow = false> | |
const Def * | set (Sym s) const |
template<bool Ow = false> | |
Def * | set (Sym s) |
template<bool Ow = false> | |
const Def * | set (std::string s) const |
template<bool Ow = false> | |
Def * | set (std::string s) |
template<bool Ow = false> | |
const Def * | set (Loc l, Sym s) const |
template<bool Ow = false> | |
Def * | set (Loc l, Sym s) |
template<bool Ow = false> | |
const Def * | set (Loc l, std::string s) const |
template<bool Ow = false> | |
Def * | set (Loc l, std::string s) |
template<bool Ow = false> | |
const Def * | set (Dbg d) const |
template<bool Ow = false> | |
Def * | set (Dbg d) |
const Def * | debug_prefix (std::string) const |
const Def * | debug_suffix (std::string) const |
Def * | stub (World &w, const Def *type) |
Def * | stub (const Def *type) |
const Def * | rebuild (World &w, const Def *type, Defs ops) const |
Def::rebuilds this Def while using new_op as substitute for its i'th Def::op. | |
const Def * | rebuild (const Def *type, Defs ops) const |
bool | is_immutabilizable () |
const Def * | refine (size_t i, const Def *new_op) const |
DefVec | reduce (const Def *arg) const |
Rewrites Def::ops by substituting this mutable's Var with arg . | |
DefVec | reduce (const Def *arg) |
const Def * | reduce (size_t i, const Def *arg) const |
As above but only rewrites this->op(i) . | |
const Def * | zonk () const |
void | dump () const |
void | dump (int max) const |
void | write (int max) const |
void | write (int max, const char *file) const |
std::ostream & | stream (std::ostream &, int max) const |
void | dot (std::ostream &os, uint32_t max=0xFFFFFF, bool types=false) const |
void | dot (const char *file=nullptr, uint32_t max=0xFFFFFF, bool types=false) const |
Same as above but write to file or std::cout if file is nullptr . | |
void | dot (const std::string &file, uint32_t max=0xFFFFFF, bool types=false) const |
![]() | |
const Pi * | set (Loc l) const |
Pi * | set (Loc l) |
const Pi * | set (Sym s) const |
Pi * | set (Sym s) |
const Pi * | set (std::string s) const |
Pi * | set (std::string s) |
const Pi * | set (Loc l, Sym s) const |
Pi * | set (Loc l, Sym s) |
const Pi * | set (Loc l, std::string s) const |
Pi * | set (Loc l, std::string s) |
const Pi * | set (Dbg d) const |
Pi * | set (Dbg d) |
Static Public Member Functions | |
Continuations | |
static const Pi * | isa_cn (const Def *d) |
Is this a continuation - i.e. is the Pi::codom mim::Bottom? | |
static const Pi * | isa_returning (const Def *d) |
Is this a continuation (Pi::isa_cn) which has a Pi::ret_pi? | |
static const Pi * | isa_basicblock (const Def *d) |
Is this a continuation (Pi::isa_cn) that is not Pi::isa_returning? | |
static Pi * | isa_implicit (const Def *d) |
Is d an Pi::is_implicit (mutable) Pi? | |
static const Pi * | has_ret_pi (const Def *d) |
Yields the Pi::ret_pi() of d , if it is in fact a Pi. | |
Static Public Attributes | |
static constexpr auto | Node = mim::Node::Pi |
Protected Member Functions | |
Pi (const Def *type, const Def *dom, const Def *codom, bool implicit) | |
Constructor for an immutable Pi. | |
Pi (const Def *type, bool implicit) | |
Constructor for a *mut*able Pi. | |
![]() | |
Def (World *, Node, const Def *type, Defs ops, flags_t flags) | |
Constructor for an immutable Def. | |
Def (Node, const Def *type, Defs ops, flags_t flags) | |
As above but World retrieved from type . | |
Def (Node, const Def *type, size_t num_ops, flags_t flags) | |
Constructor for a mutable Def. | |
virtual | ~Def ()=default |
Sym | sym (const char *) const |
Sym | sym (std::string_view) const |
Sym | sym (std::string) const |
Private Member Functions | |
const Def * | rebuild_ (World &, const Def *, Defs) const override |
Pi * | stub_ (World &, const Def *) override |
Friends | |
class | World |
Type Checking | |
const Def * | check (size_t, const Def *) override |
const Def * | check () override |
static const Def * | infer (const Def *dom, const Def *codom) |
Additional Inherited Members | ||
![]() | ||
Dbg | dbg_ | |
union { | ||
NormalizeFn | normalizer_ | |
Axiom only: Axioms use this member to store their normalizer. | ||
const Axiom * | axiom_ | |
App only: Curried Apps of Axioms use this member to propagate the Axiom. | ||
const Var * | var_ | |
Mutable only: Var of a mutable. | ||
World * | world_ | |
}; | ||
flags_t | flags_ | |
u8 | curry_ = 0 | |
u8 | trip_ = 0 | |
Constructor for an immutable Pi.
Definition at line 14 of file lam.h.
References codom(), dom(), Node, and mim::Def::type().
Referenced by has_ret_pi(), immutabilize(), isa_basicblock(), isa_cn(), isa_implicit(), isa_returning(), make_explicit(), make_implicit(), ret_pi(), set(), set_codom(), set_dom(), set_dom(), stub(), stub_(), and unset().
Constructor for a *mut*able Pi.
Definition at line 17 of file lam.h.
References Node, and mim::Def::type().
|
overridevirtual |
Reimplemented from mim::Def.
Definition at line 299 of file check.cpp.
References mim::Checker::alpha(), codom(), dom(), mim::error(), infer(), mim::Def::loc(), and mim::Def::type().
|
inline |
Definition at line 33 of file lam.h.
References mim::Def::op().
Referenced by mim::plug::autodiff::autodiff_type_fun_pi(), check(), mim::Lam::codom(), immutabilize(), infer(), Pi(), set(), set_codom(), and mim::World::test().
|
inline |
Definition at line 32 of file lam.h.
References mim::Def::op().
Referenced by mim::plug::autodiff::AutoDiffEval::augment_lam(), mim::plug::autodiff::autodiff_type_fun_pi(), check(), mim::compose_cn(), mim::Lam::dom(), immutabilize(), infer(), mim::plug::direct::op_cps2ds_dep(), Pi(), mim::Lam::ret_dom(), ret_dom(), ret_pi(), set(), set_dom(), and mim::World::test().
Yields the Pi::ret_pi() of d
, if it is in fact a Pi.
Definition at line 56 of file lam.h.
References Pi().
Referenced by mim::ast::RetExpr::emit_().
|
overridevirtual |
Tries to make an immutable from a mutable.
This usually works if the mutable isn't recursive and its var isn't used.
Reimplemented from mim::Def.
Definition at line 193 of file def.cpp.
References codom(), dom(), mim::Def::is_immutabilizable(), Pi(), mim::World::pi(), and mim::Def::world().
|
inline |
Definition at line 23 of file lam.h.
References mim::Def::flags().
Referenced by rebuild_(), and stub_().
Is this a continuation (Pi::isa_cn) that is not Pi::isa_returning?
Definition at line 48 of file lam.h.
References isa_cn(), Pi(), and ret_pi().
Referenced by mim::plug::autodiff::AutoDiffEval::augment_app(), mim::ll::Emitter::emit_epilogue(), mim::plug::clos::ClosLit::is_basicblock(), mim::Lam::isa_basicblock(), and ret_pi().
Is this a continuation - i.e. is the Pi::codom mim::Bottom?
Definition at line 44 of file lam.h.
References mim::Bot, isa_cn(), mim::Def::node(), and Pi().
Referenced by mim::plug::clos::LowerTypedClosPrep::analyze(), mim::plug::autodiff::AutoDiffEval::augment_app(), mim::plug::autodiff::autodiff_type_fun_pi(), mim::plug::clos::ClosConvPrep::enter(), isa_basicblock(), mim::plug::clos::isa_clos_type(), mim::Lam::isa_cn(), isa_cn(), isa_returning(), mim::plug::direct::op_cps2ds_dep(), mim::plug::clos::BranchClosElim::rewrite(), and mim::plug::clos::ClosConvPrep::rewrite_callee().
Is d
an Pi::is_implicit (mutable) Pi?
Definition at line 51 of file lam.h.
References Pi().
Referenced by mim::World::implicit_app().
Is this a continuation (Pi::isa_cn) which has a Pi::ret_pi?
Definition at line 46 of file lam.h.
References isa_cn(), Pi(), and ret_pi().
Referenced by mim::compose_cn(), mim::ll::Emitter::emit_epilogue(), mim::plug::clos::ClosConvPrep::enter(), mim::plug::clos::ClosLit::is_returning(), and mim::Lam::isa_returning().
|
inline |
Definition at line 25 of file lam.h.
References mim::Def::flags_, and Pi().
|
inline |
Definition at line 24 of file lam.h.
References mim::Def::flags_, and Pi().
Definition at line 89 of file lam.h.
References mim::Def::reduce().
|
inline |
Pi::domain of Pi::ret_pi.
Definition at line 66 of file lam.h.
References dom(), and ret_pi().
Referenced by mim::compose_cn().
const Pi * mim::Pi::ret_pi | ( | ) | const |
Yields the last Pi::dom, if Pi::isa_basicblock.
Definition at line 13 of file lam.cpp.
References dom(), isa_basicblock(), and Pi().
Referenced by mim::ll::Emitter::emit_imported(), isa_basicblock(), isa_returning(), ret_dom(), mim::Lam::ret_pi(), and mim::Lam::ret_var().
Definition at line 22 of file lam.cpp.
References Pi(), mim::Def::set(), and mim::Def::world().
Definition at line 90 of file lam.h.
References mim::Def::dbg(), Pi(), set(), stub_(), mim::Def::type(), and mim::Def::world().
Referenced by mim::plug::mem::CopyProp::rewrite().
|
inline |
Definition at line 77 of file lam.h.
References Pi(), and mim::Def::unset().
|
friend |
|
staticconstexpr |