1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! Engine-internal IDs. Wire/IR IDs come from `bb_ir::ids`
//! re-exported here for a single import surface.
//!
//! Each integer ID is a `#[repr(transparent)]` newtype so the
//! borrow checker rejects cross-type substitution.
use std::fmt;
pub use bb_ir::ids::{ComponentTag, OpsetId, PeerId, RequestId};
// --- Macro helpers ----------------------------------------------
macro_rules! u64_id {
($(#[$attr:meta])* $name:ident) => {
$(#[$attr])*
#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord,
serde::Serialize, serde::Deserialize,
)]
#[repr(transparent)]
pub struct $name(u64);
impl $name {
/// Construct from an explicit value.
pub const fn new(inner: u64) -> Self { Self(inner) }
/// Inner value accessor.
pub const fn as_u64(self) -> u64 { self.0 }
}
impl fmt::Display for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}({})", stringify!($name), self.0)
}
}
impl From<u64> for $name {
fn from(inner: u64) -> Self { Self(inner) }
}
};
}
macro_rules! u32_id {
($(#[$attr:meta])* $name:ident) => {
$(#[$attr])*
#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord,
serde::Serialize, serde::Deserialize,
)]
#[repr(transparent)]
pub struct $name(u32);
impl $name {
/// Construct from an explicit value.
pub const fn new(inner: u32) -> Self { Self(inner) }
/// Inner value accessor.
pub const fn as_u32(self) -> u32 { self.0 }
}
impl fmt::Display for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}({})", stringify!($name), self.0)
}
}
impl From<u32> for $name {
fn from(inner: u32) -> Self { Self(inner) }
}
};
}
// --- Engine-internal integer IDs --------------------------------
u64_id! {
/// IR-level value site. Names a slot inside a `GraphProto`'s
/// flow that the engine fills with a slot value.
NodeSiteId
}
u64_id! {
/// Op handle within a graph. Positional refs encode
/// `(graph_idx << 32) | node_idx`; one indexed lookup per
/// invoke, no HashMap probe.
OpRef
}
impl OpRef {
/// Pack a `(graph_idx, node_idx)` into one `OpRef`.
pub const fn pack(graph_idx: u32, node_idx: u32) -> Self {
Self::new(((graph_idx as u64) << 32) | (node_idx as u64))
}
/// Unpack a positional `OpRef`. Globally-counter-minted refs
/// have a zero high half.
pub const fn split(self) -> (u32, u32) {
let v = self.as_u64();
((v >> 32) as u32, v as u32)
}
}
u64_id! {
/// Per-execution identifier; survives async completions and
/// cross-Node wire hops.
ExecId
}
u64_id! {
/// Async-dispatch command id finalized via
/// `ctx.complete_command(cmd, outputs)`.
CommandId
}
u32_id! {
/// Dense per-Node component instance handle.
ComponentRef
}