Skip to main content

macroonz_compiler/host/
types.rs

1//! The host's declarations: the span custody a capture builds, how a capture refuses, and what a value answers to be emitted.
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::PartitionCargo;
6use crate::token::{CaptureBound, CaptureBuilder, LiteralReadCause, SpanHandle, TokenPath};
7use proc_macro::Span;
8
9#[path = "type_guard.rs"]
10mod guard;
11
12/// The compiler spans one capture issued handles for.
13///
14/// A handle means "the token at this index of the table its producer built", and this is that table when the producer is a proc macro.
15/// It is what lets a refusal land on the offending token rather than on the declaration's first one, because it is what holds the compiler's own spans.
16#[derive(Debug)]
17pub struct Spans {
18    builder: CaptureBuilder<Span>,
19}
20
21/// How reading one declared input into a captured surface refuses.
22///
23/// Two rows, because the two are facts about different things — and the difference is where each is reported.
24#[must_use = "a capture refusal names what stopped the read and what it is a fact about"]
25#[derive(Debug, Clone, PartialEq, Eq, Hash)]
26pub enum CaptureError {
27    /// The read ran past one of the declared magnitudes.
28    Unbounded {
29        /// Which magnitude.
30        bound: CaptureBound,
31    },
32    /// One literal's spelling could not be read into the value it names, with declaration identity and producer placement retained separately.
33    Unread {
34        /// Why it could not be read.
35        cause: LiteralReadCause,
36        /// Which token of the declared input could not be read.
37        path: TokenPath,
38        /// The producer-local handle already bound to the token's compiler span.
39        at: SpanHandle,
40    },
41}
42
43/// What one value answers to have its declaration-site cargo emitted.
44///
45/// A cargo per delivery it carries, in the order a compiler receives them: a value delivering two says so rather than handing over one stream that claims to be both.
46pub trait Emittable {
47    /// The declaration-site cargos this value delivers.
48    fn cargos(&self) -> impl Iterator<Item = &PartitionCargo>;
49}