#include <mim/lam.h>
Public Member Functions | |
arg | |
| |
| const Def * | arg () const |
| nat_t | num_args () const noexcept |
| nat_t | num_targs () const noexcept |
| const Def * | arg (nat_t a, nat_t i) const noexcept |
| const Def * | targ (nat_t i) const noexcept |
| template<nat_t A = std::dynamic_extent> | |
| auto | args (Projector auto f) const noexcept |
| auto | targs (Projector auto f) const noexcept |
| template<nat_t A = std::dynamic_extent> | |
| auto | args () const noexcept |
| auto | targs () const noexcept |
| auto | args (nat_t a, Projector auto f) const noexcept |
| auto | args (nat_t a) const noexcept |
Get axm, current curry counter and trip count | |
| const Axm * | axm () const |
| u8 | curry () const |
| u8 | trip () const |
| Public Member Functions inherited from mim::Def | |
| bool | has_hole () const noexcept |
| Is this a Hole or does it reach one through Def::deps() up to (and excluding) the next mutable? | |
| World & | world () const noexcept |
| Driver & | driver () const noexcept |
| constexpr flags_t | flags () const noexcept |
| constexpr u32 | gid () const noexcept |
| Global id - unique number for this Def. | |
| constexpr u32 | mark () const noexcept |
| Used internally by free_vars(). | |
| constexpr size_t | hash () const noexcept |
| constexpr Node | node () const noexcept |
| constexpr MutNode | mut_node () const noexcept |
| node() of a Def whose Node may be mutable, whether this one is or not; see MutNode. | |
| std::string_view | node_name () const |
| fe::Error & | error () const noexcept |
| Loc | err_loc () const |
| Returns a blame Loc from World::get_loc, this Def, or its nearest located dependency, in that order. | |
| template<class... Args> | |
| fe::Error & | blame (fe::cite_string< Args... > s, Args &&... args) const |
| Reports an error that blames this; chain Error::n for Notes and Error::bail to throw. | |
| void | bail_expected (fe::Cite what) const |
Blames this for not being what and bails; where Def::expect and friends funnel their diagnostic. | |
| Judge | judge () const noexcept |
| Def must never become polymorphic: a vptr costs 8 bytes on every node in the World and would shift Def::type_. | |
| 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 (LSucc n) if necessary. | |
| template<class T> | |
| const T * | isa_type () const |
Is Def::unfold_type a T? Yields nullptr for Level, which has no type at all. | |
| bool | is_term () const |
| Is this Def a term, i.e. is its type() a Type? | |
| const Def * | arity () const |
| Number of elements available to Extract / Insert (may be dynamic). | |
| 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 |
| bool | is_set () const |
| Def * | set (size_t i, const Def *) |
| Successively set from left to right. | |
| Def * | set (Defs ops) |
Set ops all at once (no Def::unset necessary beforehand). | |
| Def * | unset () |
| Unsets all Def::ops; works even, if not set at all or only partially set. | |
| Def * | set_type (const Def *) |
| Update type. | |
| Defs | deps () const noexcept |
| const Def * | dep (size_t i) const noexcept |
| size_t | num_deps () const noexcept |
| nat_t | num_projs () const |
| Yields Def::arity(), if it is a Lit, or 1 otherwise. | |
| nat_t | num_tprojs () const |
| As above but yields 1, if an Arr/Pack exceeds Flags::scalarize_threshold. | |
| 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 * | tproj (nat_t i) const |
| As above but takes Def::num_tprojs. | |
| template<nat_t A = std::dynamic_extent> | |
| auto | projs (Projector auto f) const |
| Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (otherwise). | |
| auto | tprojs (Projector auto f) const |
| auto | projs (nat_t a, Projector auto 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 * | tvar (nat_t i) noexcept |
| template<nat_t A = std::dynamic_extent> | |
| auto | vars (Projector auto f) noexcept |
| auto | tvars (Projector auto f) noexcept |
| template<nat_t A = std::dynamic_extent> | |
| auto | vars () noexcept |
| auto | tvars () noexcept |
| auto | vars (nat_t a, Projector auto 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 Def * | var_type () |
| If this is a binder, compute the type of its Variable. | |
| 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. | |
| template<class D = Def> | |
| std::pair< D *, const Var * > | isa_binder () const |
| Is this a mutable that introduces a Var? | |
| 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 |
| Global set of free Vars: extends local_vars() by transitively following mutables as well. | |
| Vars | free_vars () |
| As above but drives (and caches) the fixed-point iteration for mutables. | |
| Muts | users () |
| Set of mutables where this mutable is locally referenced. | |
| bool | is_open () const |
| Same as has_free_vars(). | |
| bool | is_closed () const |
| Same as !has_free_vars(). | |
| bool | is_ground () const |
| Immutable that contains neither mutables nor Vars. | |
| Def * | outermost_binder () const |
| Transitively walks up free_vars() till the outermoust binder has been found. | |
| bool | nests (Def *mut) |
Does this nest mut? | |
| bool | nests (const Def *def) |
Does this nest def? | |
| bool | in_scope (Def *mut) const |
Is every free Var of this bound by mut or by a mutable that nests mut? | |
| bool | has_free_var (const Var *) const |
| Same as free_vars().contains(var). | |
| bool | has_free_vars () const |
| Same as !free_vars().empty(). | |
| bool | has_free_vars_in (Vars) const |
| Same as vars.has_intersection(free_vars()). | |
| bool | is_external () const noexcept |
| void | externalize () |
| void | internalize () |
| void | transfer_external (Def *to) |
| bool | is_annex () const noexcept |
| bool | is_mutable () const noexcept |
| template<class T = Def> | |
| const T * | isa_imm () const |
| template<class T = Def> | |
| const T * | as_imm () const |
| template<class T = Def, bool invert = false> | |
| T * | isa_mut () const |
If this is mutable, it will cast constness 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 constness away and performs a static_cast to T. | |
| template<class T, class... Args> | |
| T * | expect (fe::cite_string< Args... > fmt, Args &&... args) |
| Like Def::as but - instead of merely asserting in Debug builds - bails via Def::bail_expected when the cast fails; hides fe::RuntimeCast::expect, as a Def can blame itself with a Loc. | |
| template<class T, class... Args> | |
| const T * | expect (fe::cite_string< Args... > fmt, Args &&... args) const |
| const version. | |
| template<class T = Def, class... Args> | |
| T * | expect_mut (fe::cite_string< Args... > fmt, Args &&... args) const |
| The mutable counterpart of Def::expect. | |
| Dbg | dbg () const |
| Looks up Def::dbg_ in Driver::dbg. | |
| DbgKey | dbg_key () const |
| Cheap handle for other->set(this->dbg_key()). | |
| 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) |
| template<bool Ow = false> | |
| const Def * | set (DbgKey key) const |
Adopts the Dbg behind key - just copies the interned index, so nothing is re-interned. | |
| template<bool Ow = false> | |
| Def * | set (DbgKey key) |
| const Def * | debug_prefix (std::string) const |
| const Def * | debug_suffix (std::string) const |
| const Def * | immutabilize () |
| bool | is_immutabilizable () |
| template<size_t N = std::dynamic_extent> | |
| constexpr auto | reduce (const Def *arg) const |
| size_t | reduction_offset () const noexcept |
| First Def::op that needs to be dealt with during reduction; e.g. | |
| const Def * | check (size_t i, const Def *def) |
| Checks whether the ith operand can be set to def. | |
| const Def * | check () |
| After all Def::ops have been Def::set, this method will be invoked to check the type of this mutable. | |
| bool | needs_zonk () const |
| Yields true, if Def::local_muts() contain a Hole that is set. | |
| const Def * | zonk () const |
| If Holes have been filled, reconstruct the program without them. | |
| const Def * | zonk_mut () const |
| If mutable, zonk()s all ops and tries to immutabilize it; otherwise just zonk. | |
| void | dot (std::ostream &os, DotConfig cfg={}) const |
| void | dot (const char *file=nullptr, DotConfig cfg={}) const |
Same as above but write to file or std::cout if file is nullptr. | |
| void | dot (const std::string &file, DotConfig cfg={}) const |
| void | dump () const |
| Dump::Expr - one line, no analysis. | |
| void | dump (Dump) const |
| void | write (Dump) const |
| void | write (Dump, const char *file) const |
| std::ostream & | stream (std::ostream &, Dump) const |
| Public Member Functions inherited from mim::Setters< App > | |
| const App * | set (Args &&... args) const |
Static Public Attributes | |
| static constexpr auto | Node = mim::Node::App |
| static constexpr size_t | Num_Ops = 2 |
Friends | |
| class | World |
callee | |
| const Def * | callee () const |
| const App * | decurry () const |
| Returns App::callee again as App. | |
| const Pi * | callee_type () const |
| static const Def * | callee_of (const Def *def) |
The App::callee of def - or nullptr, if def isn't an App at all. | |
Uncurry | |
Peel off the Use like this: auto [abc, de] = app->uncurry_args<2>();
auto [a, b, c] = abc->projs<3>();
auto [d, e] = de->projs<2>();
auto axm = app->uncurry_callee();
If you "overshoot" the number of curried Apps, the superflous args on the left will be nullptr. | |
| template<size_t N> | |
| auto | uncurry_args () const |
| const Def * | uncurry_callee () const |
| template<size_t N> | |
| static auto | uncurry_args (const Def *def) |
| static const Def * | uncurry_callee (const Def *def) |
| The innermost App::callee - the one that isn't an App itself. | |
Additional Inherited Members | |
| enum class | Dump { Expr , Scope , All } |
| enum class | Cmp { L , G , E , U } |
| Static Public Member Functions inherited from mim::Def | |
| static DefVec | zonk (Defs defs) |
zonks all defs and returns a new DefVec. | |
| static DefVec | cat (Defs a, Defs b) |
| static DefVec | cat (const Def *a, Defs bs) |
| static DefVec | cat (Defs as, const Def *b) |
| static Cmp | cmp (const Def *a, const Def *b) |
| static bool | less (const Def *a, const Def *b) |
| static bool | greater (const Def *a, const Def *b) |
| Protected Member Functions inherited from mim::Def | |
| void | collect_locals () |
| Fills in an immutable's local Vars and Muts once it is in the sea. | |
| 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. | |
| Def (Node, Def *binder) | |
Constructor for a Var; stores its binder. | |
| Sym | sym (const char *) const |
| Sym | sym (std::string_view) const |
| Sym | sym (std::string) const |
| void | set_dbg (Dbg) const |
Interns dbg via Driver::dbg and stores the key in Def::dbg_. | |
| void | set_dbg_ (Dbg, bool ow) const |
| Backs Def::set(Dbg). | |
| void | set_dbg_key_ (DbgKey, bool ow) const |
| Backs Def::set(DbgKey). | |
| Protected Attributes inherited from mim::Def | |
| union mim::Def:: { ... } | |
| flags_t | flags_ |
| u8 | curry_ = 0 |
| u8 | trip_ = 0 |
|
inline |
Definition at line 251 of file lam.h.
References mim::Def::op().
Referenced by arg(), mim::Branch::arg(), mim::Dispatch::arg(), mim::plug::autodiff::phase::Eval::augment_app(), mim::plug::ll::Emitter::emit_phi_args(), mim::plug::core::normalize_conv(), mim::plug::math::normalize_conv(), mim::plug::ord::normalize_init(), mim::plug::vec::normalize_is_unique(), mim::plug::tensor::normalize_shape(), mim::plug::tuple::normalize_zip(), mim::plug::btensor::op_affine_map(), mim::BetaRed::rewrite_imm_App(), mim::EtaConv::rewrite_imm_App(), mim::LamSpec::rewrite_imm_App(), mim::plug::affine::phase::LowerIndex::rewrite_imm_App(), mim::plug::clos::phase::BranchClosElim::rewrite_imm_App(), mim::plug::clos::phase::ClosConv::rewrite_imm_App(), mim::plug::clos::phase::ClosConvPrep::rewrite_imm_App(), mim::plug::clos::phase::LowerTypedClos::rewrite_imm_App(), mim::plug::cps::Conv::rewrite_imm_App(), mim::plug::mem::phase::AddMem::rewrite_imm_App(), mim::plug::mem::phase::FreeLocals::rewrite_imm_App(), mim::plug::mem::phase::Heap2Stack::rewrite_imm_App(), mim::plug::regex::LowerRegex::rewrite_imm_App(), mim::plug::tensor::phase::Fuse::rewrite_imm_App(), mim::plug::tensor::phase::LowerMapReduce::rewrite_imm_App(), mim::plug::tensor::phase::LowerToMem::rewrite_imm_App(), mim::RWPhase::rewrite_imm_App(), mim::Scalarize::rewrite_imm_App(), and mim::plug::tensor::transpose_perm().
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 252 of file lam.h.
Referenced by mim::plug::tensor::normalize_broadcast(), mim::plug::tuple::normalize_cat(), mim::plug::vec::normalize_cat(), mim::plug::vec::normalize_diff(), and mim::plug::mem::phase::AddMem::rewrite_imm_App().
|
inline |
Definition at line 257 of file lam.h.
References axm().
Referenced by mim::plug::mem::phase::AddMem::analyze(), axm(), and mim::Scalarize::rewrite_imm_App().
|
inline |
Definition at line 237 of file lam.h.
References mim::Def::op().
Referenced by mim::plug::autodiff::phase::Eval::augment_app(), mim::Branch::callee(), mim::Dispatch::callee(), callee_type(), decurry(), mim::plug::nvptx::HostEmitter::emit_epilogue(), mim::ast::isa_math_f(), mim::plug::ord::normalize_init(), mim::ADCE::rewrite_imm_App(), mim::BetaRed::rewrite_imm_App(), mim::EtaConv::rewrite_imm_App(), mim::LamSpec::rewrite_imm_App(), mim::plug::affine::phase::LowerIndex::rewrite_imm_App(), mim::plug::clos::phase::BranchClosElim::rewrite_imm_App(), mim::plug::clos::phase::ClosConv::rewrite_imm_App(), mim::plug::clos::phase::ClosConvPrep::rewrite_imm_App(), mim::plug::clos::phase::LowerTypedClos::rewrite_imm_App(), mim::plug::cps::Conv::rewrite_imm_App(), mim::plug::mem::phase::AddMem::rewrite_imm_App(), mim::plug::mem::phase::FreeLocals::rewrite_imm_App(), mim::plug::mem::phase::SEO::rewrite_imm_App(), mim::plug::regex::LowerRegex::rewrite_imm_App(), mim::plug::tensor::phase::Fuse::rewrite_imm_App(), mim::plug::tensor::phase::Lower::rewrite_imm_App(), mim::plug::tensor::phase::LowerToMem::rewrite_imm_App(), mim::RWPhase::rewrite_imm_App(), mim::Scalarize::rewrite_imm_App(), mim::SCCP::rewrite_imm_App(), and mim::StaticArgOpt::rewrite_imm_App().
|
inlinestatic |
The App::callee of def - or nullptr, if def isn't an App at all.
|
inline |
Definition at line 239 of file lam.h.
References callee(), and mim::Def::type().
Referenced by mim::plug::clos::phase::BranchClosElim::rewrite_imm_App(), mim::plug::clos::phase::ClosConvPrep::rewrite_imm_App(), and mim::plug::clos::phase::LowerTypedClos::rewrite_imm_App().
|
inline |
Definition at line 258 of file lam.h.
References mim::Def::curry_.
|
inline |
Returns App::callee again as App.
Definition at line 238 of file lam.h.
References callee().
Referenced by mim::plug::tensor::transpose_perm().
|
inlinenoexcept |
Definition at line 252 of file lam.h.
Referenced by mim::LamSpec::rewrite_imm_App().
|
inlinenoexcept |
Definition at line 252 of file lam.h.
Referenced by mim::plug::mem::phase::FreeLocals::rewrite_imm_App().
|
inlinenoexcept |
Definition at line 252 of file lam.h.
Referenced by mim::StaticArgOpt::rewrite_imm_App().
|
inlinenoexcept |
Definition at line 252 of file lam.h.
Referenced by mim::ADCE::rewrite_imm_App(), mim::plug::mem::phase::SEO::rewrite_imm_App(), mim::SCCP::rewrite_imm_App(), and mim::StaticArgOpt::rewrite_imm_App().
|
inline |
Definition at line 259 of file lam.h.
References mim::Def::trip_.
|
inline |
Definition at line 275 of file lam.h.
Referenced by mim::plug::vec::normalize_fold(), mim::plug::vec::normalize_scan(), and mim::plug::vec::normalize_zip().
|
inlinestatic |
Definition at line 274 of file lam.h.
Referenced by mim::PhaseMan::apply(), and mim::plug::btensor::MapRedPost::of().
|
inline |
Definition at line 279 of file lam.h.
References uncurry_callee().
Referenced by mim::Phase::create(), mim::plug::gpu::phase::run_stage(), and uncurry_callee().
|
inlinestatic |
The innermost App::callee - the one that isn't an App itself.
Definition at line 278 of file lam.h.
Referenced by mim::is_polymorphic_arg().
|
friend |
|
staticconstexpr |