MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::Pi Class Reference

A dependent function type. More...

#include <mim/lam.h>

Inheritance diagram for mim::Pi:
[legend]

Public Member Functions

Get/Set implicit
bool is_implicit () const
Pimake_implicit ()
Pimake_explicit ()
dom & codom

See also
proj
const Def * dom () const
const Def * codom () const
Return Continuation

const Piret_pi () const
 Yields the last Pi::dom, if Pi::isa_basicblock.
const Def * ret_dom () const
 Pi::domain of Pi::ret_pi.
Setters
See also
Setting Ops
Piset (const Def *dom, const Def *codom)
Piset_dom (const Def *dom)
Piset_dom (Defs doms)
Piset_codom (const Def *codom)
Piunset ()
Rebuild
const Def * reduce (const Def *arg) const
Public Member Functions inherited from mim::Def
Worldworld () const noexcept
Driverdriver () 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
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.
Judge judge () const noexcept
 Def must never become polymorphic: a vptr costs 8 bytes on every node in the World, and Def::ops_ptr hands out the operands at this + 1, so the vptr would also shift them.
bool is_form () const noexcept
bool is_intro () const noexcept
bool is_elim () const noexcept
bool is_meta () const noexcept
const Def * type () const noexcept
 Yields the "raw" type of this Def (maybe nullptr).
const Def * unfold_type () const
 Yields the type of this Def and builds a new Type (UInc n) if necessary.
template<class T>
const T * isa_type () const
 Is Def::unfold_type a T? Yields nullptr for Univ, 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
Dep dep () const noexcept
bool has_dep () const noexcept
bool has_dep (Dep d) 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 Flags::scalarize_threshold is exceeded.
const Def * proj (nat_t a, nat_t i) const
 Similar to World::extract while assuming an arity of a, but also works on Sigmas and Arrays.
const Def * proj (nat_t i) const
 As above but takes Def::num_projs as arity.
const Def * tproj (nat_t i) const
 As above but takes Def::num_tprojs.
template<nat_t A = std::dynamic_extent, class F>
auto projs (F f) const
 Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (otherwise).
template<class F>
auto tprojs (F f) const
template<class F>
auto projs (nat_t a, F f) const
template<nat_t A = std::dynamic_extent>
auto projs () const
auto tprojs () const
auto projs (nat_t a) const
nat_t num_vars () noexcept
nat_t num_tvars () noexcept
const Def * var (nat_t a, nat_t i) noexcept
const Def * var (nat_t i) noexcept
const Def * tvar (nat_t i) noexcept
template<nat_t A = std::dynamic_extent, class F>
auto vars (F f) noexcept
template<class F>
auto tvars (F f) noexcept
template<nat_t A = std::dynamic_extent>
auto vars () noexcept
auto tvars () noexcept
template<class F>
auto vars (nat_t a, F f) noexcept
auto vars (nat_t a) noexcept
const Def * var ()
 Not necessarily a Var: E.g., if the return type is [], this will yield ().
const 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?
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 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_dirty () const noexcept
void dirty (bool dirty=true) 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 = 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 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 dump () const
void dump (int max) const
void write (int max) const
void write (int max, const char *file) const
std::ostream & stream (std::ostream &, int max) const
void dot (std::ostream &os, 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
Public Member Functions inherited from mim::Setters< Pi >
const Piset (Args &&... args) const

Static Public Member Functions

Continuations

Checks certain properties of d regarding continuations.

static const Piisa_cn (const Def *d)
static const Piisa_returning (const Def *d)
 Is this a continuation (Pi::isa_cn) which has a Pi::ret_pi?
static const Piisa_basicblock (const Def *d)
 Is this a continuation (Pi::isa_cn) that is not Pi::isa_returning?
static Piisa_implicit (const Def *d)
 Is d an Pi::is_implicit (mutable) Pi?
static const Pihas_ret_pi (const Def *d)
 Yields the Pi::ret_pi() of d, if it is in fact a Pi.
Type Checking
static const Def * infer (const Def *dom, const Def *codom)
Static Public Member Functions inherited from mim::Def
static DefVec zonk (Defs defs)
 zonks all defs and returns a new DefVec.
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)

Static Public Attributes

static constexpr auto Node = mim::Node::Pi
static constexpr size_t Num_Ops = 2

Protected Member Functions

 Pi (const Def *type, const Def *dom, const Def *codom, bool implicit)
 Constructor for an immutable Pi.
 Pi (const Def *type, bool implicit)
 Constructor for a mutable Pi.
Protected Member Functions inherited from mim::Def
 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).

Friends

class World

Additional Inherited Members

enum class  Cmp {
  L ,
  G ,
  E ,
  U
}
Protected Attributes inherited from mim::Def
union mim::Def:: { ... }  
flags_t flags_
u8 curry_ = 0
u8 trip_ = 0

Detailed Description

A dependent function type.

See also
Lam

