MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::Def Class Referenceabstract

Base class for all Defs. More...

#include <mim/def.h>

Inheritance diagram for mim::Def:
[legend]

Public Member Functions

Getters
Worldworld () const noexcept
 
constexpr flags_t flags () const noexcept
 
constexpr u32 gid () const noexcept
 
constexpr size_t hash () const noexcept
 
constexpr node_t node () const noexcept
 
std::string_view node_name () const
 
type
Ref type () const noexcept
 Yields the raw type of this Def, i.e. maybe nullptr.
 
Ref unfold_type () const
 Yields the type of this Def and builds a new Type (UInc n) if necessary.
 
bool is_term () const
 Yields true if this:T and T:(Type 0).
 
arity
Ref arity () const
 
std::optional< nat_tisa_lit_arity () const
 
nat_t as_lit_arity () const
 
ops
template<size_t N = std::dynamic_extent>
constexpr auto ops () const noexcept
 
Ref op (size_t i) const noexcept
 
constexpr size_t num_ops () const noexcept
 
Setting Ops (Mutables Only)

You can set and change the Def::ops of a mutable after construction.

However, you have to obey the following rules:

  1. If Def::is_set() is ...
    1. ... false, set the operands from
      • left (i == 0) to
      • right (i == num_ops() - 1).
    2. ... true, reset the operands from left to right as in 1a.
  2. In addition, you can invoke Def::unset() at any time to start over with 1a:
    mut->unset()->set({a, b, c}); // This will always work, but should be your last resort.

MimIR assumes that a mutable is final, when its last operand is set. Then, Def::check() will be invoked.

Defset (size_t i, Ref)
 Successively set from left to right.
 
Defreset (size_t i, Ref def)
 Successively reset from left to right.
 
Defset (Defs ops)
 Def::set ops all at once.
 
Defreset (Defs ops)
 Def::reset ops all at once.
 
Defunset ()
 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.
 
deps

All dependencies of a Def and includes:

Defs deps () const
 
Ref dep (size_t i) const
 
size_t num_deps () const
 
has_dep

Checks whether one Def::deps() contains specific elements defined in Dep.

This works up to the next mutable. For example, consider the Tuple tup: (<infer>, lam (x: Nat) = y):

bool has_infer = tup->has_dep(Dep::Infer); // true;
bool has_mut = tup->has_dep(Dep::Mut); // true;
bool has_var = tup->has_dep(Dep::Var); // false - y is contained in another mutable;
bool has_dep() const
Definition def.h:313
const Var * has_var()
Only returns not nullptr, if Var of this mutable has ever been created.
Definition def.h:385
bool has_dep () const
 
bool has_dep (Dep d) const
 
bool has_dep (unsigned u) const
 
bool has_const_dep () const
 Neither a Dep::Mut nor a Dep::Var; can often be used as shortcut as an optimization.
 
proj

Splits this Def via Extracts or directly accessing the Def::ops in the case of Sigmas or Arrays.

std::array<const Def*, 2> ab = def->projs<2>();
std::array<u64, 2> xy = def->projs<2>([](auto def) { return Lit::as(def); });
auto [a, b] = def->projs<2>();
auto [x, y] = def->projs<2>([](auto def) { return Lit::as(def); });
Vector<const Def*> projs1 = def->projs(); // "projs1" has def->num_projs() many elements
Vector<const Def*> projs2 = def->projs(n);// "projs2" has n elements - asserts if incorrect
// same as above but applies Lit::as<nat_t>(def) to each element
Vector<const Lit*> lits1 = def->projs( [](auto def) { return Lit::as(def); });
Vector<const Lit*> lits2 = def->projs(n, [](auto def) { return Lit::as(def); });
static T as(Ref def)
Definition def.h:736
Vector(I, I, A=A()) -> Vector< typename std::iterator_traits< I >::value_type, Default_Inlined_Size< typename std::iterator_traits< I >::value_type >, A >
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.
 
Ref 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.
 
Ref proj (nat_t i) const
 As above but takes Def::num_projs as arity.
 
Ref 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
 
var

Retrieve Var for mutables.

See also
proj
nat_t num_vars () noexcept
 
nat_t num_tvars () noexcept
 
Ref var (nat_t a, nat_t i) noexcept
 
Ref var (nat_t i) noexcept
 
Ref 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
 
Ref var ()
 Not necessarily a Var: E.g., if the return type is [], this will yield ().
 
const Varhas_var ()
 Only returns not nullptr, if Var of this mutable has ever been created.
 
const Varhas_var () const
 As above if this is a mutable.
 
Free Vars and Muts
Muts local_muts () const
 Mutables reachable by following immutable deps(); mut->local_muts() is by definition the set { mut }.
 
Muts mut_local_muts ()
 All local_muts() of this mutable's deps().
 
Vars local_vars () const
 Vars reachable by following immutable deps().
 
Vars free_vars () const
 Compute a global solution, i.e., 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()?
 
external
bool is_external () const
 
void make_external ()
 
void make_internal ()
 
void transfer_external (Def *to)
 
Casts
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 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.
 
Dbg Getters
Dbg dbg () const
 
Loc loc () const
 
