mant_ir/document/diagnostic.rs
1//! Source-neutral findings and their explicit coverage effects.
2use super::SourceSpan;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Recoverable parser or IR validation finding attached to the document.
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
8#[serde(rename_all = "camelCase")]
9pub struct Diagnostic {
10 /// Severity of the finding.
11 pub level: DiagnosticLevel,
12 /// Explicit effect on semantic extraction, independent of severity or code.
13 /// Required on the wire: missing producer coverage must never mean complete.
14 pub impact: DiagnosticImpact,
15 /// Stable machine-readable code, when the producer defines one.
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub code: Option<String>,
18 /// Concise human-readable explanation.
19 pub message: String,
20 /// Original source location associated with the finding.
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub source: Option<SourceSpan>,
23}
24
25/// Producer-declared effect of a finding on semantic extraction completeness.
26/// This is not a measure of rendering fidelity or proof of exhaustive recall.
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
28#[serde(rename_all = "kebab-case")]
29pub enum DiagnosticImpact {
30 /// This finding does not invalidate semantic extraction coverage.
31 None,
32 /// Semantic declarations, facts or coverage were rejected or incomplete.
33 SemanticCoverage,
34}
35
36/// Whether all producers and shared validators permit a complete projection.
37/// Consumers must not infer this effect from diagnostic severity, text or codes.
38#[must_use]
39pub fn semantics_complete(diagnostics: &[Diagnostic]) -> bool {
40 diagnostics
41 .iter()
42 .all(|diagnostic| diagnostic.impact != DiagnosticImpact::SemanticCoverage)
43}
44
45/// Severity reported by the parser without turning useful output into failure.
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
47#[serde(rename_all = "kebab-case")]
48pub enum DiagnosticLevel {
49 /// Non-semantic source style issue.
50 Style,
51 /// Recoverable source defect or portability concern.
52 Warning,
53 /// Invalid source that left partial output available.
54 Error,
55 /// Valid construct that the active parser cannot represent fully.
56 Unsupported,
57}