1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::{ConflictKey, PromptSegmentId};
/// Stable prompt-compiler diagnostic classification.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum PromptDiagnosticCode {
/// An exact duplicate segment was emitted only once.
ExactDuplicate,
/// A lower-precedence conflict was shadowed by a replaceable winner.
ConflictShadowed,
/// A lower-precedence claim could not override a protected winner.
ProtectedConflict,
/// A segment was omitted due to explicit budget behavior.
OmittedForBudget,
/// A segment was deterministically truncated.
TruncatedForBudget,
}
/// Bounded deterministic compiler diagnostic without prompt content.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PromptDiagnostic {
code: PromptDiagnosticCode,
segment_id: PromptSegmentId,
winner_id: Option<PromptSegmentId>,
conflict_key: Option<ConflictKey>,
}
impl PromptDiagnostic {
pub(crate) const fn new(
code: PromptDiagnosticCode,
segment_id: PromptSegmentId,
winner_id: Option<PromptSegmentId>,
conflict_key: Option<ConflictKey>,
) -> Self {
Self {
code,
segment_id,
winner_id,
conflict_key,
}
}
/// Returns stable diagnostic code.
#[must_use]
pub const fn code(&self) -> PromptDiagnosticCode {
self.code
}
/// Returns affected segment.
#[must_use]
pub const fn segment_id(&self) -> &PromptSegmentId {
&self.segment_id
}
/// Returns winning segment for conflict/duplicate diagnostics.
#[must_use]
pub const fn winner_id(&self) -> Option<&PromptSegmentId> {
self.winner_id.as_ref()
}
/// Returns affected conflict key when applicable.
#[must_use]
pub const fn conflict_key(&self) -> Option<&ConflictKey> {
self.conflict_key.as_ref()
}
}