Sym sym () const
 
std::string unique_name () const
 name + "_" + Def::gid
 
Dbg Setters

Every subclass S of Def has the same setters that return S*/const S* via the mixin Setters.

template<bool Ow = false>
const Defset (Loc l) const
 
template<bool Ow = false>
Defset (Loc l)
 
template<bool Ow = false>
const Defset (Sym s) const
 
template<bool Ow = false>
Defset (Sym s)
 
template<bool Ow = false>
const Defset (std::string s) const
 
template<bool Ow = false>
Defset (std::string s)
 
template<bool Ow = false>
const Defset (Loc l, Sym s) const
 
template<bool Ow = false>
Defset (Loc l, Sym s)
 
template<bool Ow = false>
const Defset (Loc l, std::string s) const
 
template<bool Ow = false>
Defset (Loc l, std::string s)
 
template<bool Ow = false>
const Defset (Dbg d) const
 
template<bool Ow = false>
Defset (Dbg d)
 
debug_prefix/suffix

Prepends/Appends a prefix/suffix to Def::name - but only in Debug build.

const Defdebug_prefix (std::string) const
 
const Defdebug_suffix (std::string) const
 
Rebuild
Defstub (World &w, Ref type)
 
Defstub (Ref type)
 
Ref rebuild (World &w, Ref type, Defs ops) const
 Def::rebuilds this Def while using new_op as substitute for its i'th Def::op.
 
Ref rebuild (Ref type, Defs ops) const
 
virtual const Defimmutabilize ()
 Tries to make an immutable from a mutable.
 
bool is_immutabilizable ()
 
Ref refine (size_t i, Ref new_op) const
 
DefVec reduce (Ref arg) const
 Rewrites Def::ops by substituting this mutable's Var with arg.
 
DefVec reduce (Ref arg)
 
Ref reduce (size_t i, Ref arg) const
 As above but only rewrites this->op(i).
 
Type Checking
virtual Ref check (size_t, Ref def)
 
virtual Ref check ()
 
const Defzonk () const
 
dump
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
 
dot

Dumps DOT to os while obeying maximum recursion depth of max.

If types is true, Def::type() dependencies will be followed as well.

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
 

Protected Member Functions

C'tors and D'tors
 Def (World *, node_t, const Def *type, Defs ops, flags_t flags)
 Constructor for an immutable Def.
 
 Def (node_t n, const Def *type, Defs ops, flags_t flags)
 As above but World retrieved from type.
 
 Def (node_t, const Def *type, size_t num_ops, flags_t flags)
 Constructor for a mutable Def.
 
virtual ~Def ()=default
 
Wrappers for World::sym

These are here to have Def::setters inline without including mim/world.h.

Sym sym (const char *) const
 
Sym sym (std::string_view) const
 
Sym sym (std::string) const
 

Protected Attributes

Dbg dbg_
 
union { 
 
NormalizeFn normalizer_
 Axiom only: Axioms use this member to store their normalizer.
 
const Axiomaxiom_
 App only: Curried Apps of Axioms use this member to propagate the Axiom.
 
const Varvar_
 Mutable only: Var of a mutable.
 
Worldworld_
 
};  
 
flags_t flags_
 
u8 curry_ = 0
 
u8 trip_ = 0
 

Private Member Functions

virtual Defstub_ (World &, Ref)
 
virtual Ref rebuild_ (World &w, Ref type, Defs ops) const =0
 

Friends

class World
 
void swap (World &, World &) noexcept
 
std::ostream & operator<< (std::ostream &os, const Def *def)
 This will stream def as an operand.
 

Detailed Description

Base class for all Defs.

These are the most important subclasses:

Type Formation Term Introduction Term Elimination
Pi Lam App
Sigma / Arr Tuple / Pack Extract
Insert Insert
Uniq Wrap Unwrap
Join Vel Test
Meet Ac Pick
Nat Lit
Idx Lit

In addition there is:

  • Var: A variable. Currently the following Defs may be binders:
  • Axiom: To introduce new entities.
  • Proxy: Used for intermediate values during optimizations.
  • Infer: Hole in the presentation filled by type inference (always mutable as the holes are filled in later).
  • Type, Univ, UMax, UInc: To keep track of type levels.

The data layout (see World::alloc and Def::deps) looks like this:

Def| type | op(0) ... op(num_ops-1) |
|-----------ops-----------|
|--------------------------------| if type() != nullptr && is_set()
|-------------------------| if type() == nullptr && is_set()
|------| if type() != nullptr && !is_set()
|| if type() == nullptr && !is_set()
Base class for all Defs.
Definition def.h:212
bool is_set() const
Yields true if empty or the last op is set.
Definition def.cpp:281
Defs deps() const
Definition def.cpp:410
Ref op(size_t i) const noexcept
Definition def.h:264
constexpr auto ops() const noexcept
Definition def.h:261
Ref type() const noexcept
Yields the raw type of this Def, i.e. maybe nullptr.
Definition def.h:241
constexpr size_t num_ops() const noexcept
Definition def.h:265
Attention
This means that any subclass of Def must not introduce additional members.
See also
Immutables vs. Mutables

Definition at line 212 of file def.h.

