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

A function. More...

#include <mim/lam.h>

Inheritance diagram for mim::Lam:
[legend]

Public Types

using Filter = std::variant<bool, const Def*>
enum class  Cmp {
  L ,
  G ,
  E ,
  U
}

Public Member Functions

ops
const Def * filter () const
const Def * body () const
type

See also
proj
const Pitype () const
const Def * dom () const
const Def * codom () const
Return Continuation
const Piret_pi () const
const Def * ret_dom () const
const Def * ret_var ()
 Yields the Lam::var of the Lam::ret_pi.
Setters

Lam::Filter is a std::variant<bool, const Def*> that lets you set the Lam::filter() like this:

lam1->app(true, f, arg);
lam2->app(my_filter_def, f, arg);
Note
The filter belongs to the Lambda and not the body.
See also
Setting Ops
Lam * set (Filter filter, const Def *body)
Lam * set_filter (Filter)
 Set filter first.
Lam * set_body (const Def *body)
 Set body second.
Lam * app (Filter filter, const Def *callee, const Def *arg)
 Set body to an App of callee and arg.
Lam * app (Filter filter, const Def *callee, Defs args)
 Set body to an App of callee and args.
Lam * branch (Filter filter, const Def *cond, const Def *t, const Def *f, const Def *arg=nullptr)
 Set body to an App of (f, t)#cond mem or (f, t)#cond () if mem is nullptr.
Lam * set (Defs ops)
Lam * unset ()
Rebuild
Lam * stub (const Def *type)
Defs reduce (Defs) const
const Def * reduce_body (const Def *arg) const
constexpr size_t reduction_offset () const noexcept final
 First Def::op that needs to be dealt with during reduction; e.g.
template<size_t N = std::dynamic_extent>
constexpr auto reduce (const Def *arg) const
Type Checking
const Def * check (size_t, const Def *) final
 Checks whether the ith operand can be set to def.
Public Member Functions inherited from mim::Def
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
u32 judge () const noexcept
bool is_form () const noexcept
bool is_intro () const noexcept
bool is_elim () const noexcept
bool is_meta () const noexcept
const Def * type () const noexcept
 Yields the "raw" type of this Def (maybe nullptr).
const Def * unfold_type () const
 Yields the type of this Def and builds a new Type (UInc n) if necessary.
bool is_term () const
virtual const Def * arity () const
template<size_t N = std::dynamic_extent>
constexpr auto ops () const noexcept
const Def * op (size_t i) const noexcept
constexpr size_t num_ops () const noexcept
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.
Defs deps () const noexcept
const Def * dep (size_t i) const noexcept
size_t num_deps () const noexcept
bool has_dep () const
bool has_dep (Dep d) const
bool has_dep (unsigned u) const
nat_t num_projs () const
 Yields Def::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
 Compute a global solution by transitively following mutables as well.
Vars free_vars ()
Muts users ()
 Set of mutables where this mutable is locally referenced.
bool is_open () const
 Has free_vars()?
bool is_closed () const
 Has no free_vars()?
Def * outermost_binder () const
 Transitively walks up free_vars() till the outermoust binder has been found.
bool is_external () const noexcept
void externalize ()
void internalize ()
void transfer_external (Def *to)
bool is_annex () const noexcept
bool is_mutable () const noexcept
template<class T = Def>
const T * isa_imm () const
template<class T = Def>
const T * as_imm () const
template<class T = Def, bool invert = false>
T * isa_mut () const
 If this is mutable, it will cast constness away and perform a dynamic_cast to T.
template<class T = Def, bool invert = false>
T * as_mut () const
 Asserts that this is a mutable, casts constness away and performs a static_cast to T.
Dbg dbg () const
Loc loc () const
Sym sym () const
std::string unique_name () const
 name + "_" + Def::gid
template<bool Ow = false>
const Def * set (Loc l) const
template<bool Ow = false>
Def * set (Loc l)
template<bool Ow = false>
const Def * set (Sym s) const
template<bool Ow = false>
Def * set (Sym s)
template<bool Ow = false>
const Def * set (std::string s) const
template<bool Ow = false>
Def * set (std::string s)
template<bool Ow = false>
const Def * set (Loc l, Sym s) const
template<bool Ow = false>
Def * set (Loc l, Sym s)
template<bool Ow = false>
const Def * set (Loc l, std::string s) const
template<bool Ow = false>
Def * set (Loc l, std::string s)
template<bool Ow = false>
const Def * set (Dbg d) const
template<bool Ow = false>
Def * set (Dbg d)
const Def * debug_prefix (std::string) const
const Def * debug_suffix (std::string) const
Def * stub (World &w, const Def *type)
Def * stub (const Def *type)
const Def * rebuild (World &w, const Def *type, Defs ops) const
 Def::rebuilds this Def while using new_op as substitute for its i'th Def::op.
