Skip to main content

jeff/reader/value/
wire_value.rs

1//! Wire values representing typed hyperedges in dataflow regions.
2
3use super::ValueId;
4use crate::capnp::jeff_capnp;
5use crate::reader::metadata::sealed::HasMetadataSealed;
6use crate::reader::string_table::StringTable;
7
8use crate::types::Type;
9
10/// Wire type and associated metadata.
11///
12/// Ports in the dataflow graph reference these values by their index in the
13/// function's value array.
14///
15/// This corresponds to a jeff format `WireValue`, with a defined ID identifying
16/// it in a [`ValueTable`][super::ValueTable].
17#[derive(Clone, Copy, Debug)]
18pub struct WireValue<'a> {
19    /// The ID of this value in the function's [`ValueTable`][super::ValueTable].
20    id: ValueId,
21    /// Type of the hyperedge.
22    pub(super) value_type: Type,
23    /// Metadata associated with the value.
24    pub(super) metadata: capnp::struct_list::Reader<'a, jeff_capnp::meta::Owned>,
25    /// Module-level register of reused strings.
26    pub(super) strings: StringTable<'a>,
27}
28
29impl<'a> WireValue<'a> {
30    /// Create a new function view from a capnp reader.
31    pub(crate) fn read_capnp(
32        id: super::ValueId,
33        value: jeff_capnp::value::Reader<'a>,
34        strings: StringTable<'a>,
35    ) -> Self {
36        let value_type = value
37            .get_type()
38            .map(Type::read_capnp)
39            .expect("Type should be present");
40        let metadata = value.get_metadata().expect("Metadata should be present");
41        Self {
42            id,
43            value_type,
44            metadata,
45            strings,
46        }
47    }
48
49    /// Returns the ID of this value in the containing function's [`ValueTable`][super::ValueTable].
50    pub fn id(&self) -> ValueId {
51        self.id
52    }
53
54    /// Returns the type of this value.
55    pub fn ty(&self) -> Type {
56        self.value_type
57    }
58}
59
60impl<'a> HasMetadataSealed for WireValue<'a> {
61    fn strings(&self) -> StringTable<'a> {
62        self.strings
63    }
64
65    fn metadata_reader(&self) -> capnp::struct_list::Reader<'a, jeff_capnp::meta::Owned> {
66        self.metadata
67    }
68}