Skip to content

Commit ac5746c

Browse files
committed
feat(ir): carry source lines as a signed SourceLine across the verdict path
The representation the three RED commits were for. `own_ir::span::SourceLine` is a `#[serde(transparent)]` newtype over `i64` and nothing else: no `valid()`, no clamp, no normalisation, no `TryFrom`. `SourceLine(-1)` is legal. It is a carrier, and every rule about which lines MEAN something stays exactly where it already lives. WHY signed 64: #326 made that range part of the OwnIR contract, and the reference carries whatever the door accepted onto the verdict surface verbatim — measured at i64::MIN, -1, 0, u32::MAX + 1 and i64::MAX, on the validated `services[].line` path. A narrower carrier refuses verdicts the door admits. The producer boundary stays visible rather than being flattened: lexer token.line: u32 --From (lossless)--> AST line: SourceLine OwnIR / lowered: i64 --exact--> AST line: SourceLine The parser keeps its honest domain — a `.own` file has no line -2^63 — and `ParseError.line` stays `u32` for the same reason. What changes is that the shared AST stops asserting that every producer of a coordinate must be a lexer. `From`, never `TryFrom`: every `u32` is a `SourceLine` and the conversion cannot fail. Widened along the whole semantic/verdict path: AST, own-cfg (`ir`, `builder`, `buffers`, `Diag`), own-analysis (`di::Service`, effect, ownership, lifetime), and own-diagnostics (`Diagnostic`, `Evidence`, `DiagKey`, `EvidenceIdentity`, `DiagIdentity`, `LocatedDiagnostic::line`, `sarif::Step`, `sarif::Region`). Two crates take an already-allowed DAG edge to own-ir for the first time (own-syntax, own-diagnostics); the allowlist is unchanged. NOT changed, deliberately: * Both `>= 1` predicates. The DI004/DI005 site sentinel and the SARIF region gate are preserved verbatim — they were always written `>= 1` and that keeps meaning the same over a signed value, so a negative site now correctly takes the registration fallback and a negative line still emits no region. They were only ever *equivalent* to `!= 0` because u32 cannot go below zero. * `column`. Still `Option<NonZeroU32>`: unlike a line it really does carry a 1-based contract, and dragging it along because both are "coordinates" is the axis conflation cp1 spent three censuses removing. * RID/SymId. Those are `u32` and stay `u32`. One of them — `leak_check`'s `exclude` — was widened by the first mechanical pass and reverted: it is compared against a RID, not a line, and only ever LOOKED like a coordinate because both were u32. That is precisely the substitution this change exists to stop, caught inside the change itself. One legitimate narrowing remains and is now commented as such: `render_pretty` converts to `usize` to index the source text, where a line with no corresponding text has nothing to render and the chain already degrades to "". That is a renderer fallback, not a verdict rule. Also fixed a silent clamp found on the way: `fact_parity`'s `u32_of` mapped anything past u32::MAX to 0 while reading frozen facts — harmless while no fixture carried such a value, and a silent zero the moment one did. Replaced by a `line_of` that reads the full signed range. Evidence: every frozen parity surface still passes unchanged — cfg_parity, the diagnostic ledger, sarif_replay, di_eff_fact_parity, the lowered replay and the summaries goldens — so the widening is byte-compatible on all existing data. Workspace: 0 test failures, clippy 0, cargo doc 0, Python suite green. NOT yet proven, and not claimed: the four acceptance groups this change was specified with — carrier preservation across the band on the Rust side, sentinel preservation, projection preservation, and the identity re-proof for DiagKey/EvidenceIdentity/DiagIdentity — plus their mutation controls. Existing fixtures only exercise small positive lines, so they cannot distinguish this from a build that still narrows. That is the next commit, and until it lands this is a compiling representation rather than a demonstrated one. Refs #250, #259. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CJF7MBi1ijU5m9cJVWgQsM
1 parent 48e639d commit ac5746c

28 files changed

Lines changed: 328 additions & 196 deletions

‎rust/Cargo.lock‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/crates/own-analysis/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ version = "0.1.0"
1414
# (ownership next) add own-cfg / own-diagnostics. The DAG edge test
1515
# (own-diagnostics/tests/dag.rs) already allows that (reviewed) set.
1616
[dependencies]
17+
own-ir = { path = "../own-ir" }
1718
own-cfg = { path = "../own-cfg" }
1819
own-diagnostics = { path = "../own-diagnostics" }
1920