Constructor & Destructor Documentation

◆ Def() [1/3]

mim::Def::Def ( World * w,
node_t node,
const Def * type,
Defs ops,
flags_t flags )
protected

◆ Def() [2/3]

mim::Def::Def ( node_t n,
const Def * type,
Defs ops,
flags_t flags )
protected

As above but World retrieved from type.

Definition at line 60 of file def.cpp.

◆ Def() [3/3]

mim::Def::Def ( node_t node,
const Def * type,
size_t num_ops,
flags_t flags )
protected

Constructor for a mutable Def.

Definition at line 63 of file def.cpp.

References gid(), mim::hash(), mim::World::next_gid(), num_ops(), and world().

◆ ~Def()

virtual mim::Def::~Def ( )
protectedvirtualdefault

Member Function Documentation

◆ arity()

◆ as_imm()

template<class T = Def>
const T * mim::Def::as_imm ( ) const
inline

Definition at line 427 of file def.h.

References as_mut().

◆ as_lit_arity()

nat_t mim::Def::as_lit_arity ( ) const
inline

◆ as_mut()

template<class T = Def, bool invert = false>
T * mim::Def::as_mut ( ) const
inline

◆ check() [1/2]

virtual Ref mim::Def::check ( )
inlinevirtual

Reimplemented in mim::Arr, mim::Pi, and mim::Sigma.

Definition at line 517 of file def.h.

References type().

Referenced by set().

◆ check() [2/2]

virtual Ref mim::Def::check ( size_t ,
Ref def )
inlinevirtual

Reimplemented in mim::Arr, mim::Lam, mim::Pi, and mim::Sigma.

Definition at line 516 of file def.h.

◆ dbg()

◆ debug_prefix()

const Def * mim::Def::debug_prefix ( std::string prefix) const

Definition at line 417 of file def.cpp.

References dbg_, mim::Dbg::set(), sym(), and world().

◆ debug_suffix()

const Def * mim::Def::debug_suffix ( std::string suffix) const

Definition at line 418 of file def.cpp.

References dbg_, mim::Dbg::set(), sym(), and world().

◆ dep()

Ref mim::Def::dep ( size_t i) const
inline

Definition at line 299 of file def.h.

References deps().

◆ deps()

Defs mim::Def::deps ( ) const

◆ dot() [1/3]

void mim::Def::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.

Definition at line 128 of file dot.cpp.

References dot().

◆ dot() [2/3]

void mim::Def::dot ( const std::string & file,
uint32_t max = 0xFFFFFF,
bool types = false ) const
inline

Definition at line 537 of file def.h.

References dot().

◆ dot() [3/3]

void mim::Def::dot ( std::ostream & os,
uint32_t max = 0xFFFFFF,
bool types = false ) const

Definition at line 126 of file dot.cpp.

Referenced by dot(), and dot().

◆ dump() [1/2]

void mim::Def::dump ( ) const

Definition at line 449 of file dump.cpp.

◆ dump() [2/2]

void mim::Def::dump ( int max) const

Definition at line 450 of file dump.cpp.

◆ flags()

◆ free_vars() [1/2]

Vars mim::Def::free_vars ( )

Definition at line 312 of file def.cpp.

References free_vars(), is_set(), mim::World::next_run(), and world().

◆ free_vars() [2/2]

Vars mim::Def::free_vars ( ) const

◆ gid()

u32 mim::Def::gid ( ) const
inlineconstexprnoexcept

◆ has_const_dep()

bool mim::Def::has_const_dep ( ) const
inline

Neither a Dep::Mut nor a Dep::Var; can often be used as shortcut as an optimization.

Definition at line 317 of file def.h.

References has_dep(), mim::Mut, and mim::Var.

Referenced by Def(), mim::Scheduler::early(), mim::plug::clos::free_defs(), mim::Scheduler::late(), mim::plug::core::normalize_pe(), and mim::Rewriter::rewrite_imm().

◆ has_dep() [1/3]

bool mim::Def::has_dep ( ) const
inline

Definition at line 313 of file def.h.

Referenced by has_const_dep(), mim::VarRewriter::rewrite_imm(), and zonk().

◆ has_dep() [2/3]

bool mim::Def::has_dep ( Dep d) const
inline

Definition at line 314 of file def.h.

References has_dep().

Referenced by has_dep().

◆ has_dep() [3/3]

bool mim::Def::has_dep ( unsigned u) const
inline

Definition at line 315 of file def.h.

◆ has_var() [1/2]

const Var * mim::Def::has_var ( )
inline

Only returns not nullptr, if Var of this mutable has ever been created.

Definition at line 385 of file def.h.

Referenced by has_var(), is_immutabilizable(), mim::plug::direct::op_cps2ds_dep(), reduce(), reduce(), mim::VarRewriter::rewrite_mut(), and mim::Infer::tuplefy().

◆ has_var() [2/2]

const Var * mim::Def::has_var ( ) const
inline

As above if this is a mutable.

Definition at line 387 of file def.h.

References has_var(), and isa_mut().

◆ hash()

size_t mim::Def::hash ( ) const
inlineconstexprnoexcept

Definition at line 232 of file def.h.

