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
//! Shape-level proof strength used by execution validation.
use core::fmt;
/// How much of an operation's legality the compiler settled.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum ProofLevel {
/// Rank and every semantic dimension constraint came from type-level data.
Static,
/// Structure is typed, but named or dynamic dimensions were checked once.
Mixed,
/// Rank and all semantic dimensions were checked at runtime.
Dynamic,
}
impl ProofLevel {
/// The proof carried by shape `S`.
#[must_use]
pub const fn of<S: crate::shapes::Shape>() -> Self {
S::PROOF
}
/// The weaker of two proofs.
#[must_use]
pub const fn meet(self, other: Self) -> Self {
if (self as u8) >= (other as u8) {
self
} else {
other
}
}
/// The level for a known-rank shape, given whether every axis is static.
#[doc(hidden)]
#[must_use]
pub const fn of_ranked(all_axes_static: bool) -> Self {
if all_axes_static {
Self::Static
} else {
Self::Mixed
}
}
/// Whether the geometry is entirely a compile-time constant.
#[must_use]
pub const fn is_static(self) -> bool {
matches!(self, Self::Static)
}
/// Whether the rank was known before runtime.
#[must_use]
pub const fn has_static_rank(self) -> bool {
!matches!(self, Self::Dynamic)
}
}
impl fmt::Display for ProofLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Static => "static",
Self::Mixed => "mixed",
Self::Dynamic => "dynamic",
})
}
}