Module Checker.IR
the module holding definitions of the ANF intermediate language used by the borrow checker.
type mutability= Syntax.mutabilitytype variable= intthe type of IR variables
type source= Syntax.exprthe source of a IR value in the surface syntax. To save some memory, use source code locations instead of full surface syntax expressions
type var_kind=|Tmp|SrcVarthe kind of IR variables.
Tmpmeans variables holding temporary expressions. These variables are always used exactly once, and it is safe to not consider them during borrow checking.SrcVarmeans variables corresponding to a program variable in the surface syntax.
val generator : < gen_label : label; gen_var : variable; reset : unit; >val gen_var : unit -> variableval gen_label : unit -> label
type path= path_node listand path_node=|Field of inta field of a tuple
|Derefdata pointed by a borrow
type lvalue={lv_src : source;lv_var : variable;lv_path : path;}a
lvalueis a value that corresponds to a memory location and can be assigned to.
type value=|Loc of lvalue|Lit of inttype expr=|Val of value|Fun of string|Borrow of mutability * lvalue|Assign of lvalue * value|App of value * value list|Tuple of value list|ExitScope of variable list * valueExitScope(vars, value)means leaving a scope with variablesvars, returningvalueas the result of the whole scope. The point of having this construct is, after droppingvars,valuemay become invalid. By combining the operations of dropping variables and returning from a scope, the borrow checker and identify this kind of patterns and correctly handle them.
type program=|Jump of label * value|Decl of variable * expr * program|If of value * program * program|Block of block * program|Loop of blockBlock(blk, body)defines a non-recursive blockblk, and then executesbody, which may jump toblkLoop blkdefines a recursive blockblk, and executes the block immediately. The parameter ofblkis of typeIntand is meaningless
and block={blk_label : label;blk_param : variable;blk_body : program;}type function_def={func_src : Syntax.function_def;func_name : string;func_label : label;func_params : variable list;func_body : program;}func_labelis used to record the state of execution after the function returns
module VarMap : sig ... end