MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::plug::clos Namespace Reference

The clos Plugin More...

Namespaces

namespace  phase

Classes

class  ClosLit
 Lightweight, non-owning view onto a closure literal (env_type, fn, env); see isa_clos_lit. More...

Enumerations

%clos.BufPtr
enum class  BufPtr : flags_t
%clos.alloc_jmpbuf
enum class  alloc_jmpbuf : flags_t
%clos.setjmp
enum class  setjmp : flags_t
%clos.longjmp
enum class  longjmp : flags_t
%clos.clos_conv_prep
enum class  clos_conv_prep : flags_t
%clos.clos_conv
enum class  clos_conv : flags_t
%clos.branch_clos
enum class  branch_clos : flags_t
%clos.lower_typed_clos_prep
enum class  lower_typed_clos_prep : flags_t
%clos.clos2sjlj
enum class  clos2sjlj : flags_t
%clos.lower_typed_clos
enum class  lower_typed_clos : flags_t

Functions

void register_normalizers (Normalizers &normalizers)
Closures
ClosLit isa_clos_lit (const Def *def, bool fn_isa_lam=true)
 Tries to match a closure literal.
const Defclos_pack (const Def *env, const Def *fn, const Def *ct=nullptr)
 Pack a typed closure.
std::tuple< const Def *, const Def *, const Def * > clos_unpack (const Def *c)
 Deconstruct a closure into (env_type, function, env).
const Defclos_apply (const Def *closure, const Def *args)
 Apply a closure to arguments.
const Defapply_closure (const Def *closure, Defs args)
template<class N>
std::tuple< const Extract *, N * > isa_var_proj (const Def *def)
 If def is a projection var#i of the Var of some mutable of type N, returns (projection, binder).
Closure Types
const Sigmaisa_clos_type (const Def *def)
Sigmaclos_type (const Pi *pi)
 Creates a typed closure type from pi.
const Piclos_type_to_pi (const Def *ct, const Def *new_env_type=nullptr)
 Convert a closure type to a Pi, where the environment type has been removed or replaced by new_env_type (if new_env_type != nullptr).
Closure Environment
size_t env_param (Defs doms)
 Describes where the environment is placed in the argument list: right after a leading mem.M, if doms starts with one, or in slot 0 otherwise.
size_t env_param (const Pi *pi)
size_t shift_env (size_t ep, size_t i)
 Adjust the index of an argument to account for the env param.
size_t skip_env (size_t ep, size_t i)
 Same as shift_env, but skips the env param instead.
const Defctype (World &w, Defs doms, const Def *env_type=nullptr)
 Builds a closure type from the domains doms of a Cn.
const Defclos_insert_env (size_t ep, size_t i, const Def *env, std::function< const Def *(size_t)> f)
const Defclos_insert_env (size_t ep, size_t i, const Def *env, const Def *a)
const Defclos_insert_env (size_t ep, const Def *env, const Def *tup_or_sig)
const Defclos_remove_env (size_t ep, size_t i, std::function< const Def *(size_t)> f)
const Defclos_remove_env (size_t ep, size_t i, const Def *def)
const Defclos_remove_env (size_t ep, const Def *tup_or_sig)
const Defclos_sub_env (size_t ep, const Def *tup_or_sig, const Def *new_env)

Variables

static constexpr plugin_t Plugin_Id = 0x10d4140000000000

%clos.attr

enum class  attr : flags_t {
  returning = 0x10d4140000000400 ,
  free_bb = 0x10d4140000000401 ,
  fstclass_bb = 0x10d4140000000402 ,
  esc = 0x10d4140000000403 ,
  bottom = 0x10d4140000000404
}
template<attr o>
const Defnormalize_clos (const Def *, const Def *, const Def *arg)

Detailed Description

Enumeration Type Documentation

◆ alloc_jmpbuf

Definition at line 21 of file autogen.h.

◆ attr

enum class mim::plug::clos::attr : flags_t
strong
Enumerator
returning 
free_bb 
fstclass_bb 
esc 
bottom 

Definition at line 42 of file autogen.h.

◆ branch_clos

Definition at line 71 of file autogen.h.

◆ BufPtr

enum class mim::plug::clos::BufPtr : flags_t
strong

Definition at line 14 of file autogen.h.

◆ clos2sjlj

