use std::collections::HashSet;
use std::sync::{Arc, LazyLock};
use vyre_foundation::ir::OpId;
use vyre_foundation::operation::OperationRegistry;
#[must_use]
pub fn dialect_and_language_supported_ops() -> &'static HashSet<OpId> {
static OPS: LazyLock<HashSet<OpId>> = LazyLock::new(|| {
let language_ops = super::validation::default_supported_ops();
let semantic_ops = dialect_only_supported_ops();
let mut set = HashSet::with_capacity(language_ops.len().saturating_add(semantic_ops.len()));
set.extend(language_ops.iter().cloned());
set.extend(semantic_ops.iter().cloned());
set
});
&OPS
}
#[must_use]
pub fn dialect_only_supported_ops() -> &'static HashSet<OpId> {
static OPS: LazyLock<HashSet<OpId>> = LazyLock::new(|| {
OperationRegistry::global()
.iter()
.map(|registration| Arc::<str>::from(registration.id))
.collect()
});
&OPS
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn semantic_set_mirrors_the_operation_registry() {
let ops = dialect_only_supported_ops();
let registry = OperationRegistry::global();
assert_eq!(ops.len(), registry.iter().len());
for operation in registry.iter() {
assert!(
ops.iter().any(|id| id.as_ref() == operation.id),
"semantic set is missing registered operation `{}`",
operation.id
);
}
}
#[test]
fn union_is_exactly_language_plus_semantic() {
let union = dialect_and_language_supported_ops();
let language = super::super::validation::default_supported_ops();
let semantic = dialect_only_supported_ops();
assert!(union.contains(&OpId::from("vyre.node.store")));
for id in language.iter().chain(semantic.iter()) {
assert!(union.contains(id), "union dropped `{id}`");
}
let expected: HashSet<&OpId> = language.iter().chain(semantic.iter()).collect();
assert_eq!(union.len(), expected.len());
}
}