Module Flambda2_reaper.Traverse_acc
Accumulator used during the downward traversal of the Flambda 2 term to build the global flow graph for the reaper.
module Graph = Global_flow_graphtype continuation_info = {is_exn_handler : bool;params : Flambda2_identifiers.Variable.t list;arity : Flambda2_kinds.Flambda_kind.With_subkind.t list;
}Information about a continuation, including its parameters, arity, and whether it is an exception handler. This is used to register dependencies on the continuation at call sites.
type code_dep = {arity : [ `Complex ] Flambda2_kinds.Flambda_arity.t;params : Flambda2_identifiers.Variable.t list;my_closure : Flambda2_identifiers.Variable.t;return : Flambda2_identifiers.Variable.t list;exn : Flambda2_identifiers.Variable.t;is_tupled : bool;known_arity_call_witness : Flambda2_identifiers.Code_id_or_name.t;unknown_arity_call_witnesses : Flambda2_identifiers.Code_id_or_name.t list;
}Information about a function's code that is needed for building the dependency graph. Created by prepare_code during traversal and looked up when processing function bodies and call sites at the end of the traversal.
type apply_dep = {function_containing_apply_expr : Flambda2_identifiers.Code_id.t option;apply_code_id : Flambda2_identifiers.Code_id.t;apply_closure : Flambda2_term_basics.Simple.t option;apply_call_witness : Flambda2_identifiers.Code_id_or_name.t;
}A record of a direct function application, to be resolved into graph edges once all code has been traversed.
val create : unit -> tCreate a fresh, empty accumulator.
val kind :
t ->
Flambda2_identifiers.Name.t ->
Flambda2_kinds.Flambda_kind.t ->
unitRecord the kind of a name.
val bound_parameter_kind :
t ->
Flambda2_bound_identifiers.Bound_parameter.t ->
unitRecord the kind of a bound parameter's variable.
val alias_kind :
t ->
Flambda2_identifiers.Name.t ->
Flambda2_term_basics.Simple.t ->
unitRecord the kind of name by inferring it from simple.
val kinds : t -> Flambda2_kinds.Flambda_kind.t Flambda2_identifiers.Name.Map.tReturn the map of all recorded kinds.
val fixed_arity_continuation : t -> Flambda2_identifiers.Continuation.t -> unitMark a continuation as having fixed arity (mostly function return continuations): the rebuild pass may not change its number of parameters.
val fixed_arity_continuations : t -> Flambda2_identifiers.Continuation.Set.tReturn the set of all fixed-arity continuations.
val continuation_info :
t ->
Flambda2_identifiers.Continuation.t ->
params:Flambda2_identifiers.Variable.t list ->
arity:Flambda2_kinds.Flambda_kind.With_subkind.t list ->
is_exn_handler:bool ->
unitRecord metadata about a continuation (parameters, arity, and whether it is an exception handler).
val get_continuation_info :
t ->
continuation_info Flambda2_identifiers.Continuation.Map.tReturn the map of all recorded continuation metadata.
val add_code_dep : t -> Flambda2_identifiers.Code_id.t -> code_dep -> unitRegister a code_dep for a code id, recording the function's parameters, returns, and call witnesses in the accumulator.
val find_code_dep : t -> Flambda2_identifiers.Code_id.t -> code_dep optionLook up the code_dep for a code id. Returns None if the code id has not been registered (e.g. it belongs to another compilation unit).
val code_deps : t -> code_dep Flambda2_identifiers.Code_id.Map.tReturn the map of all registered code deps.
val add_code : t -> Flambda2_identifiers.Code_id.t -> Rev_expr.rev_code -> unitval get_all_code : t -> Rev_expr.rev_code Flambda2_identifiers.Code_id.Map.tval add_alias :
t ->
to_:Flambda2_identifiers.Code_id_or_name.t ->
from:Flambda2_identifiers.Code_id_or_name.t ->
unitAdd a (directed) alias edge: from flows into to_, meaning that every usage of to_ is a usage of from; and every source of from is a source of to_.
val add_alias_vars :
t ->
to_:Flambda2_identifiers.Variable.t ->
from:Flambda2_identifiers.Variable.t ->
unitConvenience wrapper around add_alias for variables.
val add_use_dep :
t ->
to_:Flambda2_identifiers.Code_id_or_name.t ->
from:Flambda2_identifiers.Code_id_or_name.t ->
unitAdd a use-dependency edge: if to_ has an usage, then from is any_usage. Besides, this is a source for to_.
val add_accessor_dep :
t ->
to_:Flambda2_identifiers.Code_id_or_name.t ->
Field.t ->
base:Flambda2_identifiers.Code_id_or_name.t ->
unitAdd an accessor edge: the field relation of base flows into to_.
val add_constructor_dep :
t ->
base:Flambda2_identifiers.Code_id_or_name.t ->
Field.t ->
from:Flambda2_identifiers.Code_id_or_name.t ->
unitAdd a constructor edge: from flows into field relation of base.
val add_argument_dep :
t ->
from:Flambda2_identifiers.Code_id_or_name.t ->
Cofield.t ->
base:Flambda2_identifiers.Code_id_or_name.t ->
unitAdd an argument edge: from flows into parameters of sources of base.
val add_parameter_dep :
t ->
base:Flambda2_identifiers.Code_id_or_name.t ->
Cofield.t ->
to_:Flambda2_identifiers.Code_id_or_name.t ->
unitAdd a parameter edge: arguments of usages of base flow into to_.
val add_propagate_dep :
t ->
if_used:Flambda2_identifiers.Code_id_or_name.t ->
to_:Flambda2_identifiers.Code_id_or_name.t ->
from:Flambda2_identifiers.Code_id_or_name.t ->
unitAdd a conditional propagation edge: if if_used is any_usage then add an alias from from to to_.
val add_alias_if_any_source_dep :
t ->
if_any_source:Flambda2_identifiers.Code_id_or_name.t ->
to_:Flambda2_identifiers.Code_id_or_name.t ->
from:Flambda2_identifiers.Code_id_or_name.t ->
unitAdd a conditional alias edge: if if_any_source is marked as any_source then add an alias from from to to_.
val add_any_usage : t -> Flambda2_identifiers.Code_id_or_name.t -> unitMark a node as unconditionally used.
val add_any_source : t -> Flambda2_identifiers.Code_id_or_name.t -> unitMark a node as having any possible source (i.e. it could contain any value).
val add_zero_alloc_source : t -> Flambda2_identifiers.Code_id_or_name.t -> unitMark a node as a "magic" source for zero-alloc checking purposes. This is a hack to mostly preserve zero_alloc correctness before we have zero_alloc regions.
val add_code_id_my_closure :
t ->
Flambda2_identifiers.Code_id.t ->
Flambda2_identifiers.Variable.t ->
unitRecord the my_closure variable associated with a code id.
val simple_to_node :
t ->
denv:Traverse_env.t ->
Flambda2_term_basics.Simple.t ->
Flambda2_identifiers.Code_id_or_name.tConvert a Simple.t to a dependency graph node. Constants map to the all_constants node; variables map to themselves; symbols from other compilation units are marked any_source.
val add_cond_any_usage :
t ->
denv:Traverse_env.t ->
Flambda2_term_basics.Simple.t ->
unitMark a Simple.t as used, conditional on the current function (if any) being used. At the top level, marks it unconditionally.
val add_cond_any_source :
t ->
denv:Traverse_env.t ->
Flambda2_identifiers.Code_id_or_name.t ->
unitMark a node as any_source, conditional on the current function (if any) being used. At the top level, marks it unconditionally.
Record a direct function application to be resolved later by deps. Only used for applications to code ids in the current compilation unit.
val create_known_arity_call_witness :
t ->
Flambda2_identifiers.Code_id.t ->
params:Flambda2_identifiers.Variable.t list ->
returns:Flambda2_identifiers.Variable.t list ->
exn:Flambda2_identifiers.Variable.t ->
Flambda2_identifiers.Code_id_or_name.tCreate the call witness node for a known-arity function definition. The witness carries parameter, return, exception, and code-id edges corresponding to the function's signature.
val make_known_arity_apply_widget :
t ->
denv:Traverse_env.t ->
Flambda2_terms.Apply_expr.t ->
returns:Flambda2_identifiers.Variable.t list ->
exn:Flambda2_identifiers.Variable.t ->
Flambda2_identifiers.Code_id_or_name.tCreate a call widget for a known-arity application. Links the apply's arguments to the witness's parameters, and the witness's returns and exception to the continuation parameters. Returns a node that can be connected to the callee's closure via an accessor dependency.
val create_unknown_arity_call_witnesses :
t ->
Flambda2_identifiers.Code_id.t ->
is_tupled:bool ->
arity:[ `Complex ] Flambda2_kinds.Flambda_arity.t ->
params:Flambda2_identifiers.Variable.t list ->
returns:Flambda2_identifiers.Variable.t list ->
exn:Flambda2_identifiers.Variable.t ->
Flambda2_identifiers.Code_id_or_name.t listCreate the call witness nodes for an unknown-arity function definition. For tupled functions, a single witness with tuple-field accessors is created. For curried functions, a chain of witnesses is created, one per complex parameter, linked via partial-application nodes.
val make_unknown_arity_apply_widget :
t ->
denv:Traverse_env.t ->
Flambda2_terms.Apply_expr.t ->
returns:Flambda2_identifiers.Variable.t list ->
exn:Flambda2_identifiers.Variable.t ->
Flambda2_identifiers.Code_id_or_name.tCreate a call widget for an unknown-arity application, analogous to make_known_arity_apply_widget but for calls where the callee's arity is not statically known.
val add_set_of_closures_dep :
t ->
Flambda2_identifiers.Name.t ->
closure_code_id:Flambda2_identifiers.Code_id.t ->
only_full_applications:bool ->
defined_in_code_id:Flambda2_identifiers.Code_id.t option ->
unitRecord a dependency between a closure binding and its code id. This is resolved later by deps to connect closures to their function code in the graph.
val deps : t -> all_constants:Flambda2_identifiers.Name.t -> Graph.graphFinalize the graph by resolving all deferred apply and set-of-closures dependencies, and return the completed dependency graph.
val sort_code_ids : t -> Flambda2_identifiers.Code_id.t arrayval add_set_of_closures :
t ->
(Flambda2_identifiers.Name.t
* Flambda2_identifiers.Code_id.t Flambda2_lattices.Or_unknown.t)
Flambda2_identifiers.Function_slot.Lmap.t ->
unitval get_all_sets_of_closures :
t ->
(Flambda2_identifiers.Name.t
* Flambda2_identifiers.Code_id.t Flambda2_lattices.Or_unknown.t)
Flambda2_identifiers.Function_slot.Lmap.t
list