macroonz_compiler/origin/types.rs
1use crate::bounded::{Empty, NonEmpty, Overflow};
2use crate::identity::{self, Identity, OwnerFact};
3
4#[path = "type_guard.rs"]
5mod guard;
6
7/// Edges one trail may draw.
8///
9/// A trail is the end-to-end walk from producing material toward a generated unit, one edge per act that stands between them, and a walk longer than this has stopped being provenance a reader can follow.
10pub const ORIGIN_EDGE_LIMIT: usize = 64;
11
12/// Entries one decision trace may record.
13pub const TRACE_ENTRY_LIMIT: usize = 128;
14
15/// What one edge of the origin graph stands for.
16///
17/// The roster is the vocabulary: an edge that means something else is a law change rather than a new string.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19pub enum OriginRelation {
20 /// A declaration a person authored.
21 AuthoredDeclaration,
22 /// An authored pattern instantiated with typed arguments.
23 PatternInstantiation,
24 /// Meaning derived from meaning already established.
25 SemanticDerivation,
26 /// A link an author stated explicitly.
27 ExplicitLink,
28 /// A step that changed form and not meaning.
29 Normalization,
30 /// A projection profile selected.
31 ProfileSelection,
32 /// A projection kind selected under that profile.
33 ProjectionSelection,
34 /// Typed material rendered into a target's syntax.
35 Rendering,
36 /// A test descriptor derived from an obligation.
37 TestDerivation,
38 /// A benchmark descriptor derived from a work formula.
39 BenchmarkDerivation,
40 /// A diagnostic derived from an observed disagreement.
41 DiagnosticDerivation,
42}
43
44/// One directed edge of the origin graph: which node, under which relation, produced which node.
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
46pub struct OriginEdge {
47 /// The node the relation starts at.
48 pub from: Identity<identity::OriginNode>,
49 /// The relation this edge stands for.
50 pub relation: OriginRelation,
51 /// The node the relation produces.
52 pub to: Identity<identity::OriginNode>,
53}
54
55/// The derivation walk from producing material toward one generated unit.
56///
57/// Edges are held in walk order, and there is always at least one of them.
58#[derive(Debug, Clone, PartialEq, Eq, Hash)]
59pub struct OriginTrail {
60 edges: NonEmpty<OriginEdge, ORIGIN_EDGE_LIMIT>,
61}
62
63/// How drawing a trail refuses.
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
65pub enum TrailError {
66 /// The edges offered are not one walk.
67 Discontinuous {
68 /// The position of the first edge that does not start where the edge before it ended, counted from the walk's first edge.
69 at: u32,
70 },
71 /// No edge was offered.
72 Empty(Empty),
73 /// More edges were offered than the trail admits.
74 Overflow(Overflow),
75}
76
77/// What a plan decided about one subject, and on whose fact.
78///
79/// A selection and an omission each cite the fact that decided them, because both are decisions somebody's declaration caused; a check that did not run cites nothing and stays distinct from one that ran and omitted.
80#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
81pub enum TraceDecision {
82 /// Selected, because this fact required it.
83 SelectedBecause(OwnerFact),
84 /// Omitted, because this fact excluded it.
85 OmittedBecause(OwnerFact),
86 /// The check did not run. Never a pass, never a fail.
87 NotRun,
88}
89
90/// One recorded decision about one subject.
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
92pub struct TraceEntry {
93 /// The subject decided about.
94 pub subject: Identity<identity::Traced>,
95 /// What was decided, and on whose fact.
96 pub decision: TraceDecision,
97}
98
99/// One plan's decisions, in the order it made them.
100///
101/// # Ordering
102///
103/// Selection order is the trace's own meaning, so an identity may be derived from it: two plans that decided the same things in a different order decided differently.
104#[derive(Debug, Clone, PartialEq, Eq, Hash)]
105pub struct DecisionTrace {
106 entries: NonEmpty<TraceEntry, TRACE_ENTRY_LIMIT>,
107}
108
109/// One thing a plan explicitly does not claim, and the fact that leaves it unclaimed.
110#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
111pub struct Nonclaim {
112 /// The subject the plan makes no claim about.
113 pub unclaimed: Identity<identity::Nonclaim>,
114 /// The fact that leaves it unclaimed.
115 pub because: OwnerFact,
116}