use crate::{PrimitiveOp, VerificationDomain, ViolationKind, WittLevel};
use core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
impl Sealed for super::GroundedCoord {}
impl<const N: usize> Sealed for super::GroundedTuple<N> {}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(clippy::large_enum_variant, dead_code)]
pub(crate) enum DatumInner {
W8([u8; 1]),
W16([u8; 2]),
W24([u8; 3]),
W32([u8; 4]),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Datum {
inner: DatumInner,
}
impl Datum {
#[inline]
#[must_use]
pub const fn level(&self) -> WittLevel {
match self.inner {
DatumInner::W8(_) => WittLevel::W8,
DatumInner::W16(_) => WittLevel::W16,
DatumInner::W24(_) => WittLevel::new(24),
DatumInner::W32(_) => WittLevel::new(32),
}
}
#[inline]
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
match &self.inner {
DatumInner::W8(b) => b,
DatumInner::W16(b) => b,
DatumInner::W24(b) => b,
DatumInner::W32(b) => b,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(clippy::large_enum_variant, dead_code)]
pub(crate) enum GroundedCoordInner {
W8([u8; 1]),
W16([u8; 2]),
W24([u8; 3]),
W32([u8; 4]),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GroundedCoord {
pub(crate) inner: GroundedCoordInner,
}
impl GroundedCoord {
#[inline]
#[must_use]
pub const fn w8(value: u8) -> Self {
Self {
inner: GroundedCoordInner::W8(value.to_le_bytes()),
}
}
#[inline]
#[must_use]
pub const fn w16(value: u16) -> Self {
Self {
inner: GroundedCoordInner::W16(value.to_le_bytes()),
}
}
#[inline]
#[must_use]
pub const fn w24(value: u32) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 3];
let mut i = 0;
while i < 3 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W24(out),
}
}
#[inline]
#[must_use]
pub const fn w32(value: u32) -> Self {
Self {
inner: GroundedCoordInner::W32(value.to_le_bytes()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GroundedTuple<const N: usize> {
pub(crate) coords: [GroundedCoord; N],
}
impl<const N: usize> GroundedTuple<N> {
#[inline]
#[must_use]
pub const fn new(coords: [GroundedCoord; N]) -> Self {
Self { coords }
}
}
pub trait GroundedValue: sealed::Sealed {}
impl GroundedValue for GroundedCoord {}
impl<const N: usize> GroundedValue for GroundedTuple<N> {}
pub trait Grounding {
type Output: GroundedValue;
fn ground(&self, external: &[u8]) -> Option<Self::Output>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Validated<T> {
inner: T,
_sealed: (),
}
impl<T> Validated<T> {
#[inline]
#[must_use]
pub fn inner(&self) -> &T {
&self.inner
}
#[inline]
#[allow(dead_code)]
pub(crate) const fn new(inner: T) -> Self {
Self { inner, _sealed: () }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Derivation {
step_count: u32,
root_address: u64,
}
impl Derivation {
#[inline]
#[must_use]
pub const fn step_count(&self) -> u32 {
self.step_count
}
#[inline]
#[must_use]
pub const fn root_address(&self) -> u64 {
self.root_address
}
#[inline]
#[allow(dead_code)]
pub(crate) const fn new(step_count: u32, root_address: u64) -> Self {
Self {
step_count,
root_address,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FreeRank {
total: u32,
pinned: u32,
}
impl FreeRank {
#[inline]
#[must_use]
pub const fn total(&self) -> u32 {
self.total
}
#[inline]
#[must_use]
pub const fn pinned(&self) -> u32 {
self.pinned
}
#[inline]
#[must_use]
pub const fn remaining(&self) -> u32 {
self.total - self.pinned
}
#[inline]
#[allow(dead_code)]
pub(crate) const fn new(total: u32, pinned: u32) -> Self {
Self { total, pinned }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TermList {
pub start: u32,
pub len: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TermArena<const CAP: usize> {
nodes: [Option<Term>; CAP],
len: u32,
}
impl<const CAP: usize> TermArena<CAP> {
#[inline]
#[must_use]
pub fn new() -> Self {
Self {
nodes: core::array::from_fn(|_| None),
len: 0,
}
}
#[must_use]
pub fn push(&mut self, term: Term) -> Option<u32> {
let idx = self.len;
if (idx as usize) >= CAP {
return None;
}
self.nodes[idx as usize] = Some(term);
self.len = idx + 1;
Some(idx)
}
#[inline]
#[must_use]
pub fn get(&self, index: u32) -> Option<&Term> {
self.nodes
.get(index as usize)
.and_then(|slot| slot.as_ref())
}
#[inline]
#[must_use]
pub const fn len(&self) -> u32 {
self.len
}
#[inline]
#[must_use]
pub const fn is_empty(&self) -> bool {
self.len == 0
}
}
impl<const CAP: usize> Default for TermArena<CAP> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Term {
Literal {
value: u64,
level: WittLevel,
},
Variable {
name_index: u32,
},
Application {
operator: PrimitiveOp,
args: TermList,
},
Lift {
operand_index: u32,
target: WittLevel,
},
Project {
operand_index: u32,
target: WittLevel,
},
Match {
scrutinee_index: u32,
arms: TermList,
},
Recurse {
measure_index: u32,
base_index: u32,
step_index: u32,
},
Unfold {
seed_index: u32,
step_index: u32,
},
Try {
body_index: u32,
handler_index: u32,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypeDeclaration {
pub name_index: u32,
pub constraints: TermList,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Binding {
pub name_index: u32,
pub type_index: u32,
pub value_index: u32,
pub surface: &'static str,
pub content_address: u64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Assertion {
pub lhs_index: u32,
pub rhs_index: u32,
pub surface: &'static str,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceDeclaration {
pub name_index: u32,
pub type_index: u32,
pub grounding_name_index: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SinkDeclaration {
pub name_index: u32,
pub type_index: u32,
pub projection_name_index: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShapeViolation {
pub shape_iri: &'static str,
pub constraint_iri: &'static str,
pub property_iri: &'static str,
pub expected_range: &'static str,
pub min_count: u32,
pub max_count: u32,
pub kind: ViolationKind,
}
#[derive(Debug, Clone)]
pub struct CompileUnitBuilder<'a> {
root_term: Option<&'a [Term]>,
witt_level_ceiling: Option<WittLevel>,
thermodynamic_budget: Option<u64>,
target_domains: Option<&'a [VerificationDomain]>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CompileUnit {
level: WittLevel,
budget: u64,
}
impl<'a> CompileUnitBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
root_term: None,
witt_level_ceiling: None,
thermodynamic_budget: None,
target_domains: None,
}
}
#[must_use]
pub const fn root_term(mut self, terms: &'a [Term]) -> Self {
self.root_term = Some(terms);
self
}
#[must_use]
pub const fn witt_level_ceiling(mut self, level: WittLevel) -> Self {
self.witt_level_ceiling = Some(level);
self
}
#[must_use]
pub const fn thermodynamic_budget(mut self, budget: u64) -> Self {
self.thermodynamic_budget = Some(budget);
self
}
#[must_use]
pub const fn target_domains(mut self, domains: &'a [VerificationDomain]) -> Self {
self.target_domains = Some(domains);
self
}
pub fn validate(self) -> Result<Validated<CompileUnit>, ShapeViolation> {
if self.root_term.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_rootTerm_constraint",
property_iri: "https://uor.foundation/reduction/rootTerm",
expected_range: "https://uor.foundation/schema/Term",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
let level =
match self.witt_level_ceiling {
Some(l) => l,
None => return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_unitWittLevel_constraint",
property_iri: "https://uor.foundation/reduction/unitWittLevel",
expected_range: "https://uor.foundation/schema/WittLevel",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
}),
};
let budget = match self.thermodynamic_budget {
Some(b) => b,
None => return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_thermodynamicBudget_constraint",
property_iri: "https://uor.foundation/reduction/thermodynamicBudget",
expected_range: "http://www.w3.org/2001/XMLSchema#decimal",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
}),
};
match self.target_domains {
Some(d) if !d.is_empty() => {}
_ => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_targetDomains_constraint",
property_iri: "https://uor.foundation/reduction/targetDomains",
expected_range: "https://uor.foundation/op/VerificationDomain",
min_count: 1,
max_count: 0,
kind: ViolationKind::Missing,
})
}
}
Ok(Validated::new(CompileUnit { level, budget }))
}
}
impl<'a> Default for CompileUnitBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct EffectDeclarationBuilder<'a> {
name: Option<&'a str>,
target_sites: Option<&'a [u32]>,
budget_delta: Option<i64>,
commutes: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EffectDeclaration {
pub shape_iri: &'static str,
}
impl<'a> EffectDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
name: None,
target_sites: None,
budget_delta: None,
commutes: None,
}
}
#[must_use]
pub const fn name(mut self, value: &'a str) -> Self {
self.name = Some(value);
self
}
#[must_use]
pub const fn target_sites(mut self, value: &'a [u32]) -> Self {
self.target_sites = Some(value);
self
}
#[must_use]
pub const fn budget_delta(mut self, value: i64) -> Self {
self.budget_delta = Some(value);
self
}
#[must_use]
pub const fn commutes(mut self, value: bool) -> Self {
self.commutes = Some(value);
self
}
pub fn validate(self) -> Result<Validated<EffectDeclaration>, ShapeViolation> {
if self.name.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/name",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.target_sites.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/target_sites",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.budget_delta.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/budget_delta",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.commutes.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/commutes",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(EffectDeclaration {
shape_iri: "https://uor.foundation/conformance/EffectShape",
}))
}
}
impl<'a> Default for EffectDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct GroundingDeclarationBuilder<'a> {
source_type: Option<&'a str>,
ring_mapping: Option<&'a str>,
invertibility: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GroundingDeclaration {
pub shape_iri: &'static str,
}
impl<'a> GroundingDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
source_type: None,
ring_mapping: None,
invertibility: None,
}
}
#[must_use]
pub const fn source_type(mut self, value: &'a str) -> Self {
self.source_type = Some(value);
self
}
#[must_use]
pub const fn ring_mapping(mut self, value: &'a str) -> Self {
self.ring_mapping = Some(value);
self
}
#[must_use]
pub const fn invertibility(mut self, value: bool) -> Self {
self.invertibility = Some(value);
self
}
pub fn validate(self) -> Result<Validated<GroundingDeclaration>, ShapeViolation> {
if self.source_type.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/source_type",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.ring_mapping.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/ring_mapping",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.invertibility.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/invertibility",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(GroundingDeclaration {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
}))
}
}
impl<'a> Default for GroundingDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct DispatchDeclarationBuilder<'a> {
predicate: Option<&'a [Term]>,
target_resolver: Option<&'a str>,
priority: Option<u32>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DispatchDeclaration {
pub shape_iri: &'static str,
}
impl<'a> DispatchDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
predicate: None,
target_resolver: None,
priority: None,
}
}
#[must_use]
pub const fn predicate(mut self, value: &'a [Term]) -> Self {
self.predicate = Some(value);
self
}
#[must_use]
pub const fn target_resolver(mut self, value: &'a str) -> Self {
self.target_resolver = Some(value);
self
}
#[must_use]
pub const fn priority(mut self, value: u32) -> Self {
self.priority = Some(value);
self
}
pub fn validate(self) -> Result<Validated<DispatchDeclaration>, ShapeViolation> {
if self.predicate.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/predicate",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.target_resolver.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/target_resolver",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.priority.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/priority",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(DispatchDeclaration {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
}))
}
}
impl<'a> Default for DispatchDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct LeaseDeclarationBuilder<'a> {
linear_site: Option<u32>,
scope: Option<&'a str>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LeaseDeclaration {
pub shape_iri: &'static str,
}
impl<'a> LeaseDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
linear_site: None,
scope: None,
}
}
#[must_use]
pub const fn linear_site(mut self, value: u32) -> Self {
self.linear_site = Some(value);
self
}
#[must_use]
pub const fn scope(mut self, value: &'a str) -> Self {
self.scope = Some(value);
self
}
pub fn validate(self) -> Result<Validated<LeaseDeclaration>, ShapeViolation> {
if self.linear_site.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
constraint_iri: "https://uor.foundation/conformance/LeaseShape",
property_iri: "https://uor.foundation/conformance/linear_site",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.scope.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
constraint_iri: "https://uor.foundation/conformance/LeaseShape",
property_iri: "https://uor.foundation/conformance/scope",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(LeaseDeclaration {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
}))
}
}
impl<'a> Default for LeaseDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct StreamDeclarationBuilder<'a> {
seed: Option<&'a [Term]>,
step: Option<&'a [Term]>,
productivity_witness: Option<&'a str>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StreamDeclaration {
pub shape_iri: &'static str,
}
impl<'a> StreamDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
seed: None,
step: None,
productivity_witness: None,
}
}
#[must_use]
pub const fn seed(mut self, value: &'a [Term]) -> Self {
self.seed = Some(value);
self
}
#[must_use]
pub const fn step(mut self, value: &'a [Term]) -> Self {
self.step = Some(value);
self
}
#[must_use]
pub const fn productivity_witness(mut self, value: &'a str) -> Self {
self.productivity_witness = Some(value);
self
}
pub fn validate(self) -> Result<Validated<StreamDeclaration>, ShapeViolation> {
if self.seed.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/seed",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.step.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/step",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.productivity_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/productivity_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(StreamDeclaration {
shape_iri: "https://uor.foundation/conformance/StreamShape",
}))
}
}
impl<'a> Default for StreamDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct PredicateDeclarationBuilder<'a> {
input_type: Option<&'a str>,
evaluator: Option<&'a [Term]>,
termination_witness: Option<&'a str>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PredicateDeclaration {
pub shape_iri: &'static str,
}
impl<'a> PredicateDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
input_type: None,
evaluator: None,
termination_witness: None,
}
}
#[must_use]
pub const fn input_type(mut self, value: &'a str) -> Self {
self.input_type = Some(value);
self
}
#[must_use]
pub const fn evaluator(mut self, value: &'a [Term]) -> Self {
self.evaluator = Some(value);
self
}
#[must_use]
pub const fn termination_witness(mut self, value: &'a str) -> Self {
self.termination_witness = Some(value);
self
}
pub fn validate(self) -> Result<Validated<PredicateDeclaration>, ShapeViolation> {
if self.input_type.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/input_type",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.evaluator.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/evaluator",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.termination_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/termination_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(PredicateDeclaration {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
}))
}
}
impl<'a> Default for PredicateDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct ParallelDeclarationBuilder<'a> {
site_partition: Option<&'a [u32]>,
disjointness_witness: Option<&'a str>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParallelDeclaration {
pub shape_iri: &'static str,
}
impl<'a> ParallelDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
site_partition: None,
disjointness_witness: None,
}
}
#[must_use]
pub const fn site_partition(mut self, value: &'a [u32]) -> Self {
self.site_partition = Some(value);
self
}
#[must_use]
pub const fn disjointness_witness(mut self, value: &'a str) -> Self {
self.disjointness_witness = Some(value);
self
}
pub fn validate(self) -> Result<Validated<ParallelDeclaration>, ShapeViolation> {
if self.site_partition.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
constraint_iri: "https://uor.foundation/conformance/ParallelShape",
property_iri: "https://uor.foundation/conformance/site_partition",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.disjointness_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
constraint_iri: "https://uor.foundation/conformance/ParallelShape",
property_iri: "https://uor.foundation/conformance/disjointness_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(ParallelDeclaration {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
}))
}
}
impl<'a> Default for ParallelDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct WittLevelDeclarationBuilder {
bit_width: Option<u32>,
cycle_size: Option<u128>,
predecessor: Option<WittLevel>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WittLevelDeclaration {
pub bit_width: u32,
pub predecessor: WittLevel,
}
impl WittLevelDeclarationBuilder {
#[must_use]
pub const fn new() -> Self {
Self {
bit_width: None,
cycle_size: None,
predecessor: None,
}
}
#[must_use]
pub const fn bit_width(mut self, w: u32) -> Self {
self.bit_width = Some(w);
self
}
#[must_use]
pub const fn cycle_size(mut self, s: u128) -> Self {
self.cycle_size = Some(s);
self
}
#[must_use]
pub const fn predecessor(mut self, level: WittLevel) -> Self {
self.predecessor = Some(level);
self
}
pub fn validate(self) -> Result<Validated<WittLevelDeclaration>, ShapeViolation> {
let bw = match self.bit_width {
Some(w) => w,
None => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/WittLevelShape",
constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
property_iri: "https://uor.foundation/conformance/declaredBitWidth",
expected_range: "http://www.w3.org/2001/XMLSchema#positiveInteger",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
})
}
};
let pred = match self.predecessor {
Some(p) => p,
None => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/WittLevelShape",
constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
property_iri: "https://uor.foundation/conformance/predecessorLevel",
expected_range: "https://uor.foundation/schema/WittLevel",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
})
}
};
Ok(Validated::new(WittLevelDeclaration {
bit_width: bw,
predecessor: pred,
}))
}
}
impl Default for WittLevelDeclarationBuilder {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BoundarySession {
crossing_count: u32,
is_idempotent: bool,
}
impl BoundarySession {
#[inline]
#[allow(dead_code)]
pub(crate) const fn new(is_idempotent: bool) -> Self {
Self {
crossing_count: 0,
is_idempotent,
}
}
#[inline]
#[must_use]
pub const fn crossing_count(&self) -> u32 {
self.crossing_count
}
#[inline]
#[must_use]
pub const fn is_idempotent(&self) -> bool {
self.is_idempotent
}
}
#[allow(dead_code)]
pub(crate) fn validate_and_mint_coord(
grounded: GroundedCoord,
shape: &Validated<GroundingDeclaration>,
session: &mut BoundarySession,
) -> Result<Datum, ShapeViolation> {
let _ = shape; session.crossing_count += 1;
let inner = match grounded.inner {
GroundedCoordInner::W8(b) => DatumInner::W8(b),
GroundedCoordInner::W16(b) => DatumInner::W16(b),
GroundedCoordInner::W24(b) => DatumInner::W24(b),
GroundedCoordInner::W32(b) => DatumInner::W32(b),
};
Ok(Datum { inner })
}
#[allow(dead_code)]
pub(crate) fn validate_and_mint_tuple<const N: usize>(
grounded: GroundedTuple<N>,
shape: &Validated<GroundingDeclaration>,
session: &mut BoundarySession,
) -> Result<Datum, ShapeViolation> {
if N == 0 {
return Err(ShapeViolation {
shape_iri: shape.inner().shape_iri,
constraint_iri: shape.inner().shape_iri,
property_iri: "https://uor.foundation/conformance/groundingSourceType",
expected_range: "https://uor.foundation/type/TypeDefinition",
min_count: 1,
max_count: 0,
kind: ViolationKind::CardinalityViolation,
});
}
validate_and_mint_coord(grounded.coords[0].clone(), shape, session)
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w8(op: PrimitiveOp, a: u8, b: u8) -> u8 {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::Xor => a ^ b,
PrimitiveOp::And => a & b,
PrimitiveOp::Or => a | b,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w8(op: PrimitiveOp, a: u8) -> u8 {
match op {
PrimitiveOp::Neg => 0u8.wrapping_sub(a),
PrimitiveOp::Bnot => !a,
PrimitiveOp::Succ => a.wrapping_add(1),
PrimitiveOp::Pred => a.wrapping_sub(1),
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w16(op: PrimitiveOp, a: u16, b: u16) -> u16 {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::Xor => a ^ b,
PrimitiveOp::And => a & b,
PrimitiveOp::Or => a | b,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w16(op: PrimitiveOp, a: u16) -> u16 {
match op {
PrimitiveOp::Neg => 0u16.wrapping_sub(a),
PrimitiveOp::Bnot => !a,
PrimitiveOp::Succ => a.wrapping_add(1),
PrimitiveOp::Pred => a.wrapping_sub(1),
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w24(op: PrimitiveOp, a: u32, b: u32) -> u32 {
const MASK: u32 = (18446744073709551615u64 >> (64 - 24)) as u32;
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w24(op: PrimitiveOp, a: u32) -> u32 {
const MASK: u32 = (18446744073709551615u64 >> (64 - 24)) as u32;
match op {
PrimitiveOp::Neg => (0u32.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w32(op: PrimitiveOp, a: u32, b: u32) -> u32 {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::Xor => a ^ b,
PrimitiveOp::And => a & b,
PrimitiveOp::Or => a | b,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w32(op: PrimitiveOp, a: u32) -> u32 {
match op {
PrimitiveOp::Neg => 0u32.wrapping_sub(a),
PrimitiveOp::Bnot => !a,
PrimitiveOp::Succ => a.wrapping_add(1),
PrimitiveOp::Pred => a.wrapping_sub(1),
_ => 0,
}
}
pub trait OntologyTarget: ontology_target_sealed::Sealed {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GroundingCertificate {
witt_bits: u16,
}
impl Default for GroundingCertificate {
#[inline]
fn default() -> Self {
Self { witt_bits: 32 }
}
}
impl GroundingCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_witt_bits(witt_bits: u16) -> Self {
Self { witt_bits }
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LiftChainCertificate {
witt_bits: u16,
}
impl Default for LiftChainCertificate {
#[inline]
fn default() -> Self {
Self { witt_bits: 32 }
}
}
impl LiftChainCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_witt_bits(witt_bits: u16) -> Self {
Self { witt_bits }
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct InhabitanceCertificate {
witt_bits: u16,
}
impl Default for InhabitanceCertificate {
#[inline]
fn default() -> Self {
Self { witt_bits: 32 }
}
}
impl InhabitanceCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_witt_bits(witt_bits: u16) -> Self {
Self { witt_bits }
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CompletenessCertificate {
witt_bits: u16,
}
impl Default for CompletenessCertificate {
#[inline]
fn default() -> Self {
Self { witt_bits: 32 }
}
}
impl CompletenessCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_witt_bits(witt_bits: u16) -> Self {
Self { witt_bits }
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GenericImpossibilityWitness {
_private: (),
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct InhabitanceImpossibilityWitness {
_private: (),
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ConstrainedTypeInput {
_private: (),
}
impl LiftChainCertificate {
#[inline]
#[must_use]
pub const fn target_level(&self) -> WittLevel {
WittLevel::new(self.witt_bits as u32)
}
}
impl InhabitanceCertificate {
#[inline]
#[must_use]
pub const fn witness(&self) -> Option<&'static [u8]> {
None
}
}
mod ontology_target_sealed {
pub trait Sealed {}
impl Sealed for super::GroundingCertificate {}
impl Sealed for super::LiftChainCertificate {}
impl Sealed for super::InhabitanceCertificate {}
impl Sealed for super::CompletenessCertificate {}
impl Sealed for super::GenericImpossibilityWitness {}
impl Sealed for super::InhabitanceImpossibilityWitness {}
impl Sealed for super::ConstrainedTypeInput {}
impl Sealed for super::CompileUnit {}
}
impl OntologyTarget for GroundingCertificate {}
impl OntologyTarget for LiftChainCertificate {}
impl OntologyTarget for InhabitanceCertificate {}
impl OntologyTarget for CompletenessCertificate {}
impl OntologyTarget for GenericImpossibilityWitness {}
impl OntologyTarget for InhabitanceImpossibilityWitness {}
impl OntologyTarget for ConstrainedTypeInput {}
impl OntologyTarget for CompileUnit {}
#[doc(hidden)]
pub mod __macro_internals {
pub trait GroundedShapeSealed {}
impl GroundedShapeSealed for super::ConstrainedTypeInput {}
}
pub trait GroundedShape: __macro_internals::GroundedShapeSealed {}
impl<T: __macro_internals::GroundedShapeSealed> GroundedShape for T {}
#[derive(Debug, Clone, Copy)]
pub struct BindingEntry {
pub address: u128,
pub bytes: &'static [u8],
}
#[derive(Debug, Clone, Copy)]
pub struct BindingsTable {
pub entries: &'static [BindingEntry],
}
impl BindingsTable {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(entries: &'static [BindingEntry]) -> Self {
Self { entries }
}
}
#[derive(Debug, Clone)]
pub struct Grounded<T: GroundedShape> {
validated: Validated<GroundingCertificate>,
bindings: BindingsTable,
witt_level_bits: u16,
unit_address: u128,
_phantom: PhantomData<T>,
}
impl<T: GroundedShape> Grounded<T> {
#[inline]
#[must_use]
pub fn get_binding(&self, address: u128) -> Option<&'static [u8]> {
self.bindings
.entries
.binary_search_by_key(&address, |e| e.address)
.ok()
.map(|i| self.bindings.entries[i].bytes)
}
#[inline]
pub fn iter_bindings(&self) -> impl Iterator<Item = &BindingEntry> + '_ {
self.bindings.entries.iter()
}
#[inline]
#[must_use]
pub const fn witt_level_bits(&self) -> u16 {
self.witt_level_bits
}
#[inline]
#[must_use]
pub const fn unit_address(&self) -> u128 {
self.unit_address
}
#[inline]
#[must_use]
pub const fn certificate(&self) -> &Validated<GroundingCertificate> {
&self.validated
}
#[inline]
#[allow(dead_code)]
pub(crate) const fn new_internal(
validated: Validated<GroundingCertificate>,
bindings: BindingsTable,
witt_level_bits: u16,
unit_address: u128,
) -> Self {
Self {
validated,
bindings,
witt_level_bits,
unit_address,
_phantom: PhantomData,
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum PipelineFailure {
DispatchMiss {
query_iri: &'static str,
table_iri: &'static str,
},
GroundingFailure {
reason_iri: &'static str,
},
ConvergenceStall {
stage_iri: &'static str,
angle_milliradians: i64,
},
ContradictionDetected {
at_step: usize,
trace_iri: &'static str,
},
CoherenceViolation {
site_position: usize,
constraint_iri: &'static str,
},
LiftObstructionFailure {
site_position: usize,
obstruction_class_iri: &'static str,
},
ShapeViolation {
report: ShapeViolation,
},
}
impl core::fmt::Display for PipelineFailure {
fn fmt(&self, ff: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::DispatchMiss {
query_iri,
table_iri,
} => write!(
ff,
"DispatchMiss(query_iri={:?}, table_iri={:?})",
query_iri, table_iri
),
Self::GroundingFailure { reason_iri } => {
write!(ff, "GroundingFailure(reason_iri={:?})", reason_iri)
}
Self::ConvergenceStall {
stage_iri,
angle_milliradians,
} => write!(
ff,
"ConvergenceStall(stage_iri={:?}, angle_milliradians={:?})",
stage_iri, angle_milliradians
),
Self::ContradictionDetected { at_step, trace_iri } => write!(
ff,
"ContradictionDetected(at_step={:?}, trace_iri={:?})",
at_step, trace_iri
),
Self::CoherenceViolation {
site_position,
constraint_iri,
} => write!(
ff,
"CoherenceViolation(site_position={:?}, constraint_iri={:?})",
site_position, constraint_iri
),
Self::LiftObstructionFailure {
site_position,
obstruction_class_iri,
} => write!(
ff,
"LiftObstructionFailure(site_position={:?}, obstruction_class_iri={:?})",
site_position, obstruction_class_iri
),
Self::ShapeViolation { report } => write!(ff, "ShapeViolation({:?})", report),
}
}
}
pub trait ImpossibilityWitnessKind: impossibility_witness_kind_sealed::Sealed {}
mod impossibility_witness_kind_sealed {
pub trait Sealed {}
impl Sealed for super::GenericImpossibilityWitness {}
impl Sealed for super::InhabitanceImpossibilityWitness {}
}
impl ImpossibilityWitnessKind for GenericImpossibilityWitness {}
impl ImpossibilityWitnessKind for InhabitanceImpossibilityWitness {}
pub trait Certify<I: ?Sized> {
type Certificate: OntologyTarget;
type Witness: ImpossibilityWitnessKind;
const DEFAULT_LEVEL: WittLevel = WittLevel::W32;
fn certify(&self, input: &I) -> Result<Validated<Self::Certificate>, Self::Witness> {
self.certify_at(input, Self::DEFAULT_LEVEL)
}
fn certify_at(
&self,
input: &I,
level: WittLevel,
) -> Result<Validated<Self::Certificate>, Self::Witness>;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct TowerCompletenessResolver;
impl TowerCompletenessResolver {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl<__T: crate::pipeline::ConstrainedTypeShape + ?Sized> Certify<__T>
for TowerCompletenessResolver
{
type Certificate = LiftChainCertificate;
type Witness = GenericImpossibilityWitness;
fn certify_at(
&self,
input: &__T,
level: WittLevel,
) -> Result<Validated<Self::Certificate>, Self::Witness> {
crate::pipeline::run_tower_completeness(input, level)
.map_err(|_| GenericImpossibilityWitness::default())
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct IncrementalCompletenessResolver;
impl IncrementalCompletenessResolver {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl<__T: crate::pipeline::ConstrainedTypeShape + ?Sized> Certify<__T>
for IncrementalCompletenessResolver
{
type Certificate = LiftChainCertificate;
type Witness = GenericImpossibilityWitness;
fn certify_at(
&self,
input: &__T,
level: WittLevel,
) -> Result<Validated<Self::Certificate>, Self::Witness> {
crate::pipeline::run_incremental_completeness(input, level)
.map_err(|_| GenericImpossibilityWitness::default())
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct GroundingAwareResolver;
impl GroundingAwareResolver {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl Certify<CompileUnit> for GroundingAwareResolver {
type Certificate = GroundingCertificate;
type Witness = GenericImpossibilityWitness;
fn certify_at(
&self,
input: &CompileUnit,
level: WittLevel,
) -> Result<Validated<Self::Certificate>, Self::Witness> {
crate::pipeline::run_grounding_aware(input, level)
.map_err(|_| GenericImpossibilityWitness::default())
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct InhabitanceResolver;
impl InhabitanceResolver {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl<__T: crate::pipeline::ConstrainedTypeShape + ?Sized> Certify<__T> for InhabitanceResolver {
type Certificate = InhabitanceCertificate;
type Witness = InhabitanceImpossibilityWitness;
fn certify_at(
&self,
input: &__T,
level: WittLevel,
) -> Result<Validated<Self::Certificate>, Self::Witness> {
crate::pipeline::run_inhabitance(input, level)
}
}
pub trait RingOp<L> {
type Operand;
fn apply(a: Self::Operand, b: Self::Operand) -> Self::Operand;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct Mul<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Add<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Sub<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Xor<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct And<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Or<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct W8;
#[derive(Debug, Default, Clone, Copy)]
pub struct W16;
#[derive(Debug, Default, Clone, Copy)]
pub struct W24;
#[derive(Debug, Default, Clone, Copy)]
pub struct W32;
impl RingOp<W8> for Mul<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W8> for Add<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W8> for Sub<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W8> for Xor<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W8> for And<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::And, a, b)
}
}
impl RingOp<W8> for Or<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W16> for Mul<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W16> for Add<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W16> for Sub<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W16> for Xor<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W16> for And<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::And, a, b)
}
}
impl RingOp<W16> for Or<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W24> for Mul<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W24> for Add<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W24> for Sub<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W24> for Xor<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W24> for And<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::And, a, b)
}
}
impl RingOp<W24> for Or<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W32> for Mul<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W32> for Add<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W32> for Sub<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W32> for Xor<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W32> for And<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::And, a, b)
}
}
impl RingOp<W32> for Or<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Or, a, b)
}
}
pub trait FragmentMarker: fragment_sealed::Sealed {}
mod fragment_sealed {
pub trait Sealed {}
impl Sealed for super::Is2SatShape {}
impl Sealed for super::IsHornShape {}
impl Sealed for super::IsResidualFragment {}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct Is2SatShape;
impl FragmentMarker for Is2SatShape {}
#[derive(Debug, Default, Clone, Copy)]
pub struct IsHornShape;
impl FragmentMarker for IsHornShape {}
#[derive(Debug, Default, Clone, Copy)]
pub struct IsResidualFragment;
impl FragmentMarker for IsResidualFragment {}
#[derive(Debug, Clone, Copy)]
pub struct DispatchRule {
pub predicate_iri: &'static str,
pub target_resolver_iri: &'static str,
pub priority: u32,
}
pub type DispatchTable = &'static [DispatchRule];
pub const INHABITANCE_DISPATCH_TABLE: DispatchTable = &[
DispatchRule {
predicate_iri: "https://uor.foundation/predicate/Is2SatShape",
target_resolver_iri: "https://uor.foundation/resolver/TwoSatDecider",
priority: 0,
},
DispatchRule {
predicate_iri: "https://uor.foundation/predicate/IsHornShape",
target_resolver_iri: "https://uor.foundation/resolver/HornSatDecider",
priority: 1,
},
DispatchRule {
predicate_iri: "https://uor.foundation/predicate/IsResidualFragment",
target_resolver_iri: "https://uor.foundation/resolver/ResidualVerdictResolver",
priority: 2,
},
];
impl<T: OntologyTarget> core::ops::Deref for Validated<T> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
&self.inner
}
}
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub struct MacroProvenance {
_marker: (),
}
impl MacroProvenance {
#[doc(hidden)]
#[inline]
#[must_use]
pub const fn __for_macro_crate() -> Self {
Self { _marker: () }
}
}
#[doc(hidden)]
#[inline]
pub fn __uor_macro_mint_validated<T: OntologyTarget>(
_prov: MacroProvenance,
inner: T,
) -> Validated<T> {
Validated { inner, _sealed: () }
}
#[doc(hidden)]
#[inline]
pub fn __uor_macro_mint_grounded<T: GroundedShape>(
_prov: MacroProvenance,
validated: Validated<GroundingCertificate>,
bindings: BindingsTable,
witt_level_bits: u16,
unit_address: u128,
) -> Grounded<T> {
Grounded::new_internal(validated, bindings, witt_level_bits, unit_address)
}
pub mod prelude {
pub use super::Add;
pub use super::And;
pub use super::BindingEntry;
pub use super::BindingsTable;
pub use super::Certify;
pub use super::CompileUnit;
pub use super::CompileUnitBuilder;
pub use super::CompletenessCertificate;
pub use super::ConstrainedTypeInput;
pub use super::Datum;
pub use super::FragmentMarker;
pub use super::GenericImpossibilityWitness;
pub use super::Grounded;
pub use super::GroundedShape;
pub use super::GroundingAwareResolver;
pub use super::GroundingCertificate;
pub use super::ImpossibilityWitnessKind;
pub use super::IncrementalCompletenessResolver;
pub use super::InhabitanceCertificate;
pub use super::InhabitanceImpossibilityWitness;
pub use super::InhabitanceResolver;
pub use super::LiftChainCertificate;
pub use super::Mul;
pub use super::OntologyTarget;
pub use super::Or;
pub use super::PipelineFailure;
pub use super::RingOp;
pub use super::ShapeViolation;
pub use super::Sub;
pub use super::Term;
pub use super::TermArena;
pub use super::TowerCompletenessResolver;
pub use super::Validated;
pub use super::Xor;
pub use super::W16;
pub use super::W8;
pub use crate::{Primitives, WittLevel};
pub use uor_foundation_macros::uor;
}