Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
thorin::plug::clos Namespace Reference

The clos Plugin More...

Classes

class  BranchClosElim
 
class  Clos2SJLJ
 
class  ClosConv
 Performs typed closure conversion. More...
 
class  ClosConvPrep
 
class  ClosLit
 Wrapper around a Def that can be used to match closures (see isa_clos_lit). More...
 
class  FreeDefAna
 Transitively compute free Def's on demand. More...
 
class  LowerTypedClos
 This pass lowers typed closures to untyped closures. More...
 
class  LowerTypedClosPrep
 

Enumerations

%clos.BufPtr
enum  BufPtr : flags_t
 
%clos.alloc_jmpbuf
enum  alloc_jmpbuf : flags_t
 
%clos.setjmp
enum  setjmp : flags_t
 
%clos.longjmp
enum  longjmp : flags_t
 
%clos.clos_conv_prep_pass
enum  clos_conv_prep_pass : flags_t
 
%clos.branch_clos_pass
enum  branch_clos_pass : flags_t
 
%clos.lower_typed_clos_prep_pass
enum  lower_typed_clos_prep_pass : flags_t
 
%clos.clos2sjlj_pass
enum  clos2sjlj_pass : flags_t
 
%clos.eta_red_bool_pass
enum  eta_red_bool_pass : flags_t
 
%clos.clos_conv_phase
enum  clos_conv_phase : flags_t
 
%clos.lower_typed_clos_phase
enum  lower_typed_clos_phase : flags_t
 

Functions

void register_normalizers (Normalizers &normalizers)
 
Closures
ClosLit isa_clos_lit (Ref def, bool fn_isa_lam=true)
 Tries to match a closure literal.
 
Ref clos_pack (Ref env, Ref fn, Ref ct=nullptr)
 Pack a typed closure. This assumes that fn expects the environment as its Clos_Env_Paramth argument.
 
std::tuple< Ref, Ref, Refclos_unpack (Ref c)
 Deconstruct a closure into (env_type, function, env).
 
Ref clos_apply (Ref closure, Ref args)
 Apply a closure to arguments.
 
Ref apply_closure (Ref closure, Defs args)
 
template<class N >
std::tuple< const Extract *, N * > ca_isa_var (Ref def)
 Checks is def is the variable of a mut of type N.
 
Closure Types
const Sigmaisa_clos_type (Ref def)
 Returns def if def is a closure and nullptr otherwise.
 
Sigmaclos_type (const Pi *pi)
 Creates a typed closure type from pi.
 
const Piclos_type_to_pi (Ref ct, Ref 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)
 

Variables

static constexpr plugin_t Plugin_Id = 0x10d4140000000000
 

%clos.attr

enum  attr : flags_t {
  ret = 0x10d4140000000400 ,
  freeBB = 0x10d4140000000401 ,
  fstclassBB = 0x10d4140000000402 ,
  esc = 0x10d4140000000403 ,
  bot = 0x10d4140000000404
}
 
template<attr o>
Ref normalize_clos (Ref type, Ref callee, Ref arg)
 

Closure Environment

tup_or_sig should generally be a Tuple, Sigma or Var.

static constexpr size_t Clos_Env_Param = 1_u64
 Describes where the environment is placed in the argument list.
 
size_t shift_env (size_t i)
 
size_t skip_env (size_t i)
 
Ref ctype (World &w, Defs doms, Ref env_type=nullptr)
 
Ref clos_insert_env (size_t i, Ref env, std::function< Ref(size_t)> f)
 
Ref clos_insert_env (size_t i, Ref env, Ref a)
 
Ref clos_insert_env (Ref env, Ref tup_or_sig)
 
Ref clos_remove_env (size_t i, std::function< Ref(size_t)> f)
 
Ref clos_remove_env (size_t i, Ref def)
 
Ref clos_remove_env (Ref tup_or_sig)
 
Ref clos_sub_env (Ref tup_or_sig, Ref new_env)
 

Detailed Description

Enumeration Type Documentation

◆ alloc_jmpbuf

Definition at line 26 of file autogen.h.

◆ attr

Enumerator
ret 
freeBB 
fstclassBB 
esc 
bot 

Definition at line 59 of file autogen.h.

◆ branch_clos_pass

Definition at line 90 of file autogen.h.

◆ BufPtr

Definition at line 15 of file autogen.h.

◆ clos2sjlj_pass

Definition at line 112 of file autogen.h.

◆ clos_conv_phase

Definition at line 134 of file autogen.h.

◆ clos_conv_prep_pass

Definition at line 79 of file autogen.h.

◆ eta_red_bool_pass

Definition at line 123 of file autogen.h.

◆ longjmp

Definition at line 48 of file autogen.h.

◆ lower_typed_clos_phase

◆ lower_typed_clos_prep_pass

◆ setjmp

Definition at line 37 of file autogen.h.

Function Documentation

◆ apply_closure()

Ref thorin::plug::clos::apply_closure ( Ref  closure,
Defs  args 
)
inline

Definition at line 72 of file clos.h.

References clos_apply(), and thorin::Def::world().

◆ ca_isa_var()

template<class N >
std::tuple< const Extract *, N * > thorin::plug::clos::ca_isa_var ( Ref  def)

Checks is def is the variable of a mut of type N.

Definition at line 79 of file clos.h.

◆ clos_apply()

Ref thorin::plug::clos::clos_apply ( Ref  closure,
Ref  args 
)

