MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches

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
 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
Judgement

What kind of Judgement represents this Def?

Judge judge () const noexcept
bool is_form () const noexcept
bool is_intro () const noexcept
bool is_elim () const noexcept
bool is_meta () const noexcept
type
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
 Is this Def a term, i.e. is its type() a Type?
virtual const Def * arity () const
 Number of elements available to Extract / Insert (may be dynamic).
ops
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
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: If Def::is_set() is ...

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

bool is_set () const
 Yields true if empty or the last op is set.
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.
deps

All dependencies of a Def and includes:

Defs deps () const noexcept
const Def * dep (size_t i) const noexcept
size_t num_deps () const noexcept
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: (?, lam (x: Nat) = y):

bool has_hole = tup->has_dep(Dep::Hole); // 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
const Var * has_var()
Only returns not nullptr, if Var of this mutable has ever been created.
Definition def.h:445
@ Var
Depends on a Var.
Definition def.h:123
@ Hole
Depends on a Hole.
Definition def.h:124
@ Mut
Depends on a mutable.
Definition def.h:122
Dep dep () const noexcept
bool has_dep () const noexcept
bool has_dep (Dep d) const noexcept
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(const Def *def)
Definition def.h:884
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::arity(), if it is 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
var

Retrieve Var for mutables.

See also
proj
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 Def * var_type ()
 If this is a binder, compute the type of its Variable.
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.
template<class D = Def>
std::pair< D *, const Var * > isa_binder () const
 Is this a mutable that introduces a Var?
Free Vars and Muts

MimIR splits the free-variable analysis into a local and a global layer:

  • local_muts() / local_vars() only look at the immutable fan-out and are cheap, cached, and hash-consed.
  • free_vars() close over the mutable boundary as well and are the actual set of free Vars. They are computed on demand via a fixed-point iteration and cached in mutables. Mutating a mutable transitively invalidates these caches by following users().
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
 Has free_vars()?
bool is_closed () const
 Has no free_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?
external
bool is_external () const noexcept
void externalize ()
void internalize ()
void transfer_external (Def *to)
bool is_annex () const noexcept
dirty

Scratch bit for Phases to mark muts that need re-examination.

See also
Phase::taint
bool is_dirty () const noexcept
void dirty (bool dirty=true) noexcept
Casts
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 = Def, class... Args>
T * expect_mut (std::format_string< Args... > fmt, Args &&... args) const
 Like Def::as_mut but - instead of merely asserting in Debug builds - throws via fe::throwf when the cast fails; the mutable counterpart of fe::RuntimeCast::expect (which Def inherits for the general case).
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 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)
debug_prefix/suffix

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

const Def * debug_prefix (std::string) const
const Def * debug_suffix (std::string) const
Rebuild
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
virtual const Def * immutabilize ()
 Tries to make an immutable from a mutable.
bool is_immutabilizable ()
const Def * refine (size_t i, const Def *new_op) const
template<size_t N = std::dynamic_extent>
constexpr auto reduce (const Def *arg) const
virtual constexpr size_t reduction_offset () const noexcept
 First Def::op that needs to be dealt with during reduction; e.g.
Type Checking
virtual const Def * check (size_t i, const Def *def)
 Checks whether the ith operand can be set to def.
virtual 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.
dump
Note
While this output uses Mim syntax, it does usually not produce programs that can be read back. It uses an unscheduled visiting algorithm, and is only meant for debugging purposes.
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

Streams dot to os, configured via cfg (see DotConfig).

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

Static Public Member Functions

static DefVec zonk (Defs defs)
 zonks all defs and returns a new DefVec.

Protected Member Functions

C'tors and D'tors
 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.
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_
 Axm only: Axms use this member to store their normalizer.
const Axmaxm_
 App only: Curried Apps of Axms use this member to propagate the Axm.
const Varvar_
 Mutable only: Var of a mutable.
Def * binder_
 Var only: the binder this Var refers to (not an official op).
Worldworld_
}; 
flags_t flags_
u8 curry_ = 0
u8 trip_ = 0

Private Member Functions