Definition at line 14 of file lam.h.

Constructor & Destructor Documentation

◆ Pi() [1/2]

mim::Pi::Pi ( const Def * type,
const Def * dom,
const Def * codom,
bool implicit )
inlineprotected

Constructor for an immutable Pi.

Definition at line 17 of file lam.h.

References codom(), dom(), Node, and mim::Def::type().

Referenced by has_ret_pi(), isa_basicblock(), isa_cn(), isa_implicit(), isa_returning(), make_explicit(), make_implicit(), ret_pi(), set(), set_codom(), set_dom(), set_dom(), and unset().

◆ Pi() [2/2]

mim::Pi::Pi ( const Def * type,
bool implicit )
inlineprotected

Constructor for a mutable Pi.

Definition at line 20 of file lam.h.

References Node, and mim::Def::type().

Member Function Documentation

◆ codom()

◆ dom()

◆ has_ret_pi()

const Pi * mim::Pi::has_ret_pi ( const Def * d)
inlinestatic

Yields the Pi::ret_pi() of d, if it is in fact a Pi.

Definition at line 67 of file lam.h.

References Pi().

Referenced by mim::ast::RetExpr::emit_().

◆ infer()

const Def * mim::Pi::infer ( const Def * dom,
const Def * codom )
static

Definition at line 427 of file check.cpp.

References codom(), dom(), mim::UMax::Kind, mim::Def::unfold_type(), and mim::Def::world().

Referenced by mim::Def::check(), and mim::World::pi().

◆ is_implicit()

bool mim::Pi::is_implicit ( ) const
inline

Definition at line 26 of file lam.h.

References mim::Def::flags().

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

◆ isa_basicblock()

◆ isa_cn()

◆ isa_implicit()

Pi * mim::Pi::isa_implicit ( const Def * d)
inlinestatic

Is d an Pi::is_implicit (mutable) Pi?

Note
A nullptr d - Def::unfold_type of Univ - simply is not one.

Definition at line 62 of file lam.h.

References Pi().

Referenced by mim::sexpr::Emitter::emit_type(), and mim::World::implicit_app().

◆ isa_returning()

const Pi * mim::Pi::isa_returning ( const Def * d)
inlinestatic

Is this a continuation (Pi::isa_cn) which has a Pi::ret_pi?

Definition at line 51 of file lam.h.

References isa_cn(), and Pi().

Referenced by mim::plug::clos::phase::ClosConvPrep::analyze(), mim::compose_cn(), mim::plug::clos::ClosLit::is_returning(), and mim::Lam::isa_returning().

◆ make_explicit()

Pi * mim::Pi::make_explicit ( )
inline

Definition at line 28 of file lam.h.

References mim::Def::flags_, and Pi().

◆ make_implicit()

Pi * mim::Pi::make_implicit ( )
inline

Definition at line 27 of file lam.h.

References mim::Def::flags_, and Pi().

◆ reduce()

const Def * mim::Pi::reduce ( const Def * arg) const
inline

Definition at line 101 of file lam.h.

References mim::Def::reduce().

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

◆ ret_dom()

const Def * mim::Pi::ret_dom ( ) const
inline

Pi::domain of Pi::ret_pi.

Definition at line 80 of file lam.h.

References dom(), and ret_pi().

Referenced by mim::compose_cn().

◆ ret_pi()

const Pi * mim::Pi::ret_pi ( ) const

Yields the last Pi::dom, if Pi::isa_basicblock.

Definition at line 13 of file lam.cpp.

References dom(), isa_basicblock(), and Pi().

Referenced by mim::plug::ll::Emitter::emit_imported(), ret_dom(), and mim::Lam::ret_pi().

◆ set()

Pi * mim::Pi::set ( const Def * dom,
const Def * codom )
inline

◆ set_codom()

Pi * mim::Pi::set_codom ( const Def * codom)
inline

Definition at line 90 of file lam.h.

References codom(), Pi(), and mim::Def::set().

◆ set_dom() [1/2]

Pi * mim::Pi::set_dom ( const Def * dom)
inline

Definition at line 88 of file lam.h.

References dom(), Pi(), and mim::Def::set().

◆ set_dom() [2/2]

Pi * mim::Pi::set_dom ( Defs doms)

Definition at line 20 of file lam.cpp.

References Pi(), mim::Def::set(), and mim::Def::world().

◆ unset()

Pi * mim::Pi::unset ( )
inline

Definition at line 91 of file lam.h.

References Pi(), and mim::Def::unset().

◆ World

friend class World
friend

Definition at line 108 of file lam.h.

References World.

Referenced by World.

Member Data Documentation

◆ Node

auto mim::Pi::Node = mim::Node::Pi
staticconstexpr

Definition at line 104 of file lam.h.

Referenced by Pi(), and Pi().

◆ Num_Ops

size_t mim::Pi::Num_Ops = 2
staticconstexpr

Definition at line 105 of file lam.h.


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