use std::collections::HashSet;
use std::sync::{Arc, OnceLock};
use crate::OpDefRegistration;
use vyre_foundation::ir::OpId;
#[must_use]
pub fn dialect_and_language_supported_ops() -> &'static HashSet<OpId> {
static OPS: OnceLock<HashSet<OpId>> = OnceLock::new();
OPS.get_or_init(|| {
let mut set: HashSet<OpId> = super::validation::default_supported_ops()
.iter()
.cloned()
.collect();
for reg in inventory::iter::<OpDefRegistration> {
let def = (reg.op)();
set.insert(Arc::<str>::from(def.id));
}
set
})
}
#[must_use]
pub fn dialect_only_supported_ops() -> &'static HashSet<OpId> {
static OPS: OnceLock<HashSet<OpId>> = OnceLock::new();
OPS.get_or_init(|| {
inventory::iter::<OpDefRegistration>
.into_iter()
.map(|reg| {
let def = (reg.op)();
Arc::<str>::from(def.id)
})
.collect()
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dialect_set_contains_io_ops() {
let ops = dialect_only_supported_ops();
for op in [
"io.dma_from_nvme",
"io.write_back_to_nvme",
"mem.zerocopy_map",
"mem.unmap",
] {
assert!(
ops.iter().any(|o| o.as_ref() == op),
"dialect set missing {op}; saw {:?}",
ops.iter().map(|o| o.as_ref()).collect::<Vec<_>>().len()
);
}
}
#[test]
fn union_includes_both_sources() {
let union = dialect_and_language_supported_ops();
assert!(union.iter().any(|o| o.as_ref() == "vyre.node.store"));
assert!(union.iter().any(|o| o.as_ref() == "io.dma_from_nvme"));
}
#[test]
fn union_size_exceeds_language_alone() {
let lang = super::super::validation::default_supported_ops().len();
let union = dialect_and_language_supported_ops().len();
assert!(union > lang);
}
}