const Def * rebuild (const Def *type, Defs ops) const
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 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, int max=std::numeric_limits< int >::max(), bool types=false) const
void dot (const char *file=nullptr, int max=std::numeric_limits< int >::max(), bool types=false) const
 Same as above but write to file or std::cout if file is nullptr.
void dot (const std::string &file, int max=std::numeric_limits< int >::max(), bool types=false) const
Public Member Functions inherited from mim::Setters< Lam >
const Lamset (Loc l) const

Static Public Member Functions

Continuations
static const Lam * isa_cn (const Def *d)
static const Lam * isa_basicblock (const Def *d)
static const Lam * isa_returning (const Def *d)
static Lam * isa_mut_cn (const Def *d)
 Only for mutables.
static Lam * isa_mut_basicblock (const Def *d)
 Only for mutables.
static Lam * isa_mut_returning (const Def *d)
 Only for mutables.
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::Lam
static constexpr size_t Num_Ops = 2

Private Member Functions

const Def * rebuild_ (World &, const Def *, Defs) const final
Lam * stub_ (World &, const Def *) final

Friends

class World

Eta-Conversion

const Def * eta_reduce () const
 Yields body(), if eta-convertible and nullptr otherwise.
static Lam * eta_expand (Filter, const Def *f)
static Lam * eta_expand (const Def *f)
 Use true Filter.

Additional Inherited Members

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.
virtual ~Def ()=default
Sym sym (const char *) const
Sym sym (std::string_view) const
Sym sym (std::string) const
Protected Attributes inherited from mim::Def
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.
Worldworld_
}; 
flags_t flags_
u8 curry_ = 0
u8 trip_ = 0

Detailed Description

A function.

See also
Pi

Definition at line 110 of file lam.h.

Member Typedef Documentation

◆ Filter

using mim::Lam::Filter = std::variant<bool, const Def*>

Definition at line 118 of file lam.h.

Member Function Documentation

◆ app() [1/2]

Lam * mim::Lam::app ( Filter filter,
const Def * callee,
const Def * arg )

Set body to an App of callee and arg.

Definition at line 30 of file lam.cpp.

References mim::World::app(), mim::World::filter(), mim::Def::set(), and mim::Def::world().

Referenced by app(), branch(), and eta_reduce().

◆ app() [2/2]

Lam * mim::Lam::app ( Filter filter,
const Def * callee,
Defs args )

Set body to an App of callee and args.

Definition at line 33 of file lam.cpp.

References app(), filter(), and mim::Def::world().

◆ body()

◆ branch()

Lam * mim::Lam::branch ( Filter filter,
const Def * cond,
const Def * t,
const Def * f,
const Def * arg = nullptr )

Set body to an App of (f, t)#cond mem or (f, t)#cond () if mem is nullptr.

Definition at line 35 of file lam.cpp.

References app(), filter(), and mim::Def::world().

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

◆ check()

const Def * mim::Lam::check ( size_t i,
const Def * def )
finalvirtual

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

Definition at line 331 of file check.cpp.

References mim::Checker::assignable(), body(), codom(), mim::Error::error(), filter(), mim::Def::loc(), mim::Error::note(), mim::Def::type(), type(), and mim::Def::world().

◆ codom()

const Def * mim::Lam::codom ( ) const
inline

Definition at line 132 of file lam.h.

References mim::Pi::codom(), and type().

Referenced by check(), and mim::plug::direct::CPS2DSPhase::start().

◆ dom()

const Def * mim::Lam::dom ( ) const
inline

Definition at line 131 of file lam.h.

References mim::Pi::dom(), and type().

◆ eta_expand() [1/2]

Lam * mim::Lam::eta_expand ( const Def * f)
inlinestatic

Use true Filter.

Definition at line 194 of file lam.h.

References eta_expand().

Referenced by eta_expand().

◆ eta_expand() [2/2]

