Module Flambda2_terms.Flambda
The 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:
- every intermediate value (and in particular every potential value that we may want to statically allocate) has a name;
- every point to which we might wish to jump has a name;
- there are no nested "let"s or subexpressions;
- no re-normalisation of terms is required when substituting an application for an inlined body (unlike in conventional ANF forms).
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 Flambda2_terms.Flambda.let_expr(*Bind 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 Flambda2_terms.Flambda.let_cont_expr(*Define one or more continuations.
*)| Apply of Flambda2_terms.Apply_expr.t(*Call an OCaml function, external function or method.
*)| Apply_cont of Flambda2_terms.Apply_cont_expr.t(*Call a continuation, optionally adding or removing exception trap frames from the stack, which thus allows for the raising of exceptions.
*)| Switch of Flambda2_terms.Switch_expr.t(*Conditional control flow.
*)| Invalid of {}(*Code proved type-incorrect and therefore unreachable.
*)
and named = private | Simple of Flambda2_term_basics.Simple.t(*Things that fit in a register (variables, symbols, constants). These do not have to be
*)Let-bound but are allowed here for convenience.| Prim of Flambda2_terms.Flambda_primitive.t * Debuginfo.t(*Primitive operations (arithmetic, memory access, allocation, etc).
*)| Set_of_closures of Flambda2_terms.Set_of_closures.t(*Definition of a set of (dynamically allocated) possibly mutually-recursive closures.
*)| Static_consts of Flambda2_terms.Flambda.static_const_group(*Definition of one or more symbols representing statically-allocated constants (including sets of closures).
*)| Rec_info of Flambda2_term_basics.Rec_info_expr.t(*Definition of a state of recursive inlining.
*)
The defining expressions of Let-bindings.
and let_cont_expr = private | Non_recursive of {handler : Flambda2_terms.Flambda.non_recursive_let_cont_handler;num_free_occurrences : Flambda2_nominal.Num_occurrences.t Flambda2_lattices.Or_unknown.t;(*
*)num_free_occurrencescan 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_trapsis used to prevent inlining of continuations that are applied with a trap action
}| Recursive of Flambda2_terms.Flambda.recursive_let_cont_handlers
and static_const_or_code = private | Code of Flambda2_terms.Flambda.function_params_and_body Flambda2_terms.Code0.t| Deleted_code| Static_const of Flambda2_terms.Static_const.t
module 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 = Flambda2_terms.Apply_exprmodule Apply_cont = Flambda2_terms.Apply_cont_exprmodule Function_declarations = Flambda2_terms.Function_declarationsmodule Let = Flambda2_terms.Flambda.Let_exprmodule Let_cont = Flambda2_terms.Flambda.Let_cont_exprmodule Set_of_closures = Flambda2_terms.Set_of_closuresmodule Switch = Flambda2_terms.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.