◆ immutabilize()

virtual const Def * mim::Def::immutabilize ( )
inlinevirtual

Tries to make an immutable from a mutable.

This usually works if the mutable isn't recursive and its var isn't used.

Reimplemented in mim::Arr, mim::Pack, mim::Pi, and mim::Sigma.

Definition at line 502 of file def.h.

◆ is_closed()

bool mim::Def::is_closed ( ) const

◆ is_external()

bool mim::Def::is_external ( ) const
inline

◆ is_immutabilizable()

◆ is_open()

bool mim::Def::is_open ( ) const

Has free_vars()?

Definition at line 371 of file def.cpp.

References mim::PooledSet< T >::empty(), free_vars(), local_muts(), and local_vars().

◆ is_set()

bool mim::Def::is_set ( ) const

◆ is_term()

bool mim::Def::is_term ( ) const

Yields true if this:T and T:(Type 0).

Definition at line 439 of file def.cpp.

References mim::Lit::isa(), and type().

Referenced by mim::flatten().

◆ isa_imm() [1/2]

template<class T = Def>
const T * mim::Def::isa_imm ( ) const
inline

◆ isa_imm() [2/2]

template<class T = Def, class R >
const T * mim::Def::isa_imm ( R(T::* )() const) const
inline

Definition at line 428 of file def.h.

References isa_mut().

◆ isa_lit_arity()

std::optional< nat_t > mim::Def::isa_lit_arity ( ) const

◆ isa_mut()

◆ loc()

◆ local_muts()

Muts mim::Def::local_muts ( ) const

Mutables reachable by following immutable deps(); mut->local_muts() is by definition the set { mut }.

Definition at line 293 of file def.cpp.

References isa_mut(), mim::World::muts(), and world().

Referenced by Def(), free_vars(), is_closed(), is_open(), mut_local_muts(), and mim::VarRewriter::rewrite_imm().

◆ local_vars()

Vars mim::Def::local_vars ( ) const
inline

Vars reachable by following immutable deps().

Note
var->local_vars() is by definition the set { var }.

Definition at line 405 of file def.h.

Referenced by Def(), free_vars(), is_closed(), is_open(), and mim::VarRewriter::rewrite_imm().

◆ make_external()

void mim::Def::make_external ( )

Definition at line 477 of file def.cpp.

References mim::World::make_external(), and world().

Referenced by transfer_external().

◆ make_internal()

void mim::Def::make_internal ( )

◆ mut_local_muts()

Muts mim::Def::mut_local_muts ( )

All local_muts() of this mutable's deps().

Definition at line 298 of file def.cpp.

References deps(), local_muts(), mim::World::muts(), op(), and world().

Referenced by is_immutabilizable(), and mim::post_order().

◆ node()

node_t mim::Def::node ( ) const
inlineconstexprnoexcept

Definition at line 233 of file def.h.

Referenced by Def(), mim::Pi::isa_cn(), and node_name().

◆ node_name()

std::string_view mim::Def::node_name ( ) const

◆ num_deps()

size_t mim::Def::num_deps ( ) const
inline

Definition at line 300 of file def.h.

References deps().

◆ num_ops()

◆ num_projs()

nat_t mim::Def::num_projs ( ) const
inline

Yields Def::as_lit_arity(), if it is in fact a Lit, or 1 otherwise.

Definition at line 337 of file def.h.

References isa_lit_arity().

Referenced by mim::plug::clos::clos_insert_env(), mim::plug::clos::clos_remove_env(), mim::plug::mem::mem_def(), proj(), projs(), and mim::plug::mem::replace_mem().

◆ num_tprojs()

nat_t mim::Def::num_tprojs ( ) const

As above but yields 1, if Flags::scalarize_threshold is exceeded.

Definition at line 482 of file def.cpp.

References mim::World::flags(), isa_lit_arity(), mim::Flags::scalarize_threshold, and world().

Referenced by tproj(), and tprojs().

◆ num_tvars()

nat_t mim::Def::num_tvars ( )
inlinenoexcept

Definition at line 381 of file def.h.

◆ num_vars()

nat_t mim::Def::num_vars ( )
inlinenoexcept

Definition at line 381 of file def.h.

Referenced by mim::ll::Emitter::emit_epilogue(), and mim::Lam::ret_var().

◆ op()

◆ ops()

◆ proj() [1/2]

Ref mim::Def::proj ( nat_t a,
nat_t i ) const

◆ proj() [2/2]

Ref mim::Def::proj ( nat_t i) const
inline

As above but takes Def::num_projs as arity.

Definition at line 342 of file def.h.

References num_projs(), and proj().

Referenced by proj().

◆ projs() [1/4]

template<nat_t A = std::dynamic_extent>
auto mim::Def::projs ( ) const
inline

Definition at line 365 of file def.h.

References projs().

Referenced by projs(), projs(), projs(), and tprojs().

◆ projs() [2/4]

template<nat_t A = std::dynamic_extent, class F >
auto mim::Def::projs ( F f) const
inline

Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (otherwise).

Applies f to each element.

Definition at line 347 of file def.h.

References as_lit_arity(), num_projs(), proj(), and projs().