Lam * mim::Lam::eta_expand ( Filter filter,
const Def * f )
static

◆ eta_reduce()

const Def * mim::Lam::eta_reduce ( ) const

Yields body(), if eta-convertible and nullptr otherwise.

η-convertible means: lm x = body x where xbody.

Definition at line 43 of file lam.cpp.

References app(), body(), mim::Def::has_var(), and mim::Def::var().

◆ filter()

◆ isa_basicblock()

const Lam * mim::Lam::isa_basicblock ( const Def * d)
inlinestatic

◆ isa_cn()

const Lam * mim::Lam::isa_cn ( const Def * d)
inlinestatic

Definition at line 141 of file lam.h.

References isa_cn(), and mim::Pi::isa_cn().

Referenced by mim::sexpr::Emitter::emit_head(), isa_cn(), and isa_mut_cn().

◆ isa_mut_basicblock()

Lam * mim::Lam::isa_mut_basicblock ( const Def * d)
inlinestatic

◆ isa_mut_cn()

Lam * mim::Lam::isa_mut_cn ( const Def * d)
inlinestatic

Only for mutables.

Definition at line 144 of file lam.h.

References isa_cn().

◆ isa_mut_returning()

Lam * mim::Lam::isa_mut_returning ( const Def * d)
inlinestatic

Only for mutables.

Definition at line 146 of file lam.h.

References isa_returning().

◆ isa_returning()

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

Definition at line 143 of file lam.h.

References mim::Pi::isa_returning().

Referenced by isa_mut_returning(), and mim::plug::mem::pass::CopyProp::rewrite().

◆ rebuild_()

const Def * mim::Lam::rebuild_ ( World & w,
const Def * t,
Defs o ) const
finalprivatevirtual

Implements mim::Def.

Definition at line 119 of file def.cpp.

References World.

◆ reduce() [1/2]

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

Definition at line 576 of file def.h.

◆ reduce() [2/2]

Defs mim::Lam::reduce ( Defs args) const

Definition at line 39 of file lam.cpp.

References mim::Def::reduce(), and mim::Def::world().

Referenced by mim::plug::clos::Clos2SJLJ::enter(), and reduce_body().

◆ reduce_body()

const Def * mim::Lam::reduce_body ( const Def * arg) const
inline

Definition at line 187 of file lam.h.

References reduce().

◆ reduction_offset()

size_t mim::Lam::reduction_offset ( ) const
inlineconstexprfinalvirtualnoexcept

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

Definition at line 188 of file lam.h.

◆ ret_dom()

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

Definition at line 154 of file lam.h.

References mim::Pi::dom(), and ret_pi().

◆ ret_pi()

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

Definition at line 153 of file lam.h.

References mim::Pi::ret_pi(), and type().

Referenced by ret_dom().

◆ ret_var()

const Def * mim::Lam::ret_var ( )
inline

◆ set() [1/2]

Lam * mim::Lam::set ( Defs ops)
inline

Definition at line 178 of file lam.h.

References mim::Def::ops(), and mim::Def::set().

◆ set() [2/2]

◆ set_body()

Lam * mim::Lam::set_body ( const Def * body)
inline

Set body second.

Definition at line 171 of file lam.h.

References body(), and mim::Def::set().

◆ set_filter()

Lam * mim::Lam::set_filter ( Filter filter)

Set filter first.

Definition at line 28 of file lam.cpp.

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

◆ stub()

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

Definition at line 184 of file lam.h.

References mim::Def::dbg(), set(), stub_(), type(), and mim::Def::world().

◆ stub_()

Lam * mim::Lam::stub_ ( World & w,
const Def * t )
finalprivatevirtual

Reimplemented from mim::Def.

Definition at line 153 of file def.cpp.

References World.

Referenced by stub().

◆ type()

◆ unset()

Lam * mim::Lam::unset ( )
inline

Definition at line 179 of file lam.h.

References mim::Def::unset().

Referenced by mim::plug::clos::Clos2SJLJ::enter().

◆ World

friend class World
friend

Definition at line 212 of file lam.h.

References World.

Referenced by rebuild_(), stub_(), and World.

Member Data Documentation

◆ Node

auto mim::Lam::Node = mim::Node::Lam
staticconstexpr

Definition at line 205 of file lam.h.

◆ Num_Ops

size_t mim::Lam::Num_Ops = 2
staticconstexpr

Definition at line 206 of file lam.h.


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