Skip to main content

pointlock_ir/
source_map.rs

1//! Source mapping: IR path → YAML span, plus macro origin traces (02 §7).
2//!
3//! Pure diagnostics — excluded from `irHash` (02 §12.2): moving a comment or
4//! a macro call site must not invalidate resume history.
5
6use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8
9use crate::primitives::{Identifier, JsonPointer};
10
11/// One source-map entry.
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
13#[serde(rename_all = "camelCase", deny_unknown_fields)]
14pub struct SourceMapEntry {
15    /// RFC 6901 JSON Pointer into this FlowIR document.
16    pub ir_path: JsonPointer,
17    /// The YAML source file.
18    #[schemars(length(min = 1))]
19    pub file: String,
20    /// The source span.
21    pub span: SourceSpan,
22    /// Macro expansion chain, innermost first. Present iff the IR node was
23    /// produced by macro expansion — the only structural residue macros
24    /// leave in the IR (02 §7).
25    #[serde(skip_serializing_if = "Option::is_none")]
26    #[schemars(length(min = 1))]
27    pub origin: Option<Vec<MacroOriginFrame>>,
28}
29
30/// A 1-based line/column span in a source file.
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
32#[serde(rename_all = "camelCase", deny_unknown_fields)]
33pub struct SourceSpan {
34    /// Start line (1-based).
35    #[schemars(range(min = 1))]
36    pub start_line: u32,
37    /// Start column (1-based).
38    #[schemars(range(min = 1))]
39    pub start_col: u32,
40    /// End line (1-based).
41    #[schemars(range(min = 1))]
42    pub end_line: u32,
43    /// End column (1-based).
44    #[schemars(range(min = 1))]
45    pub end_col: u32,
46}
47
48/// One frame of a macro expansion chain.
49#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
50#[serde(rename_all = "camelCase", deny_unknown_fields)]
51pub struct MacroOriginFrame {
52    /// The macro's name.
53    pub r#macro: Identifier,
54    /// The file containing the expansion site.
55    #[schemars(length(min = 1))]
56    pub file: String,
57    /// The span of the expansion site.
58    pub span: SourceSpan,
59}