Referenced by mim::plug::autodiff::AutoDiffEval::augment_tuple(), mim::ll::Emitter::emit_bb(), mim::plug::clos::Clos2SJLJ::enter(), mim::plug::regex::flatten_in_arg(), mim::plug::mem::mem_def(), mim_get_plugin(), mim::plug::core::normalize_abs(), mim::plug::autodiff::normalize_add(), mim::plug::math::normalize_arith(), mim::plug::core::normalize_bit2(), mim::plug::math::normalize_cmp(), mim::plug::compile::normalize_combine_pass_list(), mim::plug::refly::normalize_dbg(), mim::plug::core::normalize_div(), mim::plug::core::normalize_extrema(), mim::plug::math::normalize_extrema(), mim::plug::core::normalize_icmp(), mim::plug::mem::normalize_lea(), mim::plug::mem::normalize_load(), mim::plug::core::normalize_nat(), mim::plug::core::normalize_ncmp(), mim::plug::math::normalize_pow(), mim::plug::regex::normalize_range(), mim::plug::matrix::normalize_read(), mim::plug::refly::normalize_refine(), mim::plug::matrix::normalize_shape(), mim::plug::core::normalize_shr(), mim::plug::mem::normalize_store(), mim::plug::autodiff::normalize_sum(), mim::plug::core::normalize_wrap(), mim::plug::core::normalize_zip(), mim::plug::matrix::LowerMatrixMediumLevel::rewrite_(), mim::plug::matrix::LowerMatrixLowLevel::rewrite_imm(), mim::plug::mem::strip_mem(), mim::tuple2str(), and mim::unflatten().

◆ projs() [3/4]

auto mim::Def::projs ( nat_t a) const
inline

Definition at line 371 of file def.h.

References projs().

◆ projs() [4/4]

template<class F >
auto mim::Def::projs ( nat_t a,
F f ) const
inline

Definition at line 361 of file def.h.

References proj(), and mim::Vector().

◆ rebuild() [1/2]

Ref mim::Def::rebuild ( Ref type,
Defs ops ) const
inline

Definition at line 498 of file def.h.

References ops(), rebuild(), type(), and world().

Referenced by rebuild().

◆ rebuild() [2/2]

Ref mim::Def::rebuild ( World & w,
Ref type,
Defs ops ) const
inline

Def::rebuilds this Def while using new_op as substitute for its i'th Def::op.

Definition at line 494 of file def.h.

References dbg(), isa_imm(), ops(), rebuild_(), set(), and type().

Referenced by refine(), mim::EtaExp::rewrite(), and mim::Rewriter::rewrite_imm().

◆ rebuild_()

◆ reduce() [1/3]

DefVec mim::Def::reduce ( Ref arg)

Definition at line 209 of file def.cpp.

References has_var(), num_ops(), op(), ops(), var(), and world().

◆ reduce() [2/3]

DefVec mim::Def::reduce ( Ref arg) const

Rewrites Def::ops by substituting this mutable's Var with arg.

Definition at line 204 of file def.cpp.

References isa_mut(), and ops().

Referenced by mim::World::extract(), mim::plug::compile::handle_optimization_part(), mim::Arr::reduce(), mim::Pack::reduce(), and mim::Pi::reduce().

◆ reduce() [3/3]

Ref mim::Def::reduce ( size_t i,
Ref arg ) const

As above but only rewrites this->op(i).

Definition at line 223 of file def.cpp.

References has_var(), isa_mut(), and op().

◆ refine()

◆ reset() [1/2]

Def * mim::Def::reset ( Defs ops)

Def::reset ops all at once.

Definition at line 240 of file def.cpp.

References num_ops(), ops(), and reset().

◆ reset() [2/2]

Def * mim::Def::reset ( size_t i,
Ref def )
inline

Successively reset from left to right.

Definition at line 286 of file def.h.

References set(), and unset().

Referenced by mim::plug::clos::Clos2SJLJ::enter(), mim::RetWrap::enter(), mim::Infer::find(), reset(), mim::Infer::reset(), and mim::PassMan::run().

◆ set() [1/14]

template<bool Ow = false>
Def * mim::Def::set ( Dbg d)
inline

Definition at line 472 of file def.h.

References set().

Referenced by set().

◆ set() [2/14]

template<bool Ow = false>
const Def * mim::Def::set ( Dbg d) const
inline

Definition at line 471 of file def.h.

References set().

Referenced by set().

◆ set() [3/14]

Def * mim::Def::set ( Defs ops)

Def::set ops all at once.

Definition at line 239 of file def.cpp.

References num_ops(), ops(), and set().

◆ set() [4/14]

template<bool Ow = false>
Def * mim::Def::set ( Loc l)
inline

Definition at line 462 of file def.h.

References dbg_, mim::Dbg::loc(), and mim::Dbg::set().

◆ set() [5/14]

template<bool Ow = false>
const Def * mim::Def::set ( Loc l) const
inline

Definition at line 461 of file def.h.

References dbg_, mim::Dbg::loc(), and mim::Dbg::set().

◆ set() [6/14]

template<bool Ow = false>
Def * mim::Def::set ( Loc l,
std::string s )
inline

