vyre_libs/buffer_names.rs
1//! Deterministic buffer naming for generic Cat-A builder aliases.
2//!
3//! Some vyre-libs builders historically accepted generic names such as
4//! `"input"`, `"output"`, `"decoded"`, or `"out"`. When multiple Programs were
5//! fused into one rule kernel, those aliases could collide with unrelated
6//! buffers across families. This module rewrites only the generic aliases into
7//! stable family-scoped names while preserving caller-specified explicit names.
8
9/// Stable internal buffer name for a family-local role.
10#[must_use]
11pub(crate) fn fixed_name(family_prefix: &str, role: &str) -> String {
12 format!("__vyre_{family_prefix}_{role}")
13}
14
15/// Rewrite a generic buffer name into a stable family-local name.
16///
17/// Explicit caller-provided names are preserved so intentional composition can
18/// still route buffers by name.
19#[must_use]
20pub fn scoped_generic_name(
21 family_prefix: &str,
22 role: &str,
23 requested: &str,
24 generic_aliases: &[&str],
25) -> String {
26 if generic_aliases.iter().any(|alias| *alias == requested) {
27 fixed_name(family_prefix, role)
28 } else {
29 requested.to_string()
30 }
31}