pub trait DfirBuilder {
Show 21 methods
// Required methods
fn singleton_intermediates(&self) -> bool;
fn add_dfir_at(
&mut self,
location: &LocationId,
dfir: DfirCode,
operator_tag: Option<&str>,
);
fn add_tick_source(
&mut self,
location: &LocationId,
source_rhs: TokenStream,
out_ident: &Ident,
replay_each_tick: bool,
operator_tag: Option<&str>,
);
fn batch(
&mut self,
in_ident: Ident,
in_location: &LocationId,
in_kind: &CollectionKind,
out_ident: &Ident,
out_location: &LocationId,
op_meta: &HydroIrOpMetadata,
fold_hooked_idents: &HashSet<String>,
);
fn snapshot(
&mut self,
in_ident: Ident,
in_location: &LocationId,
in_kind: &CollectionKind,
out_ident: &Ident,
out_location: &LocationId,
op_meta: &HydroIrOpMetadata,
fold_hooked_idents: &HashSet<String>,
);
fn yield_from_tick(
&mut self,
in_ident: Ident,
in_location: &LocationId,
in_kind: &CollectionKind,
out_ident: &Ident,
out_location: &LocationId,
out_kind: &CollectionKind,
);
fn unwindow_for_consume(
&mut self,
in_ident: Ident,
in_location: &LocationId,
out_location: &LocationId,
) -> Ident;
fn begin_atomic(
&mut self,
in_ident: Ident,
in_location: &LocationId,
in_kind: &CollectionKind,
out_ident: &Ident,
out_location: &LocationId,
op_meta: &HydroIrOpMetadata,
);
fn end_atomic(
&mut self,
in_ident: Ident,
in_location: &LocationId,
in_kind: &CollectionKind,
out_ident: &Ident,
out_kind: &CollectionKind,
);
fn observe_nondet(
&mut self,
trusted: bool,
location: &LocationId,
in_ident: Ident,
in_kind: &CollectionKind,
out_ident: &Ident,
out_kind: &CollectionKind,
op_meta: &HydroIrOpMetadata,
);
fn merge_ordered(
&mut self,
location: &LocationId,
first_ident: Ident,
second_ident: Ident,
out_ident: &Ident,
in_kind: &CollectionKind,
op_meta: &HydroIrOpMetadata,
operator_tag: Option<&str>,
);
fn create_network(
&mut self,
from: &LocationId,
to: &LocationId,
input_ident: Ident,
out_ident: &Ident,
serialize: Option<&DebugExpr>,
sink: Expr,
source: Expr,
deserialize: Option<&DebugExpr>,
external_element_type: Option<&Type>,
tag_id: StmtId,
networking_info: &NetworkingInfo,
);
fn create_external_source(
&mut self,
on: &LocationId,
source_expr: Expr,
out_ident: &Ident,
deserialize: Option<&DebugExpr>,
tag_id: StmtId,
);
fn create_external_output(
&mut self,
on: &LocationId,
sink_expr: Expr,
input_ident: &Ident,
serialize: Option<&DebugExpr>,
tag_id: StmtId,
);
fn emit_fold_hook(
&mut self,
location: &LocationId,
in_ident: &Ident,
in_kind: &CollectionKind,
op_meta: &HydroIrOpMetadata,
) -> Option<Ident>;
fn assert_is_consistent(
&mut self,
trusted: bool,
location: &LocationId,
in_ident: Ident,
out_ident: &Ident,
);
fn observe_for_mut(
&mut self,
location: &LocationId,
in_ident: Ident,
in_kind: &CollectionKind,
out_ident: &Ident,
op_meta: &HydroIrOpMetadata,
);
fn create_versioned_network_fork(
&mut self,
channel_id: u32,
dest: &LocationId,
senders: Vec<(LocationId, Ident, Option<DebugExpr>)>,
external_element_type: Option<&Type>,
tag_id: StmtId,
);
fn create_versioned_network(
&mut self,
channel_id: u32,
source: &LocationId,
dest: &LocationId,
out_ident: &Ident,
deserialize: Option<&DebugExpr>,
external_element_type: Option<&Type>,
tag_id: StmtId,
);
// Provided methods
fn tick_state_lifetime(&self, _op_location: &LocationId) -> TokenStream { ... }
fn cross_tick_state_lifetime(
&self,
_op_location: &LocationId,
) -> TokenStream { ... }
}build only.Expand description
A trait that abstracts over elements of DFIR code-gen that differ between production deployment and simulations.
In particular, this lets the simulator fuse together all locations into one DFIR graph, spit out separate graphs for each tick, and emit hooks for controlling non-deterministic operators.
Required Methods§
Sourcefn singleton_intermediates(&self) -> bool
fn singleton_intermediates(&self) -> bool
Whether the representation of singletons should include intermediate states.
Sourcefn add_dfir_at(
&mut self,
location: &LocationId,
dfir: DfirCode,
operator_tag: Option<&str>,
)
fn add_dfir_at( &mut self, location: &LocationId, dfir: DfirCode, operator_tag: Option<&str>, )
Adds the DFIR statements to the graph for the given location.
The location determines which DFIR graph the statements are placed in (for production,
the graph of the location’s root; for simulation, either the fused async graph or the
tick’s separate graph). In the future (#2902), production codegen will also use the
location to place tick-located statements inside the tick’s loop { ... } context.
Sourcefn add_tick_source(
&mut self,
location: &LocationId,
source_rhs: TokenStream,
out_ident: &Ident,
replay_each_tick: bool,
operator_tag: Option<&str>,
)
fn add_tick_source( &mut self, location: &LocationId, source_rhs: TokenStream, out_ident: &Ident, replay_each_tick: bool, operator_tag: Option<&str>, )
Emits a source operator (e.g. source_iter(...)) that logically lives inside a tick.
source_rhsis the source pipeline (the right-hand side of the=assignment, e.g.source_iter([123])).replay_each_tickselects whether the value is re-emitted on every tick/firing (persisted) or delivered only on the first tick/firing.
TODO(#2902): eventually this should not be an option here; instead the IR should model
the source as living outside the tick, windowed in through a batch_persist() loop
ingress operator when it should replay on every firing (the production impl already
lowers to exactly that shape: a root-level source + persist() + windowing).
The default (simulation) emission places the source directly in the tick’s own graph.
Production overrides this since DFIR sources must be at the root level, outside of the
tick’s loop { ... } context: it emits the source at the root and windows it into the
loop.
Sourcefn batch(
&mut self,
in_ident: Ident,
in_location: &LocationId,
in_kind: &CollectionKind,
out_ident: &Ident,
out_location: &LocationId,
op_meta: &HydroIrOpMetadata,
fold_hooked_idents: &HashSet<String>,
)
fn batch( &mut self, in_ident: Ident, in_location: &LocationId, in_kind: &CollectionKind, out_ident: &Ident, out_location: &LocationId, op_meta: &HydroIrOpMetadata, fold_hooked_idents: &HashSet<String>, )
Lowers a HydroNode::Batch: windows a stream-like collection (in_kind must be a
stream, a keyed stream, or a keyed singleton with bounded per-key values) into the tick
at out_location, so that each firing observes just the elements that arrived since
the previous batch.
Implementations must reject singleton-like in_kinds, which are windowed with
DfirBuilder::snapshot instead.
Sourcefn snapshot(
&mut self,
in_ident: Ident,
in_location: &LocationId,
in_kind: &CollectionKind,
out_ident: &Ident,
out_location: &LocationId,
op_meta: &HydroIrOpMetadata,
fold_hooked_idents: &HashSet<String>,
)
fn snapshot( &mut self, in_ident: Ident, in_location: &LocationId, in_kind: &CollectionKind, out_ident: &Ident, out_location: &LocationId, op_meta: &HydroIrOpMetadata, fold_hooked_idents: &HashSet<String>, )
Lowers a HydroNode::Snapshot: windows a singleton-like collection (in_kind must be
a singleton, an optional, or a keyed singleton whose per-key values may change) into the
tick at out_location, so that each firing observes the collection’s current value.
Implementations must reject stream-like in_kinds, which are windowed with
DfirBuilder::batch instead.
fn yield_from_tick( &mut self, in_ident: Ident, in_location: &LocationId, in_kind: &CollectionKind, out_ident: &Ident, out_location: &LocationId, out_kind: &CollectionKind, )
Sourcefn unwindow_for_consume(
&mut self,
in_ident: Ident,
in_location: &LocationId,
out_location: &LocationId,
) -> Ident
fn unwindow_for_consume( &mut self, in_ident: Ident, in_location: &LocationId, out_location: &LocationId, ) -> Ident
Un-windows an ident when it is produced inside a tick’s loop { ... } context
(in_location) but is about to be consumed by an operator emitted at a location
(out_location) outside that loop. Returns the ident to use downstream.
This differs from DfirBuilder::yield_from_tick, which lowers an explicit IR-level
tick exit (HydroNode::YieldConcat, i.e. all_ticks()/latest()) and therefore
always emits a boundary crossing. This method is internal codegen plumbing with no
corresponding IR node: it is used for operators (e.g.
HydroNode::ReduceKeyedWatermark) whose generated code must sit inside a logical tick
while the output is not in a tick, and it only inserts an un-windowing operator when the
producer’s and consumer’s loop contexts actually differ (so it is the identity in
simulation, which emits no loops).
fn begin_atomic( &mut self, in_ident: Ident, in_location: &LocationId, in_kind: &CollectionKind, out_ident: &Ident, out_location: &LocationId, op_meta: &HydroIrOpMetadata, )
fn end_atomic( &mut self, in_ident: Ident, in_location: &LocationId, in_kind: &CollectionKind, out_ident: &Ident, out_kind: &CollectionKind, )
fn observe_nondet( &mut self, trusted: bool, location: &LocationId, in_ident: Ident, in_kind: &CollectionKind, out_ident: &Ident, out_kind: &CollectionKind, op_meta: &HydroIrOpMetadata, )
fn merge_ordered( &mut self, location: &LocationId, first_ident: Ident, second_ident: Ident, out_ident: &Ident, in_kind: &CollectionKind, op_meta: &HydroIrOpMetadata, operator_tag: Option<&str>, )
fn create_network( &mut self, from: &LocationId, to: &LocationId, input_ident: Ident, out_ident: &Ident, serialize: Option<&DebugExpr>, sink: Expr, source: Expr, deserialize: Option<&DebugExpr>, external_element_type: Option<&Type>, tag_id: StmtId, networking_info: &NetworkingInfo, )
fn create_external_source( &mut self, on: &LocationId, source_expr: Expr, out_ident: &Ident, deserialize: Option<&DebugExpr>, tag_id: StmtId, )
fn create_external_output( &mut self, on: &LocationId, sink_expr: Expr, input_ident: &Ident, serialize: Option<&DebugExpr>, tag_id: StmtId, )
Sourcefn emit_fold_hook(
&mut self,
location: &LocationId,
in_ident: &Ident,
in_kind: &CollectionKind,
op_meta: &HydroIrOpMetadata,
) -> Option<Ident>
fn emit_fold_hook( &mut self, location: &LocationId, in_ident: &Ident, in_kind: &CollectionKind, op_meta: &HydroIrOpMetadata, ) -> Option<Ident>
Optionally emit a fold hook that buffers and permutes inputs before the fold. Returns the new input ident to use for the fold if a hook was emitted.
Sourcefn assert_is_consistent(
&mut self,
trusted: bool,
location: &LocationId,
in_ident: Ident,
out_ident: &Ident,
)
fn assert_is_consistent( &mut self, trusted: bool, location: &LocationId, in_ident: Ident, out_ident: &Ident, )
Inserts necessary code to validate a manual assertion that at this point the input live collection is consistent. In production, this is a no-op, but in simulation this will (not yet implemented) inject assertions that validate consistency.
Sourcefn observe_for_mut(
&mut self,
location: &LocationId,
in_ident: Ident,
in_kind: &CollectionKind,
out_ident: &Ident,
op_meta: &HydroIrOpMetadata,
)
fn observe_for_mut( &mut self, location: &LocationId, in_ident: Ident, in_kind: &CollectionKind, out_ident: &Ident, op_meta: &HydroIrOpMetadata, )
Observes non-determinism introduced by a mut closure operating on a non-strict
(unordered / at-least-once) input. In production this is identity; in simulation
it delegates to observe_nondet with the strict output kind.
fn create_versioned_network_fork( &mut self, channel_id: u32, dest: &LocationId, senders: Vec<(LocationId, Ident, Option<DebugExpr>)>, external_element_type: Option<&Type>, tag_id: StmtId, )
fn create_versioned_network( &mut self, channel_id: u32, source: &LocationId, dest: &LocationId, out_ident: &Ident, deserialize: Option<&DebugExpr>, external_element_type: Option<&Type>, tag_id: StmtId, )
Provided Methods§
Sourcefn tick_state_lifetime(&self, _op_location: &LocationId) -> TokenStream
fn tick_state_lifetime(&self, _op_location: &LocationId) -> TokenStream
The DFIR persistence lifetime for operator state scoped to a single tick, for an operator
at op_location.
Returns 'tick. In the future (#2902), production codegen will emit tick regions as DFIR
loop { ... } blocks, where this must instead be 'none when op_location is a tick.
Sourcefn cross_tick_state_lifetime(&self, _op_location: &LocationId) -> TokenStream
fn cross_tick_state_lifetime(&self, _op_location: &LocationId) -> TokenStream
The DFIR persistence lifetime for operator state that accumulates across ticks, for an
operator at op_location.
Returns 'static. In the future (#2902), production codegen will emit tick regions as
DFIR loop { ... } blocks, where this must instead be 'loop when op_location is a
tick.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".