Flambda2_terms.FlambdaThe grammar of the Flambda 2 term language.
The language is in double-barrelled continuation-passing style (CPS). Continuations, used for normal and exceptional control flow, are second class. Unlike some CPS-based representations there is a conventional "let"-binding construct; this is structured in A-normal form (ANF). Terms are represented up to alpha-conversion of bound variables and continuations.
The basic structure of the language ensures that:
Modules may be found further down the file giving operations on the abstract types that follow. The types for some parts of terms (e.g. Apply_expr) are defined in their own files.
type expr_descr = private | Let of let_exprBind variable(s), symbol(s) and/or code ID(s). The defining expression (the part after the "=", as in "let x = defining_expr in body") never has any effect on control flow.
*)| Let_cont of let_cont_exprDefine one or more continuations.
*)| Apply of Apply_expr.tCall an OCaml function, external function or method.
*)| Apply_cont of Apply_cont_expr.tCall a continuation, optionally adding or removing exception trap frames from the stack, which thus allows for the raising of exceptions.
*)| Switch of Switch_expr.tConditional control flow.
*)| Invalid of {}Code proved type-incorrect and therefore unreachable.
*)and named = private | Simple of Flambda2_term_basics.Simple.tThings that fit in a register (variables, symbols, constants). These do not have to be Let-bound but are allowed here for convenience.
| Prim of Flambda_primitive.t * Debuginfo.tPrimitive operations (arithmetic, memory access, allocation, etc).
*)| Set_of_closures of Set_of_closures.tDefinition of a set of (dynamically allocated) possibly mutually-recursive closures.
*)| Static_consts of static_const_groupDefinition of one or more symbols representing statically-allocated constants (including sets of closures).
*)| Rec_info of Flambda2_term_basics.Rec_info_expr.tDefinition of a state of recursive inlining.
*)The defining expressions of Let-bindings.
and let_cont_expr = private | Non_recursive of {handler : non_recursive_let_cont_handler;num_free_occurrences : Flambda2_nominal.Num_occurrences.t
Flambda2_lattices.Or_unknown.t;num_free_occurrences can be used, for example, to decide whether to inline out a linearly-used continuation. It will always be strictly greater than zero.
is_applied_with_traps : bool;is_applied_with_traps is used to prevent inlining of continuations that are applied with a trap action
can_be_lifted : bool;can_be_lifted is used to prevent some continuations from being lifted during continuation specialization.
}| Recursive of recursive_let_cont_handlersand static_const_or_code = private | Code of function_params_and_body Code0.t| Deleted_code| Static_const of Static_const.tmodule Invalid : sig ... endmodule Expr : sig ... endmodule Named : sig ... endmodule Let_expr : sig ... endThe alpha-equivalence classes of expressions that bind variables; and the expressions that bind symbols and code IDs (which are not treated up to alpha equivalence).
module Continuation_handler : sig ... endmodule Continuation_handlers : sig ... endmodule Let_cont_expr : sig ... endValues of type t represent alpha-equivalence classes of the definitions of continuations:
module Non_recursive_let_cont_handler : sig ... endmodule Recursive_let_cont_handlers : sig ... endmodule Function_params_and_body : sig ... endmodule Static_const_or_code : sig ... endmodule Static_const_group : sig ... endmodule Apply = Apply_exprmodule Apply_cont = Apply_cont_exprmodule Function_declarations = Function_declarationsmodule Let = Let_exprmodule Let_cont = Let_cont_exprmodule Set_of_closures = Set_of_closuresmodule Switch = Switch_exprmodule Import : sig ... endThe idea is that you should typically do "open! Flambda" at the top of files, thus bringing in the following standard set of module aliases.