Definition at line 470 of file def.h.

References set(), and sym().

Referenced by set().

◆ set() [7/14]

template<bool Ow = false>
const Def * mim::Def::set ( Loc l,
std::string s ) const
inline

Definition at line 469 of file def.h.

References set(), and sym().

Referenced by set().

◆ set() [8/14]

template<bool Ow = false>
Def * mim::Def::set ( Loc l,
Sym s )
inline

Definition at line 468 of file def.h.

References set().

Referenced by set().

◆ set() [9/14]

template<bool Ow = false>
const Def * mim::Def::set ( Loc l,
Sym s ) const
inline

Definition at line 467 of file def.h.

References set().

Referenced by set().

◆ set() [10/14]

◆ set() [11/14]

template<bool Ow = false>
Def * mim::Def::set ( std::string s)
inline

Definition at line 466 of file def.h.

References set(), and sym().

Referenced by set().

◆ set() [12/14]

template<bool Ow = false>
const Def * mim::Def::set ( std::string s) const
inline

Definition at line 465 of file def.h.

References set(), and sym().

Referenced by set().

◆ set() [13/14]

template<bool Ow = false>
Def * mim::Def::set ( Sym s)
inline

Definition at line 464 of file def.h.

References dbg_, mim::Dbg::set(), and mim::Dbg::sym().

◆ set() [14/14]

template<bool Ow = false>
const Def * mim::Def::set ( Sym s) const
inline

Definition at line 463 of file def.h.

References dbg_, mim::Dbg::set(), and mim::Dbg::sym().

◆ stream()

std::ostream & mim::Def::stream ( std::ostream & os,
int max ) const

Definition at line 430 of file dump.cpp.

◆ stub() [1/2]

Def * mim::Def::stub ( Ref type)
inline

Definition at line 491 of file def.h.

References stub(), type(), and world().

Referenced by stub().

◆ stub() [2/2]

Def * mim::Def::stub ( World & w,
Ref type )
inline

Definition at line 490 of file def.h.

References dbg(), set(), stub_(), and type().

Referenced by mim::LamSpec::rewrite(), and mim::Rewriter::rewrite_mut().

◆ stub_()

virtual Def * mim::Def::stub_ ( World & ,
Ref  )
inlineprivatevirtual

Reimplemented in mim::Arr, mim::Global, mim::Infer, mim::Lam, mim::Pack, mim::Pi, mim::Sigma, mim::TBound< Up >, and mim::TExt< Up >.

Definition at line 552 of file def.h.

Referenced by stub().

◆ sym() [1/4]

◆ sym() [2/4]

Sym mim::Def::sym ( const char * s) const
protected

Definition at line 380 of file def.cpp.

References mim::World::sym(), and world().

◆ sym() [3/4]

Sym mim::Def::sym ( std::string s) const
protected

Definition at line 382 of file def.cpp.

References mim::World::sym(), and world().

◆ sym() [4/4]

Sym mim::Def::sym ( std::string_view s) const
protected

Definition at line 381 of file def.cpp.

References mim::World::sym(), and world().

◆ tproj()

Ref mim::Def::tproj ( nat_t i) const
inline

As above but takes Def::num_tprojs.

Definition at line 343 of file def.h.

References num_tprojs(), and proj().

◆ tprojs() [1/2]

auto mim::Def::tprojs ( ) const
inline

Definition at line 368 of file def.h.

References tprojs().

Referenced by tprojs().

◆ tprojs() [2/2]

template<class F >
auto mim::Def::tprojs ( F f) const
inline

Definition at line 359 of file def.h.

References num_tprojs(), and projs().

◆ transfer_external()

void mim::Def::transfer_external ( Def * to)
inline

Definition at line 419 of file def.h.

References make_external(), and make_internal().

◆ tvar()

Ref mim::Def::tvar ( nat_t i)
inlinenoexcept

Definition at line 381 of file def.h.

◆ tvars() [1/2]

auto mim::Def::tvars ( )
inlinenoexcept

Definition at line 381 of file def.h.

◆ tvars() [2/2]

template<class F >
auto mim::Def::tvars ( F f)
inlinenoexcept

Definition at line 381 of file def.h.

◆ type()

Ref mim::Def::type ( ) const
inlinenoexcept

Yields the raw type of this Def, i.e. maybe nullptr.

See also
Def::unfold_type.

Definition at line 241 of file def.h.

