Skip to main content

macroonz_compiler/request/
types.rs

1//! The request home's declarations: the front door itself, who is asking, the crate rendered paths are rooted at, and the two facts a request stands on.
2//!
3//! Declarations only.
4//! Every road that reaches a private field lives in `type_guard.rs`, this file's own child, so a request is whatever one of those roads built.
5
6use crate::identity::{self, Identity, MACROONZ_STEM, OwnerFact, OwnerIdentity, Profile, Version};
7use crate::kind::{Kind, Question, Role};
8use crate::token::CapturedInput;
9
10#[path = "type_guard.rs"]
11mod guard;
12
13/// The profile a request runs under where it selects no other.
14///
15/// Everything this compiler renders is Rust written at a declaration, and that is what the name says.
16pub const RUST_DECLARATION_PROFILE: Profile =
17    Profile::declared(MACROONZ_STEM, "rust-declaration", Version::declared(1));
18
19/// This home's own declared fact: the seats one request selects are its complete output set.
20///
21/// The selection rule every plan built here cites, and the first entry of every decision trace it records.
22pub const SELECTION_FACT: OwnerFact = OwnerFact {
23    home: "request",
24    name: "a-requests-selected-seats-are-its-complete-output-set",
25};
26
27/// Who is asking, for whatever a door's expansions are stamped into.
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
29pub struct Producer {
30    /// The namespace the producer's generated names stand under.
31    pub namespace: &'static str,
32    /// The producer's own declared name.
33    pub name: &'static str,
34}
35
36/// The crate a path rendered through one door is rooted at.
37///
38/// A consumer may rename its dependencies, so the word a rendered path opens with is the consumer's to declare and no spelling of it is written down in this compiler.
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
40pub struct CrateBinding {
41    spelling: &'static str,
42}
43
44/// The one value that says who is asking.
45///
46/// The two declared names are spellings rather than identities so a door is a `const` a consumer writes down once; the identities they stand for are derived on read, under the declared-name grammar at the two positions this compiler assigns.
47#[derive(Debug, Clone, PartialEq, Eq, Hash)]
48pub struct Door {
49    prefix: &'static str,
50    grammar: &'static str,
51    entry: &'static str,
52    binding: CrateBinding,
53    producer: Producer,
54}
55
56/// One request: the material it stands over, what that material means, who is asking, and the seats the caller states.
57///
58/// A builder, and the value the whole road is walked from.
59/// Stating a builder fact again replaces its earlier statement; a publication address replaces only the earlier address for that same seat.
60/// The material is held rather than committed to at the door, because a commitment beside the bytes it was taken from is one fact in two seats; the commitment is derived once, where the plan that carries it is built.
61///
62/// # Nonclaims
63///
64/// It answers nothing about the material it holds.
65/// Reading a declaration grammar out of captured tokens is the consumer's, and a request is what it hands over afterwards.
66#[must_use = "a request is a road nobody walked until it is rendered"]
67pub struct Request<'door, K: Kind> {
68    capture: CapturedInput,
69    content: K::Content,
70    door: &'door Door,
71    dependencies: Vec<Identity<identity::CapturedDeclaration>>,
72    profile: Profile,
73    assumptions: Vec<OwnerFact>,
74    addresses: Vec<(K::Role, OwnerIdentity)>,
75    answers: Vec<<K::Question as Question>::Answer>,
76    selection: Selection<K::Role>,
77}
78
79/// Whether one request selects its kind's complete role roster or one explicitly stated nonempty subset.
80pub(super) enum Selection<R: Role> {
81    /// Every role the kind declares, preserving the established default road.
82    All,
83    /// One explicitly selected role followed by the rest of the selected subset.
84    Declared { first: R, rest: Vec<R> },
85}
86
87/// The already stated request facts planning reads together.
88pub(super) struct Statements<'request, R: Role> {
89    pub(super) assumptions: &'request [OwnerFact],
90    pub(super) addresses: &'request [(R, OwnerIdentity)],
91    pub(super) selection: &'request Selection<R>,
92}