dfir_rs/scheduled/context.rs
1//! Module for the inline DFIR runtime context and execution engine.
2//!
3//! Provides [`Context`] (the lightweight operator context) and
4//! [`Dfir`] (the dataflow execution wrapper).
5
6use std::future::Future;
7use std::marker::PhantomData;
8use std::pin::Pin;
9use std::sync::Arc;
10use std::sync::atomic::Ordering;
11use std::task::Wake;
12
13#[cfg(feature = "meta")]
14use dfir_lang::diagnostic::{Diagnostic, Diagnostics, SerdeSpan};
15#[cfg(feature = "meta")]
16use dfir_lang::graph::DfirGraph;
17
18use super::metrics::{DfirMetrics, DfirMetricsIntervals, MetricsState};
19use crate::scheduled::ticks::TickInstant;
20
21/// Coordinates waking between [`Context`] (inside the tick closure) and [`Dfir`]
22/// (the external runner). Shared via `Arc` between both.
23///
24/// When external data arrives (e.g., a tokio stream receives a message), the [`Context::waker`]
25/// fires, which sets `can_start_tick` and wakes the [`Dfir::run`](Dfir::run) task so it starts a new tick.
26/// Implements [`Wake`] directly so it can be used as a `Waker` without an extra wrapper.
27#[doc(hidden)]
28pub struct WakeState {
29 /// Set to `true` when external data arrives, signaling that a new tick should run.
30 /// Checked by [`Dfir::run_tick`](Dfir::run_tick) and [`Dfir::run_available`](Dfir::run_available).
31 can_start_tick: std::sync::atomic::AtomicBool,
32 /// Wakes the [`Dfir::run`](Dfir::run) task from its idle `poll_fn` sleep.
33 task_waker: futures::task::AtomicWaker,
34}
35
36impl Default for WakeState {
37 fn default() -> Self {
38 Self {
39 can_start_tick: std::sync::atomic::AtomicBool::new(false),
40 task_waker: futures::task::AtomicWaker::new(),
41 }
42 }
43}
44
45impl Wake for WakeState {
46 fn wake(self: Arc<Self>) {
47 self.wake_by_ref();
48 }
49
50 fn wake_by_ref(self: &Arc<Self>) {
51 self.can_start_tick.store(true, Ordering::Relaxed);
52 self.task_waker.wake();
53 }
54}
55
56/// A lightweight context for inline codegen that avoids the overhead of the full
57/// scheduled graph (no tokio channels, no scheduler queues, no loop machinery).
58///
59/// Exposes methods that operator-generated code calls on both
60/// `df` (for prologues: `request_task`) and
61/// `context` (for iterators: `current_tick`, `schedule_subgraph`, etc.).
62///
63/// # Metrics typestate
64///
65/// The `M` type parameter is a [`MetricsState`] typestate which statically records whether this
66/// context tracks runtime metrics:
67///
68/// - `Context<DfirMetrics>` (the default) is created via [`Context::new_with_metrics`] and holds
69/// a shared `Arc<DfirMetrics>` handle, accessible via [`Context::metrics`].
70/// - `Context<()>` is created via [`Context::new`] and holds no metrics state whatsoever. The
71/// `metrics()` accessor does not exist on it, so it is a compile error to try to read metrics
72/// from a context which never tracked them.
73pub struct Context<M: MetricsState = DfirMetrics> {
74 /// Counter for number of ticks run.
75 current_tick: TickInstant,
76 /// Coordinates waking between [`Context`] (inside the tick closure) and [`Dfir`]
77 /// (the external runner). Shared via `Arc` between both. Implements [`Wake`].
78 wake_state: Arc<WakeState>,
79 /// Live-updating DFIR runtime metrics via atomics (`Arc<DfirMetrics>`), or `()`
80 /// when metrics are not tracked.
81 metrics: M::Handle,
82 /// Tasks buffered via [`Self::request_task`], spawned via [`tokio::spawn`] by
83 /// [`Dfir::spawn_tasks`] once the runtime is running inside a tokio runtime.
84 ///
85 /// Futures are required to be `Send` so that `Context` (and therefore [`Dfir`]) can be moved
86 /// between threads before being run, and so that the tasks can be spawned onto any tokio
87 /// runtime (no `LocalSet` required).
88 #[cfg(feature = "tokio")]
89 tasks_to_spawn: Vec<Pin<Box<dyn Future<Output = ()> + Send + 'static>>>,
90}
91
92impl Context<()> {
93 /// Create a new inline context with a fresh wake state and **no** metrics tracking.
94 ///
95 /// The returned `Context<()>` statically contains no metrics state. Use
96 /// [`Context::new_with_metrics`] to create a `Context<DfirMetrics>` which tracks metrics.
97 pub fn new() -> Self {
98 Self::with_metrics_handle(())
99 }
100}
101
102impl Default for Context<()> {
103 fn default() -> Self {
104 Self::new()
105 }
106}
107
108impl Context<DfirMetrics> {
109 /// Create a new inline context with a fresh wake state and the given (pre-populated) metrics.
110 pub fn new_with_metrics(metrics: DfirMetrics) -> Self {
111 Self::with_metrics_handle(Arc::new(metrics))
112 }
113
114 /// Returns a reference to the runtime metrics.
115 pub fn metrics(&self) -> &Arc<DfirMetrics> {
116 &self.metrics
117 }
118}
119
120impl<M: MetricsState> Context<M> {
121 fn with_metrics_handle(metrics: M::Handle) -> Self {
122 Self {
123 current_tick: TickInstant::default(),
124 wake_state: Arc::default(),
125 metrics,
126 #[cfg(feature = "tokio")]
127 tasks_to_spawn: Vec::new(),
128 }
129 }
130
131 // --- Methods called as `df.xxx()` in operator prologues ---
132
133 /// Buffers an async task to be spawned later by `Dfir::spawn_tasks`.
134 ///
135 /// Tasks are deferred because `write_prologue` runs during graph construction,
136 /// which may occur before a tokio runtime is entered. Buffered tasks are
137 /// drained and spawned via [`tokio::spawn`] at the start of
138 /// [`Dfir::run_tick`]. Tasks requested after that point remain buffered until
139 /// the next call to [`Dfir::run_tick`].
140 ///
141 /// The future must be `Send` so that the `Context` remains `Send` and so the task can be
142 /// spawned onto any tokio runtime.
143 #[cfg(feature = "tokio")]
144 pub fn request_task<Fut>(&mut self, future: Fut)
145 where
146 Fut: Future<Output = ()> + Send + 'static,
147 {
148 self.tasks_to_spawn.push(Box::pin(future));
149 }
150
151 // --- Methods called as `context.xxx()` in operator iterators ---
152
153 /// Gets the current tick count.
154 pub fn current_tick(&self) -> TickInstant {
155 self.current_tick
156 }
157
158 /// Signals that external data has arrived and a new tick should be started.
159 pub fn schedule_subgraph(&self, is_external: bool) {
160 if is_external {
161 self.wake_state.wake_by_ref();
162 }
163 }
164
165 /// Returns a waker that signals external data has arrived.
166 pub fn waker(&self) -> std::task::Waker {
167 std::task::Waker::from(self.wake_state.clone())
168 }
169
170 /// Increments the tick counter.
171 /// Called by the generated tick closure at the end of each tick.
172 #[doc(hidden)]
173 pub fn __end_tick(&mut self) {
174 self.current_tick += crate::scheduled::ticks::TickDuration::SINGLE_TICK;
175 }
176}
177
178/// An executable DFIR dataflow, as created by
179/// [`dfir_syntax!`](crate::dfir_syntax). Provides the [`Self::run`],
180/// [`Self::run_available`], and [`Self::run_tick`] family of methods to
181/// execute the dataflow.
182///
183/// # Design
184///
185/// The inline codegen generates an `async move |df: &mut Context<M>|` closure that captures
186/// dataflow-specific state (handoff buffers, source iterators) and receives the [`Context`]
187/// (tick counter, metrics) by reference each tick. `Dfir` owns both the
188/// closure and the context, and coordinates tick lifecycle and idle/wake behavior.
189///
190/// We use a single opaque closure rather than generating a bespoke struct per dataflow because:
191/// - The closure naturally captures exactly the state it needs with correct lifetimes
192/// - No codegen needed for struct definitions, field accessors, or initialization
193/// - Rust's async closure machinery handles the complex state machine (suspend/resume across
194/// `.await` points) that would be very difficult to replicate in a generated struct
195///
196/// The `Tick` type parameter is bounded by [`TickClosure`] (not `AsyncFnMut` directly) to
197/// support type erasure via [`TickClosureErased`] / [`DfirErased`] for heterogeneous
198/// collections (e.g., the sim runtime storing multiple locations in a `Vec`). The concrete
199/// (non-erased) path used by trybuild and embedded has zero overhead.
200///
201/// # Metrics
202///
203/// Whether this `Dfir` tracks runtime metrics is determined statically by
204/// [`TickClosure::Metrics`] (see [`MetricsState`]). The [`Self::metrics`] and
205/// [`Self::metrics_intervals`] accessors only exist when `Tick::Metrics = DfirMetrics`. When
206/// returning a `Dfir` from a function via `impl TickClosure`, use
207/// `Dfir<impl TickClosure<Metrics = DfirMetrics>>` if callers need to access the metrics.
208pub struct Dfir<Tick: TickClosure> {
209 /// Async closure which runs a single tick when called.
210 tick_closure: Tick,
211 /// Coordinates waking between [`Context`] (inside the tick closure) and [`Dfir`]
212 /// (the external runner). Shared via `Arc` between both. Implements [`Wake`].
213 wake_state: Arc<WakeState>,
214 /// The inline context, owned by `Dfir` and passed to the tick closure by reference.
215 context: Context<Tick::Metrics>,
216 /// See [`Self::meta_graph()`].
217 ///
218 /// Stored as the serialized JSON string rather than a deserialized [`DfirGraph`], since
219 /// `DfirGraph` contains `proc_macro2` types which are `!Send`. Deserialized on demand.
220 #[cfg(feature = "meta")]
221 meta_graph_json: Option<String>,
222 /// See [`Self::diagnostics()`].
223 #[cfg(feature = "meta")]
224 diagnostics: Option<Vec<Diagnostic<SerdeSpan>>>,
225}
226
227/// Trait for tick closures — abstracts over both concrete async closures (wrapped in
228/// [`TickClosureFn`]) and type-erased boxed versions ([`TickClosureErased`]).
229///
230/// The `&mut Context` parameter is owned by [`Dfir`] and lent to the
231/// closure each tick, avoiding shared-ownership overhead for the context.
232///
233/// The [`Self::Metrics`] associated type carries the [`MetricsState`] typestate of the context the
234/// closure expects, so that [`Dfir<Tick>`] can be parameterized by the closure alone.
235pub trait TickClosure {
236 /// Whether the context passed to this closure tracks metrics. See [`MetricsState`].
237 type Metrics: MetricsState;
238
239 /// Call the tick closure. Returns `true` if any subgraph received input data.
240 #[doc(hidden)]
241 fn call_tick<'a>(
242 &'a mut self,
243 ctx: &'a mut Context<Self::Metrics>,
244 ) -> impl Future<Output = bool> + 'a;
245}
246
247/// Wraps an `AsyncFnMut(&mut Context<M>) -> bool` closure as a [`TickClosure`].
248///
249/// A blanket `impl<M, F: AsyncFnMut(&mut Context<M>)> TickClosure for F` is not allowed
250/// since `M` would only be constrained via the `AsyncFnMut` bound (E0207), so the generated code
251/// wraps the tick closure in this newtype which carries `M` explicitly.
252#[doc(hidden)]
253pub struct TickClosureFn<M, F> {
254 func: F,
255 _metrics: PhantomData<fn() -> M>,
256}
257
258impl<M, F> TickClosureFn<M, F>
259where
260 M: MetricsState,
261 F: for<'a> AsyncFnMut(&'a mut Context<M>) -> bool,
262{
263 /// Wrap the given async tick closure.
264 pub fn new(func: F) -> Self {
265 Self {
266 func,
267 _metrics: PhantomData,
268 }
269 }
270}
271
272impl<M, F> TickClosure for TickClosureFn<M, F>
273where
274 M: MetricsState,
275 F: for<'a> AsyncFnMut(&'a mut Context<M>) -> bool,
276{
277 type Metrics = M;
278
279 fn call_tick<'a>(&'a mut self, ctx: &'a mut Context<M>) -> impl Future<Output = bool> + 'a {
280 (self.func)(ctx)
281 }
282}
283
284/// No-op `TickClosure`. Used by `dfir_syntax!` as a stand-in when codegen fails, so its
285/// `Metrics` matches the macro's default (metrics tracking enabled).
286#[doc(hidden)]
287pub struct NullTickClosure;
288
289impl TickClosure for NullTickClosure {
290 type Metrics = DfirMetrics;
291
292 fn call_tick<'a>(
293 &'a mut self,
294 _ctx: &'a mut Context<DfirMetrics>,
295 ) -> impl Future<Output = bool> + 'a {
296 std::future::ready(false)
297 }
298}
299
300/// Type-erased tick function for use in heterogeneous collections (e.g., the sim runtime).
301#[doc(hidden)]
302pub struct TickClosureErased<M: MetricsState = DfirMetrics>(Box<dyn TickClosureErasedInner<M>>);
303
304/// Object-safe inner trait for [`TickClosureErased`]. Needed because [`TickClosure::call_tick`]
305/// returns `impl Future` (not object-safe), but a trait with `&mut self -> Pin<Box<dyn Future + '_>>`
306/// is — the returned future borrows from the trait object which owns the closure.
307trait TickClosureErasedInner<M: MetricsState> {
308 fn call_tick<'a>(
309 &'a mut self,
310 ctx: &'a mut Context<M>,
311 ) -> Pin<Box<dyn Future<Output = bool> + 'a>>;
312}
313
314impl<Tick: TickClosure> TickClosureErasedInner<Tick::Metrics> for Tick {
315 fn call_tick<'a>(
316 &'a mut self,
317 ctx: &'a mut Context<Tick::Metrics>,
318 ) -> Pin<Box<dyn Future<Output = bool> + 'a>> {
319 Box::pin(TickClosure::call_tick(self, ctx))
320 }
321}
322
323impl<M: MetricsState> TickClosure for TickClosureErased<M> {
324 type Metrics = M;
325
326 fn call_tick<'a>(&'a mut self, ctx: &'a mut Context<M>) -> impl Future<Output = bool> + 'a {
327 self.0.call_tick(ctx)
328 }
329}
330
331/// Type alias for a type-erased [`Dfir`] that can be stored in heterogeneous collections.
332/// Created via [`Dfir::into_erased`].
333///
334/// `M` is the [`MetricsState`] of the erased dataflow: `DfirMetrics` (the default) if metrics
335/// are tracked, or `()` if not.
336pub type DfirErased<M = DfirMetrics> = Dfir<TickClosureErased<M>>;
337
338impl<Tick: TickClosure> Dfir<Tick> {
339 /// Create a new `Dfir` from a tick closure, inline context,
340 /// and meta graph / diagnostics JSON strings.
341 #[doc(hidden)]
342 pub fn new(
343 tick_closure: Tick,
344 context: Context<Tick::Metrics>,
345 meta_graph_json: Option<&str>,
346 diagnostics_json: Option<&str>,
347 ) -> Self {
348 #[cfg(not(feature = "meta"))]
349 let _ = (meta_graph_json, diagnostics_json);
350 Self {
351 tick_closure,
352 wake_state: context.wake_state.clone(),
353 context,
354 #[cfg(feature = "meta")]
355 meta_graph_json: meta_graph_json.map(str::to_owned),
356 #[cfg(feature = "meta")]
357 diagnostics: diagnostics_json.map(|json| {
358 serde_json::from_str(json).expect("Failed to deserialize diagnostics.")
359 }),
360 }
361 }
362
363 /// Returns the meta graph, if set.
364 ///
365 /// The graph is deserialized from its JSON representation on each call, so callers which need
366 /// it multiple times should store the result.
367 #[cfg(feature = "meta")]
368 #[cfg_attr(docsrs, doc(cfg(feature = "meta")))]
369 pub fn meta_graph(&self) -> Option<DfirGraph> {
370 self.meta_graph_json.as_deref().map(|json| {
371 let mut meta_graph: DfirGraph =
372 serde_json::from_str(json).expect("Failed to deserialize graph.");
373 let mut op_inst_diagnostics = Diagnostics::new();
374 meta_graph.insert_node_op_insts_all(&mut op_inst_diagnostics);
375 assert!(
376 op_inst_diagnostics.is_empty(),
377 "Expected no diagnostics, got: {:#?}",
378 op_inst_diagnostics
379 );
380 meta_graph
381 })
382 }
383
384 /// Returns any diagnostics generated by the surface syntax macro.
385 #[cfg(feature = "meta")]
386 #[cfg_attr(docsrs, doc(cfg(feature = "meta")))]
387 pub fn diagnostics(&self) -> Option<&[Diagnostic<SerdeSpan>]> {
388 self.diagnostics.as_deref()
389 }
390
391 /// Gets the current tick (local time) count.
392 pub fn current_tick(&self) -> TickInstant {
393 self.context.current_tick()
394 }
395}
396
397/// Metrics accessors, only available when metrics tracking is enabled (`Tick::Metrics = DfirMetrics`).
398impl<Tick: TickClosure<Metrics = DfirMetrics>> Dfir<Tick> {
399 /// Returns a reference-counted handle to the continually-updated runtime metrics for this DFIR instance.
400 ///
401 /// Only available when metrics tracking is enabled, see [`MetricsState`].
402 pub fn metrics(&self) -> Arc<DfirMetrics> {
403 Arc::clone(self.context.metrics())
404 }
405
406 /// Returns a [`DfirMetricsIntervals`] handle where each call to
407 /// [`DfirMetricsIntervals::take_interval`] ends the current interval and returns its metrics.
408 ///
409 /// The first call to `take_interval` returns metrics since this DFIR instance was created. Each subsequent call to
410 /// `take_interval` returns metrics since the previous call.
411 ///
412 /// Cloning the handle "forks" it from the original, as afterwards each interval may return different metrics
413 /// depending on when exactly `take_interval` is called.
414 ///
415 /// Only available when metrics tracking is enabled, see [`MetricsState`].
416 pub fn metrics_intervals(&self) -> DfirMetricsIntervals {
417 DfirMetricsIntervals {
418 curr: self.metrics(),
419 prev: None,
420 }
421 }
422}
423
424impl<Tick: TickClosure> Dfir<Tick> {
425 /// Spawns all tasks buffered via [`Context::request_task`] onto the current tokio runtime.
426 ///
427 /// This drains the buffer, so subsequent calls are no-ops until new tasks are requested.
428 ///
429 /// # Panics
430 ///
431 /// Panics if there are buffered tasks and this is called outside of a tokio runtime.
432 #[cfg(feature = "tokio")]
433 fn spawn_tasks(&mut self) {
434 for task in self.context.tasks_to_spawn.drain(..) {
435 tokio::spawn(task);
436 }
437 }
438
439 /// Run a single tick. Returns `true` if any subgraph received input data.
440 ///
441 /// Checks both handoff buffers (via `work_done` flag set in generated recv port code)
442 /// and external events (via `can_start_tick` set by `waker`/`schedule_subgraph`).
443 pub async fn run_tick(&mut self) -> bool {
444 #[cfg(feature = "tokio")]
445 self.spawn_tasks();
446 let had_external = self
447 .wake_state
448 .can_start_tick
449 .swap(false, Ordering::Relaxed);
450 let tick_had_work = self.tick_closure.call_tick(&mut self.context).await;
451 had_external || tick_had_work || self.wake_state.can_start_tick.load(Ordering::Relaxed)
452 }
453
454 /// Run a single tick synchronously. Panics if the tick yields (async suspension).
455 /// Returns `true` if work was done (see [`Self::run_tick`]).
456 pub fn run_tick_sync(&mut self) -> bool {
457 let mut fut = std::pin::pin!(self.run_tick());
458 let mut ctx = std::task::Context::from_waker(std::task::Waker::noop());
459 match fut.as_mut().poll(&mut ctx) {
460 std::task::Poll::Ready(result) => result,
461 std::task::Poll::Pending => {
462 panic!("Dfir::run_tick_sync: tick yielded asynchronously.")
463 }
464 }
465 }
466
467 /// Run ticks as long as work is available, then return.
468 #[cfg(feature = "tokio")]
469 pub async fn run_available(&mut self) {
470 // Always run at least one tick.
471 self.wake_state
472 .can_start_tick
473 .store(false, Ordering::Relaxed);
474 loop {
475 self.run_tick().await;
476 let can_start_tick = self
477 .wake_state
478 .can_start_tick
479 .swap(false, Ordering::Relaxed);
480 if !can_start_tick {
481 break;
482 }
483 // Yield between each tick to receive more events.
484 tokio::task::yield_now().await;
485 }
486 }
487
488 /// [`Self::run_available`] but panics if any tick yields asynchronously.
489 pub fn run_available_sync(&mut self) {
490 self.wake_state
491 .can_start_tick
492 .store(false, Ordering::Relaxed);
493 loop {
494 self.run_tick_sync();
495 let can_start_tick = self
496 .wake_state
497 .can_start_tick
498 .swap(false, Ordering::Relaxed);
499 if !can_start_tick {
500 break;
501 }
502 }
503 }
504
505 /// Run forever, processing ticks when work is available and yielding when idle.
506 #[cfg(feature = "tokio")]
507 pub async fn run(&mut self) -> crate::Never {
508 loop {
509 self.run_available().await;
510 // Wait for an external event to wake us.
511 std::future::poll_fn(|cx| {
512 // Register waker first to avoid race: if an event fires between
513 // the check and the register, the waker is already in place.
514 self.wake_state.task_waker.register(cx.waker());
515 if self.wake_state.can_start_tick.load(Ordering::Relaxed) {
516 std::task::Poll::Ready(())
517 } else {
518 std::task::Poll::Pending
519 }
520 })
521 .await;
522 }
523 }
524}
525
526impl<Tick: TickClosure> Dfir<Tick> {
527 /// Replaces the tick closure with `f(tick_closure)`, keeping the rest of the dataflow (its
528 /// context, wake state and meta graph). Lets a runner wrap every tick, e.g. to catch panics
529 /// raised by the dataflow at the boundary of the code that compiled it.
530 #[doc(hidden)]
531 pub fn map_tick_closure<Tick2: TickClosure<Metrics = Tick::Metrics>>(
532 self,
533 f: impl FnOnce(Tick) -> Tick2,
534 ) -> Dfir<Tick2> {
535 Dfir {
536 tick_closure: f(self.tick_closure),
537 wake_state: self.wake_state,
538 context: self.context,
539 #[cfg(feature = "meta")]
540 meta_graph_json: self.meta_graph_json,
541 #[cfg(feature = "meta")]
542 diagnostics: self.diagnostics,
543 }
544 }
545}
546
547impl<Tick: TickClosure + 'static> Dfir<Tick> {
548 /// Type-erase the tick closure for use in heterogeneous collections.
549 ///
550 /// Wraps the concrete tick closure in [`TickClosureErased`], which boxes the future
551 /// returned by each tick call. This adds one heap allocation per tick, but enables
552 /// storing multiple `Dfir`s with different closure types in a single `Vec`.
553 ///
554 /// The [`MetricsState`] typestate is preserved: the result is `DfirErased<Tick::Metrics>`.
555 ///
556 /// Only needed for the sim runtime path. The trybuild and embedded paths keep the
557 /// concrete type and pay no erasure cost.
558 pub fn into_erased(self) -> DfirErased<Tick::Metrics> {
559 Dfir {
560 tick_closure: TickClosureErased(Box::new(self.tick_closure)),
561 wake_state: self.wake_state,
562 context: self.context,
563 #[cfg(feature = "meta")]
564 meta_graph_json: self.meta_graph_json,
565 #[cfg(feature = "meta")]
566 diagnostics: self.diagnostics,
567 }
568 }
569}
570
571#[cfg(test)]
572mod tests {
573 use std::future::ready;
574
575 use static_assertions::assert_impl_all;
576
577 use super::{Context, Dfir, NullTickClosure, TickClosure};
578 use crate::scheduled::metrics::{
579 AtomicCount, AtomicDuration, DfirMetrics, DfirMetricsIntervals,
580 };
581
582 struct SendTick;
583
584 impl TickClosure for SendTick {
585 type Metrics = ();
586
587 fn call_tick<'a>(
588 &'a mut self,
589 _ctx: &'a mut Context<()>,
590 ) -> impl Future<Output = bool> + 'a {
591 ready(false)
592 }
593 }
594
595 // Without metrics tracking.
596 assert_impl_all!(Context<()>: Send);
597 assert_impl_all!(Dfir<SendTick>: Send);
598
599 // With metrics tracking (`NullTickClosure` has `Metrics = DfirMetrics`).
600 assert_impl_all!(AtomicCount: Send, Sync);
601 assert_impl_all!(AtomicDuration: Send, Sync);
602 assert_impl_all!(DfirMetrics: Send, Sync);
603 assert_impl_all!(DfirMetricsIntervals: Send);
604 assert_impl_all!(Context<DfirMetrics>: Send);
605 assert_impl_all!(Dfir<NullTickClosure>: Send);
606}