Referenced by mim::World::app(), arity(), mim::plug::autodiff::AutoDiffEval::augment_(), mim::plug::autodiff::AutoDiffEval::augment_app(), mim::plug::autodiff::AutoDiffEval::augment_extract(), mim::plug::autodiff::AutoDiffEval::augment_pack(), mim::plug::autodiff::AutoDiffEval::augment_tuple(), mim::App::callee_type(), mim::Arr::check(), check(), mim::Lam::check(), mim::Pi::check(), mim::Sigma::check(), mim::plug::clos::clos_pack(), mim::plug::matrix::counting_for(), Def(), deps(), mim::plug::autodiff::AutoDiffEval::derive_(), mim::ll::Emitter::emit_bb(), mim::plug::clos::ClosLit::env_type(), mim::plug::clos::ClosConvPrep::eta_wrap(), mim::World::extract(), mim::Bound::find(), mim::flatten(), mim::plug::clos::ClosLit::fnc_type(), mim::Bound::get(), mim::plug::compile::handle_optimization_part(), mim::World::implicit_app(), mim::World::insert(), is_term(), mim::is_unit(), isa_lit_arity(), mim::plug::mem::mem_def(), mim::merge_tuple(), mim::plug::core::normalize_bitcast(), mim::plug::core::normalize_conv(), mim::plug::math::normalize_conv(), mim::plug::core::normalize_shr(), mim::plug::core::op(), mim::plug::direct::op_cps2ds_dep(), mim::plug::mem::op_lea(), mim::plug::mem::op_lea_unsafe(), mim::plug::matrix::op_read(), mim::optimize(), mim::World::pack(), proj(), rebuild(), rebuild(), refine(), mim::plug::mem::replace_mem(), mim::EtaExp::rewrite(), mim::plug::matrix::LowerMatrixHighLevelMapRed::rewrite_(), mim::plug::clos::ClosConvPrep::rewrite_callee(), mim::plug::matrix::LowerMatrixLowLevel::rewrite_imm(), mim::Rewriter::rewrite_imm(), mim::Rewriter::rewrite_mut(), mim::PassMan::run(), mim::Scheduler::Scheduler(), set(), mim::Pack::shape(), mim::plug::mem::strip_mem(), mim::Arr::stub(), stub(), stub(), mim::Infer::stub(), mim::Pack::stub(), mim::Pi::stub(), mim::Sigma::stub(), mim::TBound< Up >::stub(), mim::TExt< Up >::stub(), mim::World::test(), mim::World::tuple(), mim::Infer::tuplefy(), mim::Global::type(), mim::Lam::type(), mim::plug::clos::ClosLit::type(), mim::World::type(), mim::World::uinc(), mim::World::uniq(), and world().

◆ unfold_type()

Ref mim::Def::unfold_type ( ) const

Yields the type of this Def and builds a new Type (UInc n) if necessary.

Definition at line 390 of file def.cpp.

References mim::World::type(), and world().

Referenced by mim::World::arr(), mim::Arr::check(), mim::Pi::infer(), and mim::World::uniq().

◆ unique_name()

std::string mim::Def::unique_name ( ) const

name + "_" + Def::gid

Definition at line 480 of file def.cpp.

References gid(), and sym().

Referenced by mim::Nest::Node::name(), and mim::ll::Emitter::prepare().

◆ unset()

Def * mim::Def::unset ( )

Unsets all Def::ops; works even, if not set at all or partially.

Definition at line 259 of file def.cpp.

References num_ops(), op(), and unset().

Referenced by reset(), mim::Arr::unset(), unset(), mim::Infer::unset(), mim::Lam::unset(), mim::Pack::unset(), mim::Pi::unset(), and mim::Sigma::unset().

◆ users()

Muts mim::Def::users ( )
inline

Set of mutables where this mutable is locally referenced.

Definition at line 409 of file def.h.

◆ var() [1/3]

Ref mim::Def::var ( )

Not necessarily a Var: E.g., if the return type is [], this will yield ().

Definition at line 423 of file def.cpp.

References world().

Referenced by Def(), reduce(), mim::Lam::ret_var(), and mim::Infer::tuplefy().

◆ var() [2/3]

◆ var() [3/3]

Ref mim::Def::var ( nat_t i)
inlinenoexcept

Definition at line 381 of file def.h.

◆ vars() [1/4]

template<nat_t A = std::dynamic_extent>
auto mim::Def::vars ( )
inlinenoexcept

Definition at line 381 of file def.h.

Referenced by free_vars().

◆ vars() [2/4]

template<nat_t A = std::dynamic_extent, class F >
auto mim::Def::vars ( F f)
inlinenoexcept

◆ vars() [3/4]

auto mim::Def::vars ( nat_t a)
inlinenoexcept

Definition at line 381 of file def.h.

◆ vars() [4/4]

template<class F >
auto mim::Def::vars ( nat_t a,
F f )
inlinenoexcept

Definition at line 381 of file def.h.

◆ world()

World & mim::Def::world ( ) const
noexcept

Definition at line 384 of file def.cpp.

References type(), and world().

