Skip to main content

macroonz_compiler/expansion/
types.rs

1//! The expansion home's declarations: the fact a binding refusal cites, how binding refuses, the sealed account one request produces, and the complete disposition witness a door seats beside it.
2//!
3//! Declarations only, with every road that reaches a private field in `type_guard.rs`, this file's own child.
4
5use crate::closure::Closure;
6use crate::explanation::View;
7use crate::identity::{ClosedExpansionId, ClosureId, OwnerFact, PlanId, Provenance};
8use crate::kind::{DispositionSet, Kind, KindSet};
9use crate::plan::Plan;
10
11#[path = "type_guard.rs"]
12mod guard;
13
14/// The fact this home declares, and the one a binding refusal cites as its repair.
15pub const BINDING_FACT: OwnerFact = OwnerFact {
16    home: "expansion",
17    name: "nothing-is-handed-out-that-did-not-bind",
18};
19
20/// How binding one expansion refuses.
21///
22/// Three values produced separately can disagree about their parentage in exactly three places, and each of the three is a different repair.
23/// Every arm names both identities it holds and elects neither.
24#[must_use = "a binding refusal names the two identities an expansion was asked to bind as one"]
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
26pub enum BindError {
27    /// The closure proves a rendering against a plan other than the one handed in beside it.
28    ClosureProvedAgainstAnotherPlan {
29        /// The plan handed to the binding.
30        planned: PlanId,
31        /// The plan the closure was actually proved against.
32        proved: PlanId,
33    },
34    /// The explanation was answered over a plan other than the one handed in beside it.
35    ///
36    /// Reachable under one kind, which is why the type parameter cannot catch it: two plans of one kind admit the same questions, so an explanation written over the other one covers its roster exactly.
37    ExplanationAnsweredOverAnotherPlan {
38        /// The plan handed to the binding.
39        planned: PlanId,
40        /// The plan the explanation was actually answered over.
41        answered: PlanId,
42    },
43    /// The explanation was answered over a proof other than the one handed in beside it.
44    ///
45    /// Reachable on its own, because one plan may be proved by two renderings and an explanation over the other proof states a digest of bytes this expansion never emitted.
46    ExplanationAnsweredOverAnotherClosure {
47        /// The proof handed to the binding.
48        proved: ClosureId,
49        /// The proof the explanation was actually answered over.
50        answered: ClosureId,
51    },
52}
53
54/// Everything one request produced, bound under one identity, with tokens reachable from here and from nowhere else.
55///
56/// One cannot be held without a plan, a closure proved over that plan, and an explanation answered over the two, all having been produced and having agreed.
57/// [`Expansion::plan`] and [`Expansion::closure`] are the same values the deliveries are read from, so what it says it did and what it did cannot drift.
58#[must_use = "an expansion is the whole account one request produced, and the only road to tokens"]
59#[derive(Debug, Clone, PartialEq, Eq)]
60pub struct Expansion<K: Kind> {
61    identity: ClosedExpansionId,
62    provenance: Provenance,
63    plan: Plan<K>,
64    closure: Closure<K::Role>,
65    explanation: View<K>,
66}
67
68/// One door's complete account: the expansion it produced, and what happened to every kind of the set it answers for.
69///
70/// The expansion carries what was produced and is silent about every kind that produced nothing; the sealed witness beside it carries one disposition per declared kind.
71/// Which row says generated about this expansion remains the door's decision, but an incomplete or overfull record cannot become the witness stored here.
72#[must_use = "an accounted expansion is what one door produced and what happened to every kind it did not"]
73#[derive(Debug, Clone, PartialEq, Eq)]
74pub struct Accounted<K: Kind, Set: KindSet> {
75    expansion: Expansion<K>,
76    dispositions: DispositionSet<Set>,
77}