jon.recoil.org

Module Flambda2_reaper.Traverse_env

Environment threaded through the downward traversal of a function body. Tracks the context needed to register dependencies at each expression.

type cont_kind =
  1. | Normal of Flambda2_identifiers.Variable.t list

Normal params carries the variables representing a continuation's parameters.

type should_preserve_direct_calls =
  1. | Yes
  2. | No
  3. | Auto

Controls whether the reaper preserves direct function calls when the code_id being called might otherwise be dead. The typical situation is a call to a code_id f, which has two newer versions f1 and f2, and the closure that is used could have either code_id f1 or f2, but never f.

  • Yes: always preserve direct calls: this has the consequence that it needs to keep old code_ids (f in this case) alive.
  • No: never preserve direct calls to dead code_ids: the call will be replaced by Indirect_known_arity if the reaper isn't able to determine the possibly called code_ids.
  • Auto: preserve only if the closure is any_source, preventing a determination of a set of possibly called code_ids. In this case, direct calls can never be completely degraded to Indirect_known_arity that doesn't know the set of possibly called code_ids: if that were to happen, the direct call is instead kept.
type t

The type of downwards environments.

val create : parent:Rev_expr.rev_expr_holed -> conts:cont_kind Flambda2_identifiers.Continuation.Map.t -> current_code_id:Flambda2_identifiers.Code_id.t option -> should_preserve_direct_calls:should_preserve_direct_calls -> le_monde_exterieur:Flambda2_identifiers.Name.t -> all_constants:Flambda2_identifiers.Name.t -> t

Create a new downwards environment.

val parent : t -> Rev_expr.rev_expr_holed

The reversed expression context above the current point in the traversal.

Get parameters of a given continuation

Add new continuation in scope with given parameters.

val current_code_id : t -> Flambda2_identifiers.Code_id.t option

The code id of the function currently being traversed, or None at the top level.

val should_preserve_direct_calls : t -> should_preserve_direct_calls

Whether direct calls in the current function should be preserved by the reaper. Set per function body based on the reaper_preserve_direct_calls flag and whether zero-alloc checking is active.

val le_monde_exterieur : t -> Flambda2_identifiers.Name.t

A distinguished any_source symbol representing the external world. Dependencies on this node model side effects.

val all_constants : t -> Flambda2_identifiers.Name.t

A distinguished any_source symbol to which all compile-time constants are mapped.

val with_parent : t -> Rev_expr.rev_expr_holed -> t

Return a copy of the environment with a new parent context.