‎rust/crates/own-analysis/src/di.rs‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//! `(line, code)` is the parity contract (DI findings anchor at the registration
1818
//! line here; the bridge does final call-site anchoring/evidence at step 6).
1919
20+
use own_ir::span::SourceLine;
21+
2022
use std::collections::{BTreeMap, BTreeSet};
2123

2224
use own_diagnostics::{title, Diagnostic};
@@ -50,7 +52,7 @@ impl Lifetime {
5052
/// SARIF are a later step, out of #214.
5153
/// A `(type, file, line)` call/store site (a `root_resolve` or `scope_cache`
5254
/// site), the DI004/DI005 primary anchor.
53-
pub type SiteTriple = (String, String, u32);
55+
pub type SiteTriple = (String, String, SourceLine);
5456

5557
#[derive(Debug, Clone)]
5658
pub struct Service {
@@ -61,7 +63,7 @@ pub struct Service {
6163
/// The **registration** site — the DI001/002/003 primary `(path, line)` and
6264
/// the DI004/DI005 fallback when the call/store site is unknown.
6365
pub file: String,
64-
pub line: u32,
66+
pub line: SourceLine,
6567
/// Services injected via `WeakReference<T>` (DI002).
6668
pub weak_deps: Vec<String>,
6769
/// Types hand-resolved from an injected root `IServiceProvider` (DI004).
@@ -77,7 +79,7 @@ pub struct Service {
7779
impl Service {
7880
/// A minimal service with a name + lifetime + registration `(file, line)`.
7981
#[must_use]
80-
pub fn new(name: &str, lifetime: Lifetime, file: &str, line: u32) -> Self {
82+
pub fn new(name: &str, lifetime: Lifetime, file: &str, line: SourceLine) -> Self {
8183
Self {
8284
name: name.to_owned(),
8385
lifetime: Some(lifetime),
@@ -105,7 +107,7 @@ pub struct DiFinding {
105107
pub subject: String,
106108
pub path: Vec<String>,
107109
pub file: String,
108-
pub line: u32,
110+
pub line: SourceLine,
109111
}
110112

111113
fn by_name(services: &[Service]) -> BTreeMap<&str, &Service> {
@@ -130,15 +132,15 @@ fn primary_from_site(
130132
sites: &[SiteTriple],
131133
entry: &str,
132134
reg_file: &str,
133-
reg_line: u32,
134-
) -> (String, u32) {
135+
reg_line: SourceLine,
136+
) -> (String, SourceLine) {
135137
// Python builds `{t: (f, ln) for (t, f, ln) in sites}` — a duplicate entry
136138
// type is **last-wins** — then `.get(entry)` and uses it only when its line
137139
// is >= 1 (registration fallback otherwise). Take the LAST matching site
138140
// (iterate reversed, match on type), then apply the same `>= 1` guard, so a
139141
// trailing line-0 site falls back exactly as Python does.
140142
match sites.iter().rev().find(|(ty, _, _)| ty == entry) {
141-
Some((_, file, line)) if *line >= 1 => (file.clone(), *line),
143+
Some((_, file, line)) if *line >= SourceLine(1) => (file.clone(), *line),
142144
_ => (reg_file.to_owned(), reg_line),
143145
}
144146
}
@@ -401,8 +403,8 @@ pub fn all_di_findings(services: &[Service]) -> Vec<DiFinding> {
401403
/// The #214 comparison surface. `path` is the finding's primary file
402404
/// (registration / resolve site / cache site), part of the verdict identity.
403405
#[must_use]
404-
pub fn di_verdicts(services: &[Service]) -> Vec<(String, u32, &'static str)> {
405-
let mut out: Vec<(String, u32, &'static str)> = all_di_findings(services)
406+
pub fn di_verdicts(services: &[Service]) -> Vec<(String, SourceLine, &'static str)> {
407+
let mut out: Vec<(String, SourceLine, &'static str)> = all_di_findings(services)
406408
.into_iter()
407409
.map(|f| (f.file, f.line, f.code))
408410
.collect();
@@ -443,9 +445,10 @@ mod tests {
443445
find_explicit_root_resolutions, find_scope_cached_captives, find_weak_captive_dependencies,
444446
Lifetime, Service,
445447
};
448+
use own_ir::span::SourceLine;
446449

447450
fn svc(name: &str, lt: Lifetime, deps: &[&str]) -> Service {
448-
let mut s = Service::new(name, lt, "reg.cs", 1);
451+
let mut s = Service::new(name, lt, "reg.cs", SourceLine(1));
449452
s.deps = deps.iter().map(|d| (*d).to_owned()).collect();
450453
s
451454
}
@@ -492,7 +495,7 @@ mod tests {
492495

493496
#[test]
494497
fn di002_weak_scoped_capture() {
495-
let mut app = Service::new("App", Lifetime::Singleton, "reg.cs", 1);
498+
let mut app = Service::new("App", Lifetime::Singleton, "reg.cs", SourceLine(1));
496499
app.weak_deps = vec!["Db".to_owned()];
497500
let services = vec![app, svc("Db", Lifetime::Scoped, &[])];
498501
let f = find_weak_captive_dependencies(&services);
@@ -512,7 +515,7 @@ mod tests {
512515

513516
#[test]
514517
fn di004_root_resolved_transient_disposable() {
515-
let mut app = Service::new("App", Lifetime::Singleton, "reg.cs", 1);
518+
let mut app = Service::new("App", Lifetime::Singleton, "reg.cs", SourceLine(1));
516519
app.root_resolves = vec!["Conn".to_owned()];
517520
let mut disp = svc("Conn", Lifetime::Transient, &[]);
518521
disp.disposable = true;
@@ -524,7 +527,7 @@ mod tests {
524527

525528
#[test]
526529
fn di005_scope_cached_scoped_service() {
527-
let mut app = Service::new("App", Lifetime::Singleton, "reg.cs", 1);
530+
let mut app = Service::new("App", Lifetime::Singleton, "reg.cs", SourceLine(1));
528531
app.scope_cached = vec!["Db".to_owned()];
529532
let services = vec![app, svc("Db", Lifetime::Scoped, &[])];
530533
let f = find_scope_cached_captives(&services);

‎rust/crates/own-analysis/src/effect.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
//! parity lands with the bridge. `#[allow(clippy::panic)]`-free; `(line, code)`
1414
//! is the parity contract (EFF001 anchors at the effect's call line).
1515
16+
use own_ir::span::SourceLine;
17+
1618
use std::collections::{BTreeMap, BTreeSet};
1719

1820
use own_diagnostics::{title, Diagnostic};
@@ -42,7 +44,7 @@ pub struct Binding {
4244
pub name: String,
4345
pub init: String,
4446
pub refs: Vec<String>,
45-
pub line: u32,
47+
pub line: SourceLine,
4648
}
4749

4850
/// One `useEffect`, mirroring `effects.Effect`.
@@ -57,7 +59,7 @@ pub struct Effect {
5759
pub io: bool,
5860
pub bindings: Vec<Binding>,
5961
pub file: String,
60-
pub line: u32,
62+
pub line: SourceLine,
6163
}
6264

6365
/// An EFF001 finding: the effect whose IO re-fires and the unstable dependency.
@@ -70,7 +72,7 @@ pub struct EffectStorm {
7072
pub dep: String,
7173
pub origin: String,
7274
pub file: String,
73-
pub line: u32,
75+
pub line: SourceLine,
7476
}
7577

7678
fn kind_stability(init: &str) -> Option<Stability> {
@@ -223,7 +225,7 @@ pub fn find_effect_storms(effects: &[Effect]) -> Vec<EffectStorm> {
223225
/// `path` is the effect's file (a fact-set can span files), so it is part of the
224226
/// verdict identity, not presentation.
225227
#[must_use]
226-
pub fn effect_verdicts(effects: &[Effect]) -> Vec<(String, u32, &'static str)> {
228+
pub fn effect_verdicts(effects: &[Effect]) -> Vec<(String, SourceLine, &'static str)> {
227229
find_effect_storms(effects)
228230
.into_iter()
229231
.map(|s| (s.file, s.line, "EFF001"))
@@ -253,13 +255,14 @@ pub fn effect_diagnostics(effects: &[Effect]) -> Vec<Diagnostic> {
253255
)]
254256
mod tests {
255257
use super::{find_effect_storms, Binding, Effect};
258+
use own_ir::span::SourceLine;
256259

257260
fn binding(name: &str, init: &str, refs: &[&str]) -> Binding {
258261
Binding {
259262
name: name.to_owned(),
260263
init: init.to_owned(),
261264
refs: refs.iter().map(|s| (*s).to_owned()).collect(),
262-
line: 1,
265+
line: SourceLine(1),
263266
}
264267
}
265268

@@ -270,7 +273,7 @@ mod tests {
270273
io,
271274
bindings,
272275
file: "C.tsx".to_owned(),
273-
line: 10,
276+
line: SourceLine(10),
274277
}
275278
}
276279

@@ -280,7 +283,7 @@ mod tests {
280283
let storms = find_effect_storms(&[e]);
281284
assert_eq!(storms.len(), 1);
282285
assert_eq!(storms[0].dep, "opts");
283-
assert_eq!(storms[0].line, 10);
286+
assert_eq!(storms[0].line, SourceLine(10));
284287
}
285288

286289
#[test]

‎rust/crates/own-analysis/src/lifetime.rs‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
//! Parity contract (#214): `(line, code)`. The AST is read through `own_cfg::ast`
1111
//! (the CFG seam), so this crate keeps no production `own-syntax` edge.
1212
13+
use own_ir::span::SourceLine;
14+
1315
use std::collections::{BTreeMap, BTreeSet};
1416

1517
use own_cfg::ast::{FnDecl, LifetimeDecl, Module, Stmt, Subscribe};
1618
use own_diagnostics::{title, Diagnostic};
1719

1820
/// Emit a `(code, line)` diagnostic (message is the title; text parity is a
1921
/// later step). `code` is a compile-time constant, so `new` cannot fail.
20-
fn push(diags: &mut Vec<Diagnostic>, code: &'static str, line: u32) {
22+
fn push(diags: &mut Vec<Diagnostic>, code: &'static str, line: SourceLine) {
2123
let msg = title(code).unwrap_or(code);
2224
match Diagnostic::new(code, msg, line) {
2325
Ok(d) => diags.push(d),
@@ -161,10 +163,11 @@ fn check_fn(
161163
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
162164
mod tests {
163165
use super::check_lifetimes;
166+
use own_ir::span::SourceLine;
164167

165-
fn codes(src: &str) -> Vec<(u32, String)> {
168+
fn codes(src: &str) -> Vec<(SourceLine, String)> {
166169
let module = own_syntax::parse(src).expect("parses");
167-
let mut v: Vec<(u32, String)> = check_lifetimes(&module)
170+
let mut v: Vec<(SourceLine, String)> = check_lifetimes(&module)
168171
.into_iter()
169172
.map(|d| (d.line, d.code))
170173
.collect();
@@ -183,7 +186,7 @@ mod tests {
183186
fn VM(bus: EventBus lifetime App) lifetime ViewModel {\n\
184187
subscribe self to bus;\n\
185188
}\n";
186-
assert_eq!(codes(src), vec![(6, "OWN014".to_owned())]);
189+
assert_eq!(codes(src), vec![(SourceLine(6), "OWN014".to_owned())]);
187190
}
188191

189192
#[test]
@@ -204,7 +207,10 @@ mod tests {
204207
let src = "module M\nlifetime A < B;\nlifetime B < A;\n";
205208
assert_eq!(
206209
codes(src),
207-
vec![(2, "OWN036".to_owned()), (3, "OWN036".to_owned())]
210+
vec![
211+
(SourceLine(2), "OWN036".to_owned()),
212+
(SourceLine(3), "OWN036".to_owned())
213+
]
208214
);
209215
}
210216

@@ -217,7 +223,10 @@ mod tests {
217223
lifetime Short < Ghost;\n";
218224
assert_eq!(
219225
codes(src),
220-
vec![(3, "OWN031".to_owned()), (4, "OWN030".to_owned())]
226+
vec![
227+
(SourceLine(3), "OWN031".to_owned()),
228+
(SourceLine(4), "OWN030".to_owned())
229+
]
221230
);
222231
}
223232

@@ -230,6 +239,6 @@ mod tests {
230239
fn VM(bus: EventBus lifetime App) lifetime ViewModel {\n\
231240
if (x) { subscribe self to bus; }\n\
232241
}\n";
233-
assert_eq!(codes(src), vec![(5, "OWN014".to_owned())]);
242+
assert_eq!(codes(src), vec![(SourceLine(5), "OWN014".to_owned())]);
234243
}
235244
}

0 commit comments

Comments
 (0)