virtual Def * stub_ (World &, const Def *)
virtual const Def * rebuild_ (World &w, const Def *type, Defs ops) const =0

Friends

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

Syntactic Comparison

Establishes an arbitrary but deterministic total order on Defs that is stable across runs.

enum class  Cmp {
  L ,
  G ,
  E ,
  U
}
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)

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
Join Inj Match
Meet Merge Split
Reform Rule
Nat Lit
Idx Lit

In addition there is:

  • Var: A variable. Currently the following Defs may be binders:
  • Axm: To introduce new entities.
  • Proxy: Used for intermediate values during optimizations.
  • Hole: A metavariable filled in by the type inference (always mutable as 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()
bool is_set() const
Yields true if empty or the last op is set.
Definition def.cpp:308
Defs deps() const noexcept
Definition def.cpp:514
constexpr auto ops() const noexcept
Definition def.h:317
const Def * op(size_t i) const noexcept
Definition def.h:320
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition def.cpp:491
constexpr size_t num_ops() const noexcept
Definition def.h:321
Attention
This means that any subclass of Def must not introduce additional members.
See also
Immutables vs. Mutables

Definition at line 261 of file def.h.

Member Enumeration Documentation

◆ Cmp

enum class mim::Def::Cmp
strong
Enumerator

Less.

Greater.

Equal.

Unknown.

Definition at line 666 of file def.h.

Constructor & Destructor Documentation

◆ Def() [1/4]

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

Constructor for an immutable Def.

Definition at line 24 of file def.cpp.

References flags(), flags_, mim::hash_begin(), mim::hash_combine(), node(), op(), ops(), type(), mim::Univ, vars(), World, and world().

◆ Def() [2/4]

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

As above but World retrieved from type.

Definition at line 71 of file def.cpp.

References flags(), ops(), and type().

◆ Def() [3/4]

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

Constructor for a mutable Def.

Definition at line 74 of file def.cpp.

References flags(), flags_, gid(), mim::hash(), mim::World::next_gid(), node(), num_ops(), type(), and world().

◆ Def() [4/4]

mim::Def::Def ( Node node,
Def * binder )
protected

Constructor for a Var; stores its binder.

Definition at line 90 of file def.cpp.

References flags_, gid(), mim::hash_begin(), mim::hash_combine(), node(), mim::Var, and world().

◆ ~Def()

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

References World.

Member Function Documentation

◆ arity()

const Def * mim::Def::arity ( ) const
virtual

◆ as_imm()

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

Definition at line 522 of file def.h.

References as_mut().

◆ as_mut()

◆ check() [1/2]

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

After all Def::ops have been Def::set, this method will be invoked to check the type of this mutable.

The method returns a possibly updated version of its type (e.g. where Holes have been resolved). If different from Def::type, it will update its Def::type to a Def::zonked version of that.

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

Definition at line 634 of file def.h.

References type().

Referenced by set(), and set().

◆ check() [2/2]

virtual const Def * mim::Def::check ( size_t i,
const Def * def )
inlinevirtual

Checks whether the ith operand can be set to def.

The method returns a possibly updated version of def (e.g. where Holes have been resolved). This is the actual def that will be set as the ith operand.

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

Definition at line 629 of file def.h.

◆ cmp()

Def::Cmp mim::Def::cmp ( const Def * a,
const Def * b )
staticnodiscard

◆ dbg()

◆ debug_prefix()

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

Definition at line 543 of file def.cpp.

References dbg_, sym(), and world().

◆ debug_suffix()

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

Definition at line 544 of file def.cpp.

References dbg_, sym(), and world().

◆ dep() [1/2]

Dep mim::Def::dep ( ) const
inlinenoexcept

Definition at line 369 of file def.h.

Referenced by has_dep().

◆ dep() [2/2]

const Def * mim::Def::dep ( size_t i) const
inlinenoexcept

Definition at line 355 of file def.h.

References dep(), and deps().

Referenced by dep().

◆ deps()

◆ dirty()

void mim::Def::dirty ( bool dirty = true)
inlinenoexcept

Definition at line 512 of file def.h.

References dirty().

Referenced by dirty().

◆ dot() [1/3]

void mim::Def::dot ( const char * file = nullptr,
DotConfig cfg = {} ) const

Same as above but write to file or std::cout if file is nullptr.

Definition at line 204 of file dot.cpp.

References dot().

◆ dot() [2/3]

void mim::Def::dot ( const std::string & file,
DotConfig cfg = {} ) const
inline

Definition at line 683 of file def.h.

◆ dot() [3/3]

void mim::Def::dot ( std::ostream & os,
DotConfig cfg = {} ) const

Definition at line 202 of file dot.cpp.

References mim::DotConfig::max.

Referenced by dot().

◆ dump() [1/2]

void mim::Def::dump ( ) const

Definition at line 549 of file dump.cpp.

◆ dump() [2/2]

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

Definition at line 550 of file dump.cpp.

References stream().

◆ expect_mut()

template<class T = Def, class... Args>
T * mim::Def::expect_mut ( std::format_string< Args... > fmt,
Args &&... args ) const
inline

Like Def::as_mut but - instead of merely asserting in Debug builds - throws via fe::throwf when the cast fails; the mutable counterpart of fe::RuntimeCast::expect (which Def inherits for the general case).

fmt / args describe what was expected; a plain string works, as does a format string plus arguments.

Definition at line 548 of file def.h.

References isa_mut().

◆ externalize()

void mim::Def::externalize ( )

◆ flags()

◆ free_vars() [1/2]

Vars mim::Def::free_vars ( )

As above but drives (and caches) the fixed-point iteration for mutables.

Definition at line 360 of file def.cpp.

References free_vars(), and world().

◆ free_vars() [2/2]

Vars mim::Def::free_vars ( ) const

Global set of free Vars: extends local_vars() by transitively following mutables as well.

Note
On a mutable this simply forwards to the caching non-const overload below.

Definition at line 347 of file def.cpp.

References isa_mut(), local_muts(), local_vars(), vars(), mim::World::vars(), and world().

Referenced by cmp(), mim::Nest::contains(), free_vars(), is_closed(), mim::Rule::is_in_rule(), is_open(), mim::plug::cps::Conv::map(), nests(), and outermost_binder().

◆ gid()

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

◆ greater()

bool mim::Def::greater ( const Def * a,
const Def * b )
staticnodiscard

◆ has_dep() [1/2]

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

Definition at line 370 of file def.h.

Referenced by needs_zonk().

◆ has_dep() [2/2]

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

Definition at line 371 of file def.h.

References dep().

◆ 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 445 of file def.h.

References has_var().

Referenced by mim::Lam::eta_reduce(), has_var(), has_var(), is_immutabilizable(), nests(), nests(), mim::VarRewriter::rewrite_mut(), and mim::Rewriter::rewrite_mut_Seq().

◆ has_var() [2/2]

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

As above if this is a mutable.

Definition at line 447 of file def.h.

References has_var(), and isa_mut().

◆ hash()

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

Definition at line 285 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, mim::Rule, and mim::Sigma.

Definition at line 607 of file def.h.

Referenced by mim::Zonker::rewire_mut(), and mim::Rewriter::rewrite_stub().

◆ internalize()

void mim::Def::internalize ( )

Definition at line 618 of file def.cpp.

References mim::World::externals(), mim::World::Externals::internalize(), and world().

Referenced by mim::optimize(), and transfer_external().

◆ is_annex()

bool mim::Def::is_annex ( ) const
inlinenoexcept

Definition at line 504 of file def.h.

Referenced by mim::plug::cps::convertible(), and mim::isa_optimizable().

◆ is_closed()

◆ is_dirty()

bool mim::Def::is_dirty ( ) const
inlinenoexcept

Definition at line 511 of file def.h.

◆ is_elim()

bool mim::Def::is_elim ( ) const
inlinenoexcept

Definition at line 297 of file def.h.

References mim::Elim, and judge().

◆ is_external()

◆ is_form()

bool mim::Def::is_form ( ) const
inlinenoexcept

Definition at line 295 of file def.h.

References mim::Form, is_form(), and judge().

Referenced by is_form().

◆ is_immutabilizable()

◆ is_intro()

bool mim::Def::is_intro ( ) const
inlinenoexcept

Definition at line 296 of file def.h.

References mim::Intro, and judge().

Referenced by mim::Rewriter::rewrite_imm_Seq(), and mim::Rewriter::rewrite_mut_Seq().

◆ is_meta()

bool mim::Def::is_meta ( ) const
inlinenoexcept

Definition at line 298 of file def.h.

References judge(), and mim::Meta.

◆ is_mutable()

bool mim::Def::is_mutable ( ) const
inlinenoexcept

Definition at line 518 of file def.h.

◆ is_open()

bool mim::Def::is_open ( ) const

◆ is_set()

◆ is_term()

bool mim::Def::is_term ( ) const

Is this Def a term, i.e. is its type() a Type?

Definition at line 531 of file def.cpp.

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

◆ isa_binder()

template<class D = Def>
std::pair< D *, const Var * > mim::Def::isa_binder ( ) const
inline

Is this a mutable that introduces a Var?

Returns
{nullptr, nullptr} otherwise.

Definition at line 455 of file def.h.

References isa_mut(), and var().

Referenced by mim::Hole::tuplefy().

◆ isa_imm()

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

◆ isa_mut()

◆ judge()

Judge mim::Def::judge ( ) const
noexcept

Definition at line 521 of file def.cpp.

References CODE, MIM_NODE, and node().

Referenced by is_elim(), is_form(), is_intro(), and is_meta().

◆ less()

bool mim::Def::less ( const Def * a,
const Def * b )
staticnodiscard

Definition at line 593 of file def.cpp.

◆ 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 342 of file def.cpp.

References isa_mut().

Referenced by free_vars(), is_closed(), needs_zonk(), and mim::VarRewriter::rewrite().

◆ local_vars()

Vars mim::Def::local_vars ( ) const

Vars reachable by following immutable deps().

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

Definition at line 358 of file def.cpp.

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

◆ mark()

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

Used internally by free_vars().

Definition at line 284 of file def.h.

◆ needs_zonk()

bool mim::Def::needs_zonk ( ) const

Yields true, if Def::local_muts() contain a Hole that is set.

Rewriting (Def::zonking) will resolve the Hole to its operand.

Definition at line 12 of file check.cpp.

References has_dep(), mim::Hole, mim::Hole::isa_set(), and local_muts().

Referenced by mim::Zonker::rewrite(), and zonk().

◆ nests() [1/2]

bool mim::Def::nests ( const Def * def)

Does this nest def?

Also strict: a def that only uses this's own Var sits at this's level and is not nested.

Definition at line 464 of file def.cpp.

References free_vars(), has_var(), isa_mut(), and nests().

◆ nests() [2/2]

bool mim::Def::nests ( Def * mut)

Does this nest mut?

The relation is strict: f->nests(f) is false.

Definition at line 456 of file def.cpp.

References has_var(), and nests().

Referenced by nests(), and nests().

◆ node()

◆ node_name()

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

Definition at line 504 of file def.cpp.

References CODE, MIM_NODE, and node().

Referenced by mim::plug::autodiff::phase::Eval::augment_().

◆ num_deps()

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

Definition at line 356 of file def.h.

References deps().

◆ num_ops()

◆ num_projs()

◆ num_tprojs()

nat_t mim::Def::num_tprojs ( ) const

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

Definition at line 630 of file def.cpp.

References arity(), mim::World::flags(), mim::Lit::isa(), mim::Flags::scalarize_threshold, and world().

Referenced by tproj(), and tprojs().

◆ num_tvars()

nat_t mim::Def::num_tvars ( )
inlinenoexcept

Definition at line 441 of file def.h.

References var(), and var_type().

Referenced by mim::plug::ll::Emitter::emit_phi_args(), and mim::Scalarize::rewrite_mut_Lam().

◆ num_vars()

◆ op()

◆ ops()

◆ outermost_binder()

Def * mim::Def::outermost_binder ( ) const

Transitively walks up free_vars() till the outermoust binder has been found.

Returns
nullptr, if is_closed() and not a mutable.

Definition at line 441 of file def.cpp.

References free_vars(), is_closed(), and isa_mut().

◆ proj() [1/2]

◆ proj() [2/2]

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

As above but takes Def::num_projs as arity.

Definition at line 396 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 425 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 402 of file def.h.

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

Referenced by mim::plug::autodiff::phase::Eval::augment_app(), mim::plug::autodiff::phase::Eval::augment_tuple(), mim::sexpr::Emitter::emit_var(), mim::plug::mem::mem_def(), mim::plug::core::normalize_abs(), mim::plug::autodiff::normalize_add(), mim::plug::math::normalize_arith(), mim::plug::core::normalize_bit2(), mim::plug::tensor::normalize_broadcast(), mim::plug::buffer::normalize_Buf(), mim::plug::tuple::normalize_cat(), mim::plug::vec::normalize_cat(), mim::plug::refly::normalize_check(), mim::plug::math::normalize_cmp(), mim::plug::ord::normalize_contains(), mim::plug::tuple::normalize_contains(), mim::plug::refly::normalize_dbg(), mim::plug::vec::normalize_diff(), mim::plug::core::normalize_div(), mim::plug::refly::normalize_equiv(), mim::plug::core::normalize_extrema(), mim::plug::math::normalize_extrema(), mim::plug::vec::normalize_fold(), mim::plug::ord::normalize_get(), mim::plug::tensor::normalize_get(), mim::plug::core::normalize_icmp(), mim::plug::ord::normalize_insert(), 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::buffer::normalize_read(), mim::plug::refly::normalize_refine(), mim::plug::tensor::normalize_set(), mim::plug::buffer::normalize_shape(), mim::plug::core::normalize_shr(), mim::plug::mem::normalize_store(), mim::plug::autodiff::normalize_sum(), mim::plug::core::normalize_wrap(), mim::plug::tuple::normalize_zip(), mim::plug::clos::phase::LowerTypedClos::rewrite(), mim::plug::affine::phase::LowerIndex::rewrite_imm_App(), mim::plug::buffer::LowerPtr::rewrite_imm_App(), and mim::plug::matrix::phase::LowerMatrixMediumLevel::rewrite_imm_App().

◆ projs() [3/4]

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

Definition at line 431 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 420 of file def.h.

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

◆ rebuild() [1/2]

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

Definition at line 603 of file def.h.

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

Referenced by rebuild().

◆ rebuild() [2/2]

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

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

Definition at line 599 of file def.h.

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

Referenced by refine(), and mim::plug::clos::phase::LowerTypedClos::rewrite().

◆ rebuild_()

◆ reduce()

template<size_t N = std::dynamic_extent>
auto mim::Def::reduce ( const Def * arg) const
inlineconstexpr

◆ reduction_offset()

virtual constexpr size_t mim::Def::reduction_offset ( ) const
inlineconstexprvirtualnoexcept

First Def::op that needs to be dealt with during reduction; e.g.

for a Pi we don't reduce the Pi::dom.

See also
World::reduce

Reimplemented in mim::Arr, mim::Bound, mim::Lam, mim::Pack, mim::Pi, mim::Rule, and mim::Sigma.

Definition at line 620 of file def.h.

◆ refine()

const Def * mim::Def::refine ( size_t i,
const Def * new_op ) const

◆ set() [1/14]

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

Definition at line 577 of file def.h.

References set().

◆ set() [2/14]

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

Definition at line 576 of file def.h.

References set().

◆ set() [3/14]

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

Set ops all at once (no Def::unset necessary beforehand).

Definition at line 253 of file def.cpp.

References check(), gid(), num_ops(), ops(), and world().

◆ set() [4/14]

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

Definition at line 567 of file def.h.

References dbg_.

◆ set() [5/14]

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

Definition at line 566 of file def.h.

References dbg_.

◆ set() [6/14]

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

Definition at line 575 of file def.h.

References set(), and sym().

◆ set() [7/14]

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

Definition at line 574 of file def.h.

References set(), and sym().

◆ set() [8/14]

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

Definition at line 573 of file def.h.

References set().

◆ set() [9/14]

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

Definition at line 572 of file def.h.

References set().

◆ set() [10/14]

◆ set() [11/14]

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

Definition at line 571 of file def.h.

References set(), and sym().

◆ set() [12/14]

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

Definition at line 570 of file def.h.

References set(), and sym().

◆ set() [13/14]

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

Definition at line 569 of file def.h.

References dbg_.

◆ set() [14/14]

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

Definition at line 568 of file def.h.

References dbg_.

◆ set_type()

Def * mim::Def::set_type ( const Def * type)

Update type.

Warning
Only make type-preserving updates such as removing Holes. Do this even before updating all other ops()!

Definition at line 293 of file def.cpp.

References type().

Referenced by mim::Zonker::rewire_mut().

◆ stream()

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

Definition at line 529 of file dump.cpp.

References world().

Referenced by dump(), and write().

◆ stub() [1/2]

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

Definition at line 596 of file def.h.

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

Referenced by stub().

◆ stub() [2/2]

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

Definition at line 595 of file def.h.

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

Referenced by mim::Seq::stub().

◆ stub_()

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

Reimplemented in mim::Arr, mim::Global, mim::Hole, mim::Lam, mim::Pack, mim::Pi, mim::Rule, and mim::Sigma.

Definition at line 697 of file def.h.

References World.

Referenced by stub().

◆ sym() [1/4]

◆ sym() [2/4]

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

Definition at line 479 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 481 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 480 of file def.cpp.

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

◆ tid()

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

Trie id - only used in Trie.

Definition at line 283 of file def.h.

◆ tproj()

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

As above but takes Def::num_tprojs.

Definition at line 397 of file def.h.

References num_tprojs(), and proj().

◆ tprojs() [1/2]

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

Definition at line 428 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 415 of file def.h.

References num_tprojs(), and projs().

◆ transfer_external()

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

Definition at line 620 of file def.cpp.

References externalize(), internalize(), and sym().

◆ tvar()

const Def * mim::Def::tvar ( nat_t i)
inlinenoexcept

Definition at line 441 of file def.h.

Referenced by mim::Scalarize::rewrite_mut_Lam().

◆ tvars() [1/2]

auto mim::Def::tvars ( )
inlinenoexcept

Definition at line 441 of file def.h.

◆ tvars() [2/2]

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

Definition at line 441 of file def.h.

◆ type()

const Def * mim::Def::type ( ) const
noexcept

Yields the "raw" type of this Def (maybe nullptr).

See also
Def::unfold_type.

Definition at line 491 of file def.cpp.

References var().

Referenced by mim::World::app(), arity(), mim::Pack::arity(), mim::Checker::assignable(), mim::plug::autodiff::phase::Eval::augment_(), mim::plug::autodiff::phase::Eval::augment_app(), mim::plug::autodiff::phase::Eval::augment_extract(), mim::plug::autodiff::phase::Eval::augment_pack(), mim::plug::autodiff::phase::Eval::augment_tuple(), mim::Bound::Bound(), mim::App::callee_type(), mim::Arr::check(), check(), mim::Lam::check(), mim::Pi::check(), mim::Reform::check(), mim::Rule::check(), mim::Sigma::check(), mim::plug::clos::clos_pack(), cmp(), mim::plug::tensor::phase::compose_map(), mim::plug::tensor::phase::counting_for(), Def(), Def(), Def(), mim::sexpr::Emitter::emit_bb(), mim::sexpr::Emitter::emit_node(), mim::plug::clos::ClosLit::env_type(), mim::Idx::expect_bitwidth(), mim::Ext::Ext(), mim::Bound::find(), mim::plug::ll::find_common_simd_src(), mim::plug::clos::ClosLit::fnc_type(), mim::Bound::get(), mim::World::implicit_app(), mim::Axm::infer_curry_and_trip(), mim::World::insert(), is_term(), mim::is_unit(), mim::plug::clos::ClosLit::isa_clos_lit, mim::plug::mem::isa_mem(), mim::plug::ll_nvptx::HostEmitter::isa_targetspecific_intrinsic(), mim::World::match(), mim::plug::mem::mem_def(), mim::plug::core::normalize_bitcast(), mim::plug::core::normalize_conv(), mim::plug::math::normalize_conv(), mim::plug::tensor::normalize_get(), mim::plug::tensor::normalize_set(), mim::plug::tensor::normalize_shape(), mim::plug::refly::normalize_type(), mim::plug::core::op(), mim::plug::cps::op_cps2ds_dep(), mim::plug::mem::op_lea(), mim::plug::mem::op_lea_unsafe(), mim::optimize(), mim::Pi::Pi(), mim::Pi::Pi(), mim::plug::mem::pointee(), mim::plug::ll_nvptx::DeviceEmitter::prepare(), proj(), rebuild(), rebuild(), mim::Axm::rebuild_(), rebuild_(), refine(), mim::Reform::Reform(), mim::Zonker::rewire_mut(), mim::plug::clos::phase::LowerTypedClos::rewrite(), mim::plug::clos::phase::ClosConvPrep::rewrite_imm_App(), mim::plug::mem::phase::AddMem::rewrite_imm_App(), mim::plug::tensor::phase::LowerToMem::rewrite_imm_App(), mim::Scalarize::rewrite_mut_Lam(), mim::Rewriter::rewrite_mut_Seq(), mim::Scheduler::Scheduler(), mim::World::seq(), set(), set_type(), mim::plug::mem::strip_mem(), mim::Arr::stub(), stub(), stub(), mim::Hole::stub(), mim::Pack::stub(), mim::Pi::stub(), mim::Seq::stub(), mim::Sigma::stub(), mim::Hole::tuplefy(), mim::Global::type(), mim::Lam::type(), mim::plug::clos::ClosLit::type(), mim::Rule::type(), mim::World::type(), unfold_type(), mim::World::uniq(), world(), and mim::Bound::~Bound().

◆ unfold_type()

const Def * mim::Def::unfold_type ( ) const

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

Definition at line 496 of file def.cpp.

References type(), and world().

Referenced by mim::Arr::check(), mim::World::seq(), and mim::World::uniq().

◆ unique_name()

◆ unset()

Def * mim::Def::unset ( )

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

Definition at line 299 of file def.cpp.

References num_ops().

Referenced by mim::Zonker::rewire_mut(), mim::Arr::unset(), mim::Hole::unset(), mim::Lam::unset(), mim::Pack::unset(), mim::Pi::unset(), mim::Reform::unset(), mim::Rule::unset(), mim::Seq::unset(), and mim::Sigma::unset().

◆ users()

Muts mim::Def::users ( )
inline

Set of mutables where this mutable is locally referenced.

Definition at line 482 of file def.h.

◆ var() [1/3]

const Def * mim::Def::var ( )

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

Definition at line 320 of file def.cpp.

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

Referenced by mim::Lam::ret_var().

◆ var() [2/3]

◆ var() [3/3]

const Def * mim::Def::var ( nat_t i)
inlinenoexcept

Definition at line 441 of file def.h.

◆ var_type()

const Def * mim::Def::var_type ( )

If this is a binder, compute the type of its Variable.

Definition at line 325 of file def.cpp.

References arity(), and world().

Referenced by num_tvars(), mim::Var::type(), and mim::World::var().

◆ vars() [1/4]

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

Definition at line 441 of file def.h.

◆ 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 441 of file def.h.

◆ vars() [4/4]

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

Definition at line 441 of file def.h.

◆ world()

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

Definition at line 483 of file def.cpp.

References type(), var(), and World.

Referenced by mim::Checker::alpha(), mim::Lam::app(), mim::Lam::app(), mim::plug::clos::apply_closure(), arity(), mim::Pack::arity(), mim::Sigma::arity(), mim::plug::autodiff::autodiff_type_fun(), mim::plug::autodiff::autodiff_type_fun_pi(), mim::Lam::branch(), mim::cat_sigma(), mim::cat_tuple(), mim::Lam::check(), mim::Rule::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::tensor::phase::counting_for(), mim::Phase::create(), debug_prefix(), debug_suffix(), Def(), Def(), Def(), externalize(), free_vars(), free_vars(), mim::plug::autodiff::id_pullback(), mim::Arr::immutabilize(), mim::Pack::immutabilize(), mim::Pi::immutabilize(), mim::Sigma::immutabilize(), mim::Tuple::infer(), internalize(), mim::is_unit(), mim::plug::clos::isa_clos_type(), mim::plug::mem::mut_con(), mim::plug::compile::normalize_aggr(), mim::plug::core::normalize_bitcast(), mim::plug::buffer::normalize_Buf(), mim::plug::compile::normalize_cond(), mim::plug::ord::normalize_contains(), mim::plug::core::normalize_conv(), mim::plug::math::normalize_conv(), mim::plug::core::normalize_div(), mim::plug::ord::normalize_get(), mim::plug::refly::normalize_gid(), mim::plug::core::normalize_idx_unsafe(), mim::plug::compile::normalize_is_loaded(), num_tprojs(), mim::plug::core::op(), mim::plug::cps::op_cps2ds_dep(), mim::plug::tensor::op_get(), mim::plug::mem::op_lea(), mim::plug::mem::op_lea_unsafe(), mim::plug::mem::op_lea_unsafe(), mim::plug::tensor::op_set(), mim::plug::autodiff::op_sum(), operator<<, proj(), mim::plug::autodiff::pullback_type(), rebuild(), mim::Axm::rebuild_(), mim::Lam::reduce(), mim::Rule::replace(), set(), set(), mim::Lam::set(), mim::Pi::set_dom(), mim::Lam::set_filter(), stream(), mim::plug::mem::strip_mem(), mim::plug::mem::strip_mem_ty(), mim::Arr::stub(), stub(), mim::Global::stub(), mim::Hole::stub(), mim::Lam::stub(), mim::Pack::stub(), mim::Pi::stub(), mim::Rule::stub(), mim::Sigma::stub(), sym(), sym(), sym(), mim::tuple2str(), mim::Hole::tuplefy(), unfold_type(), var(), var_type(), mim::plug::autodiff::zero_def(), mim::plug::autodiff::zero_pullback(), zonk(), and zonk_mut().

◆ write() [1/2]

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

Definition at line 557 of file dump.cpp.

References write().

Referenced by write().

◆ write() [2/2]

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

Definition at line 552 of file dump.cpp.

References stream().

◆ zonk() [1/2]

◆ zonk() [2/2]

DefVec mim::Def::zonk ( Defs defs)
static

zonks all defs and returns a new DefVec.

Definition at line 42 of file check.cpp.

◆ zonk_mut()

const Def * mim::Def::zonk_mut ( ) const

If mutable, zonk()s all ops and tries to immutabilize it; otherwise just zonk.

Definition at line 23 of file check.cpp.

References deps(), is_set(), isa_mut(), op(), mim::Zonker::rewire_mut(), world(), zonk(), and mim::World::zonker().

◆ 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 520 of file dump.cpp.

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

◆ Sets

template<class D, size_t N>
friend class Sets
friend

Definition at line 745 of file def.h.

References Sets.

Referenced by Sets.

◆ swap

void swap ( World & ,
World &  )
friend

References World.

◆ World

friend class World
friend

Definition at line 746 of file def.h.

References World.

Referenced by Def(), proj(), rebuild(), rebuild_(), stub(), mim::Seq::stub(), stub_(), swap, World, world(), and ~Def().

Member Data Documentation

◆ [union]

union { ... } mim::Def

◆ curry_

u8 mim::Def::curry_ = 0
protected

Definition at line 722 of file def.h.

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

◆ dbg_

Dbg mim::Def::dbg_
mutableprotected

Definition at line 713 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

◆ trip_

u8 mim::Def::trip_ = 0
protected

Definition at line 723 of file def.h.

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


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