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::{
7 CaptureBound, CaptureBuilder, LiteralReadCause, SpanHandle, SpanResolutionRefusal, TokenPath,
8};
9use proc_macro::Span;
10
11#[path = "type_guard.rs"]
12mod guard;
13
14/// The compiler spans one capture issued handles for.
15///
16/// 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.
17/// 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.
18#[derive(Debug)]
19pub struct Spans {
20 builder: CaptureBuilder<Span>,
21}
22
23/// How reading one declared input into a captured surface refuses.
24///
25/// Two rows, because the two are facts about different things — and the difference is where each is reported.
26#[must_use = "a capture refusal names what stopped the read and what it is a fact about"]
27#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28pub enum CaptureError {
29 /// The read ran past one of the declared magnitudes.
30 Unbounded {
31 /// Which magnitude.
32 bound: CaptureBound,
33 },
34 /// One literal's spelling could not be read into the value it names, with declaration identity and producer placement retained separately.
35 Unread {
36 /// Why it could not be read.
37 cause: LiteralReadCause,
38 /// Which token of the declared input could not be read.
39 path: TokenPath,
40 /// The producer-local handle already bound to the token's compiler span.
41 at: SpanHandle,
42 },
43}
44
45/// Why one admitted generated literal could not cross the compiler-token host.
46///
47/// This is a host contradiction rather than a declaration diagnostic: the ordinary compiler admitted the literal before the proc API was asked to materialize it.
48#[must_use = "an emission refusal names the admitted literal the compiler host could not materialize"]
49#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50pub enum EmissionError {
51 /// The proc-macro literal API rejected one already admitted numeric spelling.
52 NumberRejected {
53 /// The exact admitted numeric spelling.
54 spelling: String,
55 },
56 /// The proc-macro C-string literal API rejected already admitted C-string material.
57 NulTerminatedTextRejected,
58 /// A generated tree's private source roster no longer matches its recursive token denominator.
59 SourceSpanRosterContradiction,
60 /// One preserved source handle does not resolve in the capture table supplied for emission.
61 SourceSpanUnresolved(SpanResolutionRefusal),
62}
63
64/// What one value answers to have its declaration-site cargo emitted.
65///
66/// 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.
67pub trait Emittable {
68 /// The declaration-site cargos this value delivers.
69 fn cargos(&self) -> impl Iterator<Item = &PartitionCargo>;
70}