Low_level.Scope_ordergh-ocannl-2213: the order a statement's scope definitions are emitted in, in one place for the renderer and the analyses. C_syntax.pp_local_defs renders plan of the entries its pp_scalar collects; Access_fold's Emitted mode walks order of plan of the entries entries derives from the IR. The two derivations meet the same backend facts through an oracle, and the renderer asserts on every statement it renders that they agree (C_syntax.pp_local_defs' consistency check), so they cannot drift silently.
The emission order (gh-ocannl-2145, gh-ocannl-1895): the unconditional definitions, ascending by scope id except that a definition follows the sibling definitions its body reads; then the conditional ones' zero-initialized declarations, ascending; then the conditional bodies in one such dependency order, consecutive ones under the same conditions sharing one if. A definition runs under the disjunction of the conditions of its occurrences, of the reads of its local at operand position and, to a fixpoint, of the definitions reading it.
The renderer partitions its conditions by their rendered tests (plan's same); the derivation keys them by IR, and the renderer's check holds the two to one partition (same_plan). The IR key: the condition and the precision it renders at for a short-circuiting Where (Select); the operator, its first operand, the precision that operand renders at and the operator's evaluation precision for a short-circuiting gate (Gate, whose test is that the second operand matters: at an integer compute precision the operand renders at the integer precision and the test at a float one). Float constants compare by their bits. Two conditions keyed alike are one value: a condition reads no scope local (the cond_defs rule of arms), and the bodies run before it write only their own locals.
Normalize heterogeneous operand annotations through the backend's comp_prec (identity by default). Projection-discarded operands are ignored; Round_prec keeps its exact target.
One condition an occurrence is evaluated under: holds in the then-arm, not in the else-arm. anywhere: the condition can be evaluated in any iteration -- it reads no memory and no local, and divides nothing. payload is the caller's (the renderer's rendered test); equality ignores it.
A scope's definition (def = Some _) or, with def = None, a read of its local at operand position, under guard, outermost first.
Whether two literals test one condition, polarity aside: equal keys.
val evaluable_anywhere : scalar_t -> Base.boolval arms :
key:key ->
payload:'p ->
v1:scalar_t ->
cond_defs:('p, 'd) entry Base.list ->
('p, 'd) entry Base.list ->
('p, 'd) entry Base.list ->
('p, 'd) entry Base.listThe entries of a short-circuiting Where's arms, under its condition v1 (keyed key), whose own entries are cond_defs. A condition reading a scope local guards nothing: the arms keep only their conditions evaluable anywhere.
val gate :
key:key ->
payload:(Base.unit -> 'p) ->
v1:scalar_t ->
cond_defs:('p, 'd) entry Base.list ->
('p, 'd) entry Base.list ->
('p, 'd) entry Base.listThe entries of a short-circuiting gate's second operand: its definitions that run under a Where's condition keep that condition behind the gate's test.
type ('p, 'd) plan = {unconditional : (Base.int * 'd) Base.list;In emission order.
*)conditional : (Base.int * 'd) Base.list;Ascending: the order of their zeroed declarations.
*)groups : ('p lit Base.list Base.list * (Base.int * 'd) Base.list) Base.list;In emission order: each group's conditions (a disjunction of conjunctions) and its definitions.
*)}val order : ('p, 'd) plan -> (Base.int * Access_fold.placement) Base.listval same_plan :
?same_a:('p lit -> 'p lit -> Base.bool) ->
?same_b:('q lit -> 'q lit -> Base.bool) ->
('p, 'd) plan ->
('q, 'e) plan ->
Base.boolEqual orders, placements and declaration orders, and groups of the same shape and polarities whose literals are one condition under same_a exactly where they are under same_b.
type oracle = {short_circuits : prec:Ops.prec -> scalar_t -> Base.bool;Whether a Where or a Relu_gate / Satur01_gate node rendered at prec short-circuits rather than blending its arms (the renderer's blend_for); true at every integer precision.
comp_prec : Ops.prec -> Ops.prec;int_math_prec : Ops.prec;The float precision a float-valued subexpression at an integer compute precision is computed in.
*)root_precs : t -> Ops.prec Base.list;The precision each scalar of a rendering unit renders at, in Access_fold's root order: a Set_dynamic's index, then its value.
}The backend facts the emission order reads: C_syntax's scope_order_oracle.
val entries :
oracle ->
Ops.prec ->
scalar_t ->
(Base.unit, Base.int Base.list Base.Lazy.t) entry Base.listThe entries of a scalar rendered at a precision: the renderer's own descent.
val emission : oracle -> Access_fold.emissionAccess_fold's Emitted mode under oracle.