use crate::bounded::{Bounded, Capping};
use crate::identity::{
Contract, HumanProjection, Identity, OwnerFact, RelatedBody, RelatedIssue, ServiceEntry,
};
use crate::token::{SourceCoordinate, SpanHandle, SpanResolutionRefusal, SpanTable};
#[path = "type_guard.rs"]
mod guard;
pub(crate) use guard::intrinsic_diagnostic;
pub const REPAIR_LIMIT: usize = 8;
pub const RELATED_ISSUE_LIMIT: usize = 64;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Family(&'static str);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DiagnosticName(&'static str);
#[must_use = "a diagnostic-name refusal states why no kebab-case name was declared"]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DiagnosticNameRefusal {
Empty,
NotKebabCase,
}
pub const PLANNING_FAMILY: Family = Family::declared("macroonz/planning");
pub const CLOSURE_FAMILY: Family = Family::declared("macroonz/closure");
pub const EXPLANATION_FAMILY: Family = Family::declared("macroonz/explanation");
pub const RENDERING_FAMILY: Family = Family::declared("macroonz/rendering");
pub const BINDING_FAMILY: Family = Family::declared("macroonz/binding");
pub const ASSEMBLY_FAMILY: Family = Family::declared("macroonz/assembly");
pub const SHELL_FAMILY: Family = Family::declared("macroonz/shell");
pub const DECLARATION_FAMILY: Family = Family::declared("macroonz/descriptor-declaration");
pub const SUPPORT_DECLARATION_FAMILY: Family = Family::declared("macroonz/support-declaration");
pub const FIRST_HELPER_FAMILY: Family = Family::declared("macroonz/trial-helper");
pub const SECOND_HELPER_FAMILY: Family = Family::declared("macroonz/mutation-helper");
pub const BENCH_HELPER_FAMILY: Family = Family::declared("macroonz/bench-helper");
pub const SHADOW_HELPER_FAMILY: Family = Family::declared("macroonz/shadow-helper");
pub const NETWORK_HELPER_FAMILY: Family = Family::declared("macroonz/network-helper");
pub const CONCURRENCY_HELPER_FAMILY: Family = Family::declared("macroonz/concurrency-helper");
pub const CAPTURE_FAMILY: Family = Family::declared("macroonz/capture");
pub const CODEC_DECLARATION_FAMILY: Family = Family::declared("macroonz/codec-declaration");
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Phase {
Capture,
Planning,
Rendering,
Closure,
Explanation,
Binding,
Assembly,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RefusalClass {
DeclarationNotRead,
PlanNotStated,
RenderingNotProduced,
RenderingNotClosed,
ExplanationNotCovered,
MagnitudeNotHeld,
ExpansionNotBound,
CarrierNotAssembled,
CarrierNotDeclared,
Declared {
name: DiagnosticName,
described: &'static str,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Observed {
SeatAbsent,
ContractDisagreement,
IdentityDisagreement,
ProfileDisagreement,
BoundExceeded,
OriginAbsent,
Declared {
name: DiagnosticName,
described: &'static str,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RenderedMagnitude {
RenderedBytes,
RenderedUnits,
GeneratedTokens,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LineBody {
SingleCause,
Body {
further: usize,
capping: Capping,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Line<'issue> {
pub class: RefusalClass,
pub first: &'issue str,
pub body: LineBody,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LineSite {
WholeDeclaration,
At(SiteCoordinate),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SiteCoordinate {
Resolved(SourceCoordinate),
NotReached(SpanResolutionRefusal),
}
#[must_use = "a site names the token it points at, the byte it was born at, or the whole declaration"]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Site {
AtToken {
token: SpanHandle,
coordinate: SiteCoordinate,
},
BeforeCapture {
coordinate: SourceCoordinate,
},
WholeDeclaration,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RelatedIdentity {
Body(Identity<RelatedBody>),
Issue(Identity<RelatedIssue>),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RelatedSet {
carried: Bounded<RelatedIdentity, RELATED_ISSUE_LIMIT>,
capping: Capping,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Repair {
pub declared_by: OwnerFact,
pub description: HumanProjection,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Route {
entry: Identity<ServiceEntry>,
}
#[derive(Debug, Clone, Copy)]
pub enum Placement<'table> {
WholeDeclaration,
AtToken {
token: SpanHandle,
spans: &'table SpanTable,
},
}
#[must_use = "a diagnostic carries the observation, its site, and the owner-declared repair"]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Diagnostic {
phase: Phase,
site: Site,
observed: Observed,
carried: Box<DiagnosticSeats>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct DiagnosticSeats {
summary: String,
expected: Identity<Contract>,
related: RelatedSet,
repairs: Bounded<Repair, REPAIR_LIMIT>,
route: Route,
}
pub(super) struct DiagnosticProjection {
pub(super) phase: Phase,
pub(super) site: Site,
pub(super) observed: Observed,
pub(super) summary: String,
pub(super) expected: Identity<Contract>,
pub(super) related: RelatedSet,
pub(super) repairs: Bounded<Repair, REPAIR_LIMIT>,
pub(super) route: Route,
}
pub trait Refused {
const PHASE: Phase;
const FAMILY: Family;
fn class(&self) -> RefusalClass;
fn first(&self) -> String;
fn observed(&self) -> Observed;
fn body(&self) -> LineBody;
fn related(&self) -> Vec<Vec<u8>>;
fn repairs(&self) -> Bounded<Repair, REPAIR_LIMIT>;
}
pub(crate) trait IntrinsicRefused: Refused {
fn site(&self) -> Site;
}