Issue #2523: While a text position is used its text stays as it was, and a cut at positions has no run-time check (ADR-text-positions-v1 D8, D9)

Open and answer this issue on GitHub.

ready, yaml · opened 2026-11-21 · updated 2026-11-29 · 0 comments

Part of #743 After #743

Decided 2026-11-29 (supervisor): ADR-text-positions-v1 D9 (2276d831), which consolidates ADR-374 (ADR-decision-records-v2 D4).

What it is

ADR-text-positions-v1 D8 says a cut at proven positions is not checked at run time. Today every before/after/between/split_at keeps Rust’s boundary check (run reports of 71a74e37 and 6bbfac8b), because nothing ruled out that the text changed while a position of it lived.

Found

Probes on develop 00ccf2cc, nikaia run:

fn main() throws {
    let mut t = "ab;cd"
    let m = t.find(";") ?? return
    t.push_str("ä")
    println(t.after(m.end))
}

error[NK1343]: Internal compiler error, rustc cannot borrow t as mutable because it is also borrowed as immutable. Expected NK2305 at the push_str.

fn main() throws {
    let mut t = "ab;cd"
    let m = t.find(";") ?? return
    t = "ä"
    println(t.after(m.end))
}

Run-time panic in crates/nikaia-std/src/text_pos.rs:58 (start byte index 3 is out of bounds for string of length 2), with Rust’s message. Expected NK1214 at the cut.

For comparison, the same change under a view is refused as Part I 6.6 says: let v = t.after(t.start()) then t.push_str("x") then println(v) gives NK2305 (t is changed here, but v may point into its data and is used later).

Decision

ADR-text-positions-v1 D9: while a position is used, its text stays as it was. A position carries its text’s sources as a view does (D5), so Part I 6.6’s rule for a view holds for it unchanged:

So every cut the compiler accepts is at positions of an unchanged text, and D8 drops the boundary check everywhere. Option (b), dropping the check only where the compiler sees no change, is rejected in D9: it keeps a check at every cut the compiler cannot see through.

To build

Done when

The first probe gives NK2305 and the second NK1214, a cut at proven positions lowers without is_char_boundary, each shown by its test, and the commit carries Fixes #2523.


Generated by Claude Code

Back to Open Issues