jon.recoil.org

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:

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
type let_expr
type non_recursive_let_cont_handler
type recursive_let_cont_handlers
type function_params_and_body
type static_const_group
type expr_descr = private
  1. | 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.

    *)
  2. | Let_cont of Flambda2_terms.Flambda.let_cont_expr
    (*

    Define one or more continuations.

    *)
  3. | Apply of Flambda2_terms.Apply_expr.t
    (*

    Call an OCaml function, external function or method.

    *)
  4. | 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.

    *)
  5. | Switch of Flambda2_terms.Switch_expr.t
    (*

    Conditional control flow.

    *)
  6. | Invalid of {
    1. message : string;
    }
    (*

    Code proved type-incorrect and therefore unreachable.

    *)
and named = private
  1. | 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.

    *)
  2. | Prim of Flambda2_terms.Flambda_primitive.t * Debuginfo.t
    (*

    Primitive operations (arithmetic, memory access, allocation, etc).

    *)
  3. | Set_of_closures of Flambda2_terms.Set_of_closures.t
    (*

    Definition of a set of (dynamically allocated) possibly mutually-recursive closures.

    *)
  4. | Static_consts of Flambda2_terms.Flambda.static_const_group
    (*

    Definition of one or more symbols representing statically-allocated constants (including sets of closures).

    *)
  5. | 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
  1. | Non_recursive of {
    1. handler : Flambda2_terms.Flambda.non_recursive_let_cont_handler;
    2. 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.

      *)
    3. is_applied_with_traps : bool;
      (*

      is_applied_with_traps is used to prevent inlining of continuations that are applied with a trap action

      *)
    }
  2. | Recursive of Flambda2_terms.Flambda.recursive_let_cont_handlers
and static_const_or_code = private
  1. | Code of Flambda2_terms.Flambda.function_params_and_body Flambda2_terms.Code0.t
  2. | Deleted_code
  3. | Static_const of Flambda2_terms.Static_const.t
module Invalid : sig ... end
module Expr : sig ... end
module Named : sig ... end
module Let_expr : sig ... end

The 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 ... end
module Continuation_handlers : sig ... end
module Let_cont_expr : sig ... end

Values of type t represent alpha-equivalence classes of the definitions of continuations:

module Non_recursive_let_cont_handler : sig ... end
module Recursive_let_cont_handlers : sig ... end
module Function_params_and_body : sig ... end
module Static_const_or_code : sig ... end
module Static_const_group : sig ... end
module Apply_cont = Flambda2_terms.Apply_cont_expr
module Function_declarations = Flambda2_terms.Function_declarations
module Set_of_closures = Flambda2_terms.Set_of_closures
module Import : sig ... end

The idea is that you should typically do "open! Flambda" at the top of files, thus bringing in the following standard set of module aliases.