Apply a closure to arguments.

Definition at line 100 of file clos.cpp.

References clos_unpack(), and thorin::Def::world().

Referenced by apply_closure(), and thorin::plug::clos::Clos2SJLJ::enter().

◆ clos_insert_env() [1/3]

Ref thorin::plug::clos::clos_insert_env ( Ref  env,
Ref  tup_or_sig 
)
inline

Definition at line 124 of file clos.h.

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

◆ clos_insert_env() [2/3]

Ref thorin::plug::clos::clos_insert_env ( size_t  i,
Ref  env,
Ref  a 
)
inline

Definition at line 120 of file clos.h.

References clos_insert_env().

◆ clos_insert_env() [3/3]

Ref thorin::plug::clos::clos_insert_env ( size_t  i,
Ref  env,
std::function< Ref(size_t)>  f 
)

Definition at line 135 of file clos.cpp.

References Clos_Env_Param, and shift_env().

Referenced by clos_insert_env().

◆ clos_pack()

Ref thorin::plug::clos::clos_pack ( Ref  env,
Ref  fn,
Ref  ct = nullptr 
)

Pack a typed closure. This assumes that fn expects the environment as its Clos_Env_Paramth argument.

Definition at line 78 of file clos.cpp.

References Clos_Env_Param, clos_remove_env(), clos_type(), isa_clos_type(), thorin::Def::type(), and thorin::Def::world().

Referenced by thorin::plug::clos::Clos2SJLJ::enter(), thorin::plug::clos::Clos2SJLJ::rewrite(), and thorin::plug::clos::LowerTypedClosPrep::rewrite().

◆ clos_remove_env() [1/3]

Ref thorin::plug::clos::clos_remove_env ( Ref  tup_or_sig)
inline

Definition at line 134 of file clos.h.

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

◆ clos_remove_env() [2/3]

Ref thorin::plug::clos::clos_remove_env ( size_t  i,
Ref  def 
)
inline

Definition at line 131 of file clos.h.

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

◆ clos_remove_env() [3/3]

Ref thorin::plug::clos::clos_remove_env ( size_t  i,
std::function< Ref(size_t)>  f 
)

◆ clos_sub_env()

Ref thorin::plug::clos::clos_sub_env ( Ref  tup_or_sig,
Ref  new_env 
)
inline

Definition at line 140 of file clos.h.

References Clos_Env_Param, and thorin::Def::refine().

Referenced by clos_type_to_pi().

◆ clos_type()

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

Creates a typed closure type from pi.

Definition at line 121 of file clos.cpp.

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

Referenced by clos_pack(), and thorin::plug::clos::Clos2SJLJ::enter().

◆ clos_type_to_pi()

const Pi * thorin::plug::clos::clos_type_to_pi ( Ref  ct,
Ref  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 123 of file clos.cpp.

References clos_remove_env(), clos_sub_env(), isa_clos_type(), thorin::Def::op(), and thorin::Def::world().

◆ clos_unpack()

std::tuple< Ref, Ref, Ref > thorin::plug::clos::clos_unpack ( Ref  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 88 of file clos.cpp.

References isa_clos_type().

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

◆ ctype()

Ref thorin::plug::clos::ctype ( World w,
Defs  doms,
Ref  env_type = nullptr 
)

Definition at line 141 of file clos.cpp.

References ctype().

Referenced by clos_type(), and ctype().

◆ isa_clos_lit()

ClosLit thorin::plug::clos::isa_clos_lit ( Ref  def,
bool  fn_isa_lam = true 
)

◆ isa_clos_type()

const Sigma * thorin::plug::clos::isa_clos_type ( Ref  def)

Returns def if def is a closure and nullptr otherwise.

Definition at line 111 of file clos.cpp.

References Clos_Env_Param, thorin::Pi::isa_cn(), thorin::Def::isa_mut(), thorin::Def::num_ops(), thorin::Def::op(), thorin::Def::var(), and thorin::Def::world().

Referenced by clos_pack(), clos_type_to_pi(), and clos_unpack().

◆ normalize_clos()

template<attr o>
Ref thorin::plug::clos::normalize_clos ( Ref  type,
Ref  callee,
Ref  arg 
)

Definition at line 5 of file normalizers.cpp.

References bot, and thorin::Def::world().

◆ register_normalizers()

void thorin::plug::clos::register_normalizers ( Normalizers normalizers)

Referenced by thorin_get_plugin().

◆ shift_env()

size_t thorin::plug::clos::shift_env ( size_t  i)
inline

Definition at line 111 of file clos.h.

References Clos_Env_Param.

Referenced by clos_insert_env().

◆ skip_env()

size_t thorin::plug::clos::skip_env ( size_t  i)
inline

Definition at line 114 of file clos.h.

References Clos_Env_Param.

Referenced by clos_remove_env().

Variable Documentation

◆ Clos_Env_Param

constexpr size_t thorin::plug::clos::Clos_Env_Param = 1_u64
staticconstexpr

Describes where the environment is placed in the argument list.

Definition at line 108 of file clos.h.

Referenced by clos_insert_env(), clos_pack(), clos_sub_env(), thorin::plug::clos::ClosLit::env_var(), isa_clos_type(), shift_env(), and skip_env().

◆ Plugin_Id

constexpr plugin_t thorin::plug::clos::Plugin_Id = 0x10d4140000000000
staticconstexpr

Definition at line 10 of file autogen.h.