enum class mim::plug::clos::clos2sjlj : flags_t
strong

Definition at line 85 of file autogen.h.

◆ clos_conv

enum class mim::plug::clos::clos_conv : flags_t
strong

Definition at line 64 of file autogen.h.

◆ clos_conv_prep

Definition at line 57 of file autogen.h.

◆ longjmp

enum class mim::plug::clos::longjmp : flags_t
strong

Definition at line 35 of file autogen.h.

◆ lower_typed_clos

Definition at line 92 of file autogen.h.

◆ lower_typed_clos_prep

Definition at line 78 of file autogen.h.

◆ setjmp

enum class mim::plug::clos::setjmp : flags_t
strong

Definition at line 28 of file autogen.h.

Function Documentation

◆ apply_closure()

const Def * mim::plug::clos::apply_closure ( const Def * closure,
Defs args )
inline

Definition at line 65 of file clos.h.

References clos_apply(), mim::World::tuple(), and mim::Def::world().

◆ clos_apply()

const Def * mim::plug::clos::clos_apply ( const Def * closure,
const Def * args )

Apply a closure to arguments.

Definition at line 76 of file clos.cpp.

References clos_unpack(), env_param(), and mim::Def::world().

Referenced by apply_closure(), and mim::plug::clos::phase::ClosConv::rewrite_imm_App().

◆ clos_insert_env() [1/3]

const Def * mim::plug::clos::clos_insert_env ( size_t ep,
const Def * env,
const Def * tup_or_sig )
inline

Definition at line 119 of file clos.h.

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

◆ clos_insert_env() [2/3]

const Def * mim::plug::clos::clos_insert_env ( size_t ep,
size_t i,
const Def * env,
const Def * a )
inline

Definition at line 115 of file clos.h.

References clos_insert_env().

◆ clos_insert_env() [3/3]

const Def * mim::plug::clos::clos_insert_env ( size_t ep,
size_t i,
const Def * env,
std::function< const Def *(size_t)> f )

Definition at line 118 of file clos.cpp.

References shift_env().

Referenced by clos_insert_env().

◆ clos_pack()

const Def * mim::plug::clos::clos_pack ( const Def * env,
const Def * fn,
const Def * ct = nullptr )

Pack a typed closure.

This assumes that fn expects the environment at its env_param()th argument.

Definition at line 59 of file clos.cpp.

References clos_remove_env(), clos_type(), mim::Pi::dom(), env_param(), isa_clos_type(), mim::Def::type(), and mim::Def::world().

Referenced by mim::plug::clos::phase::LowerTypedClosPrep::rewrite_imm_Tuple(), and mim::plug::clos::phase::ClosConv::rewrite_mut_Lam().

◆ clos_remove_env() [1/3]

const Def * mim::plug::clos::clos_remove_env ( size_t ep,
const Def * tup_or_sig )
inline

Definition at line 129 of file clos.h.

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

◆ clos_remove_env() [2/3]

const Def * mim::plug::clos::clos_remove_env ( size_t ep,
size_t i,
const Def * def )
inline

Definition at line 126 of file clos.h.

References clos_remove_env(), and mim::Def::proj().

◆ clos_remove_env() [3/3]

const Def * mim::plug::clos::clos_remove_env ( size_t ep,
size_t i,
std::function< const Def *(size_t)> f )

◆ clos_sub_env()

const Def * mim::plug::clos::clos_sub_env ( size_t ep,
const Def * tup_or_sig,
const Def * new_env )
inline

Definition at line 135 of file clos.h.

References mim::Def::refine().

Referenced by clos_type_to_pi().

◆ clos_type()

Sigma * mim::plug::clos::clos_type ( const Pi * pi)

Creates a typed closure type from pi.

Definition at line 99 of file clos.cpp.

References mim::Def::as_mut(), ctype(), and mim::Def::world().

Referenced by clos_pack().

◆ clos_type_to_pi()

const Pi * mim::plug::clos::clos_type_to_pi ( const Def * ct,
const Def * new_env_type = nullptr )

Convert a closure type to a Pi, where the environment type has been removed or replaced by new_env_type (if new_env_type != nullptr).

Definition at line 105 of file clos.cpp.

References clos_remove_env(), clos_sub_env(), mim::Pi::dom(), env_param(), isa_clos_type(), mim::Def::op(), and mim::Def::world().

◆ clos_unpack()

std::tuple< const Def *, const Def *, const Def * > mim::plug::clos::clos_unpack ( const Def * c)

Deconstruct a closure into (env_type, function, env).

Important: use this or ClosLit to destruct closures, since typechecking dependent pairs is currently broken.

Definition at line 70 of file clos.cpp.

References isa_clos_type().

Referenced by clos_apply(), mim::plug::clos::ClosLit::env(), mim::plug::clos::ClosLit::fnc(), and mim::plug::clos::ClosLit::isa_clos_lit.

◆ ctype()

const Def * mim::plug::clos::ctype ( World & w,
Defs doms,
const Def * env_type = nullptr )

Builds a closure type from the domains doms of a Cn.

If env_type is nullptr, returns the recursive closure Sigma [T: *, Cn [doms with T at env_param], T]. Otherwise, returns the bare Cn [doms with env_type at env_param] (the code part of such a closure).

Definition at line 124 of file clos.cpp.

References ctype(), and env_param().

Referenced by clos_type(), and ctype().

◆ env_param() [1/2]

size_t mim::plug::clos::env_param ( const Pi * pi)
inline

Definition at line 101 of file clos.h.

References env_param().

◆ env_param() [2/2]

size_t mim::plug::clos::env_param ( Defs doms)
inline

Describes where the environment is placed in the argument list: right after a leading mem.M, if doms starts with one, or in slot 0 otherwise.

tup_or_sig should generally be a Tuple, Sigma or Var. This way, closures built from mem-free (pure) functions don't gain a bogus mem-shaped layout, and don't get misaligned with their real parameters (see issue #126).

Definition at line 100 of file clos.h.

References mim::Axm::isa().

Referenced by clos_apply(), clos_pack(), clos_type_to_pi(), ctype(), env_param(), mim::plug::clos::ClosLit::env_var(), isa_clos_type(), mim::plug::clos::phase::BranchClosElim::rewrite_imm_App(), and mim::plug::clos::phase::ClosConv::rewrite_imm_Extract().

◆ isa_clos_lit()

ClosLit mim::plug::clos::isa_clos_lit ( const Def * def,
bool fn_isa_lam = true )

Tries to match a closure literal.

If fn_isa_lam, additionally requires the code part to be a Lam.

Definition at line 50 of file clos.cpp.

Referenced by mim::plug::clos::phase::LowerTypedClosPrep::analyze(), mim::plug::clos::phase::LowerTypedClos::rewrite(), and mim::plug::clos::phase::LowerTypedClosPrep::rewrite_imm_Tuple().

◆ isa_clos_type()

const Sigma * mim::plug::clos::isa_clos_type ( const Def * def)

◆ isa_var_proj()

template<class N>
std::tuple< const Extract *, N * > mim::plug::clos::isa_var_proj ( const Def * def)

If def is a projection var#i of the Var of some mutable of type N, returns (projection, binder).

Otherwise, returns (nullptr, nullptr).

Definition at line 72 of file clos.h.

References mim::Var::binder().

Referenced by mim::plug::clos::phase::ClosConv::rewrite_imm_Extract().

◆ normalize_clos()

template<attr o>
const Def * mim::plug::clos::normalize_clos ( const Def * ,
const Def * ,
const Def * arg )

Definition at line 6 of file normalizers.cpp.

References bottom.

◆ register_normalizers()

void mim::plug::clos::register_normalizers ( Normalizers & normalizers)

Referenced by mim_get_plugin().

◆ shift_env()

size_t mim::plug::clos::shift_env ( size_t ep,
size_t i )
inline

Adjust the index of an argument to account for the env param.

Definition at line 104 of file clos.h.

Referenced by clos_insert_env().

◆ skip_env()

size_t mim::plug::clos::skip_env ( size_t ep,
size_t i )
inline

Same as shift_env, but skips the env param instead.

Definition at line 107 of file clos.h.

Referenced by clos_remove_env(), and mim::plug::clos::phase::ClosConv::rewrite_imm_Extract().

Variable Documentation

◆ Plugin_Id

plugin_t mim::plug::clos::Plugin_Id = 0x10d4140000000000
staticconstexpr

Definition at line 10 of file autogen.h.