Skip to main content

tenferro_runtime/program/
import.rs

1use std::fmt;
2
3use super::{ProgramBindings, ProgramValue, SemanticProgram};
4
5/// Read-only request to import the dependency closure of ordered roots.
6pub struct ProgramImport<'a> {
7    /// Immutable source semantic program.
8    pub program: &'a SemanticProgram,
9    /// Tensor bindings frozen with the source program.
10    pub bindings: &'a ProgramBindings,
11    /// Ordered source roots to remap; empty and duplicate roots are valid.
12    pub roots: &'a [ProgramValue],
13}
14
15impl fmt::Debug for ProgramImport<'_> {
16    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
17        formatter
18            .debug_struct("ProgramImport")
19            .field("program_inputs", &self.program.inputs().len())
20            .field("program_outputs", &self.program.outputs().len())
21            .field("bindings", &self.bindings.len())
22            .field("roots", &self.roots.len())
23            .finish()
24    }
25}
26
27/// Destination-builder values corresponding to requested import roots.
28pub struct ImportedProgramValues {
29    roots: Box<[ProgramValue]>,
30}
31
32impl ImportedProgramValues {
33    pub(crate) fn new(roots: Box<[ProgramValue]>) -> Self {
34        Self { roots }
35    }
36
37    /// Borrow imported roots in request order, including duplicates.
38    pub fn roots(&self) -> &[ProgramValue] {
39        &self.roots
40    }
41}
42
43impl fmt::Debug for ImportedProgramValues {
44    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
45        formatter
46            .debug_struct("ImportedProgramValues")
47            .field("roots", &self.roots.len())
48            .finish()
49    }
50}