Referenced by mim::Checker::alpha(), mim::Lam::app(), mim::Lam::app(), mim::plug::clos::apply_closure(), arity(), mim::Checker::assignable(), mim::plug::autodiff::autodiff_type_fun(), mim::plug::autodiff::autodiff_type_fun_pi(), mim::Lam::branch(), mim::Lam::check(), mim::Sigma::check(), mim::plug::clos::clos_apply(), mim::plug::clos::clos_insert_env(), mim::plug::clos::clos_pack(), mim::plug::clos::clos_remove_env(), mim::plug::clos::clos_type(), mim::plug::clos::clos_type_to_pi(), mim::plug::core::convert(), mim::plug::matrix::counting_for(), debug_prefix(), debug_suffix(), Def(), Def(), mim::flatten(), free_vars(), free_vars(), mim::plug::autodiff::id_pullback(), mim::Arr::immutabilize(), mim::Pack::immutabilize(), mim::Pi::immutabilize(), mim::Sigma::immutabilize(), mim::Pi::infer(), mim::is_unit(), mim::plug::clos::isa_clos_type(), local_muts(), make_external(), make_internal(), mim::merge_sigma(), mim::merge_tuple(), mim::plug::mem::mut_con(), mut_local_muts(), mim::plug::core::normalize_abs(), mim::plug::math::normalize_abs(), mim::plug::autodiff::normalize_add(), mim::plug::math::normalize_arith(), mim::plug::core::normalize_bit1(), mim::plug::core::normalize_bit2(), mim::plug::core::normalize_bitcast(), mim::plug::math::normalize_cmp(), mim::plug::compile::normalize_combine_pass_list(), mim::plug::compile::normalize_combined_phase(), mim::plug::regex::normalize_conj(), mim::plug::demo::normalize_const(), mim::plug::core::normalize_conv(), mim::plug::math::normalize_conv(), mim::plug::regex::normalize_disj(), mim::plug::core::normalize_div(), mim::plug::math::normalize_er(), mim::plug::math::normalize_exp(), mim::plug::core::normalize_extrema(), mim::plug::math::normalize_extrema(), mim::plug::math::normalize_gamma(), mim::plug::refly::normalize_gid(), mim::plug::core::normalize_icmp(), mim::plug::core::normalize_idx(), mim::plug::mem::normalize_load(), mim::plug::core::normalize_nat(), mim::plug::core::normalize_ncmp(), mim::plug::compile::normalize_pass_phase(), mim::plug::core::normalize_pe(), mim::plug::math::normalize_pow(), mim::plug::regex::normalize_quant(), mim::plug::regex::normalize_range(), mim::plug::matrix::normalize_read(), mim::plug::math::normalize_round(), mim::plug::math::normalize_rt(), mim::plug::matrix::normalize_shape(), mim::plug::core::normalize_shr(), mim::plug::compile::normalize_single_pass_phase(), mim::plug::autodiff::normalize_sum(), mim::plug::core::normalize_trait(), mim::plug::math::normalize_tri(), mim::plug::core::normalize_wrap(), mim::plug::core::normalize_zip(), num_tprojs(), mim::plug::core::op(), mim::plug::core::op(), mim::plug::mem::op_alloc(), mim::plug::direct::op_cps2ds_dep(), mim::plug::mem::op_lea(), mim::plug::mem::op_lea_unsafe(), mim::plug::mem::op_lea_unsafe(), mim::plug::mem::op_malloc(), mim::plug::mem::op_mslot(), mim::plug::matrix::op_read(), mim::plug::mem::op_slot(), mim::plug::autodiff::op_sum(), proj(), mim::plug::autodiff::pullback_type(), rebuild(), reduce(), mim::PassMan::run(), mim::Pi::set_dom(), mim::Lam::set_filter(), mim::Pack::shape(), mim::plug::mem::strip_mem(), mim::plug::mem::strip_mem_ty(), mim::Arr::stub(), stub(), mim::Global::stub(), mim::Infer::stub(), mim::Lam::stub(), mim::Pack::stub(), mim::Pi::stub(), mim::Sigma::stub(), mim::TBound< Up >::stub(), mim::TExt< Up >::stub(), sym(), sym(), sym(), mim::Lam::test(), mim::Infer::tuplefy(), unfold_type(), var(), world(), mim::plug::autodiff::zero_def(), mim::plug::autodiff::zero_pullback(), and zonk().

◆ write() [1/2]

void mim::Def::write ( int max) const

Definition at line 457 of file dump.cpp.

◆ write() [2/2]

void mim::Def::write ( int max,
const char * file ) const

Definition at line 452 of file dump.cpp.

◆ zonk()

const Def * mim::Def::zonk ( ) const

Definition at line 23 of file check.cpp.

References has_dep(), mim::Infer, and world().

Referenced by mim::World::app().

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Def * def )
friend

This will stream def as an operand.

This is usually id(def) unless it can be displayed Inline.

Definition at line 421 of file dump.cpp.

◆ swap

void swap ( World & ,
World &  )
friend

◆ World

friend class World
friend

Definition at line 592 of file def.h.

Member Data Documentation

◆ [union]

union { ... } mim::Def

◆ curry_

u8 mim::Def::curry_ = 0
protected

Definition at line 572 of file def.h.

Referenced by mim::App::curry(), and mim::Axiom::curry().

◆ dbg_

Dbg mim::Def::dbg_
mutableprotected

Definition at line 564 of file def.h.

Referenced by dbg(), debug_prefix(), debug_suffix(), loc(), set(), set(), set(), set(), and sym().

◆ flags_

flags_t mim::Def::flags_
protected

Definition at line 571 of file def.h.

Referenced by Def(), flags(), mim::Lit::get(), mim::Pi::make_explicit(), and mim::Pi::make_implicit().

◆ trip_

u8 mim::Def::trip_ = 0
protected

Definition at line 573 of file def.h.

Referenced by mim::App::trip(), and mim::Axiom::trip().


The documentation for this class was generated from the following files: