Phase 6A: .aji layers 3-4 (addressable values, lexical borrows, slices)

Owner rules: addressability is decided by lowering (a variable that is
borrowed, indexed or written through a place gets frame storage in the
entry block; otherwise SSA; by name, deterministic); borrows are bound
only by 'ref r = place;' / 'mut r = place;' and live to the end of the
block (borrow.end at every normal exit, including break/continue/return);
no shadowing of an active borrow in the same scope; ref/mut as call
arguments are temporaries ended after the call; *r only for scalar and
struct referents, slices via s[i], s[a..b], s.len; writes *r = v,
r.f = v, s[i] = v with the value evaluated first; split_at as the only
multi-result binding; slice.copy(mut dst, ref src) as the only copy;
[e; N] evaluates e once; byte strings as [u8; N] in frame storage with
a fixed escape set; borrow.index.proven only for the verifier's own
fact form (if i < s.len, same SSA values), otherwise checked.

Diagnostics on lowered AIR are deduplicated per code and source
location. aji lower --stats counts code only (no comment lines).

Tests: 10 run (architecture goldens: value-only has no local.alloc,
borrowed has local.alloc, proven indexing), 6 rejects incl.
verifier-caught E2101 (aliasing; parent used after split_at).
Expansion on these programs: 4-9x bytes, 2.2-6.6x lines.
This commit is contained in:
dev committed 2026-10-05 11:51:04 +03:00
1 parent 0fdd04179b
commit eca30f817a
28 files changed
+1157 -73

No files matched your search

@@ -0,0 +1,14 @@
// The frontend does not check aliasing: the verifier reports E2101 at the second borrow.
// expect: reject E2101
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.conflict
fn main() -> u64
effects []
{
var buf: [u64; 2] = zero;
mut a = buf;
ref b = buf;
return 0;
}
@@ -0,0 +1,13 @@
// One spelling: borrows are bound with `ref r = …;` / `mut r = …;`.
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.letborrow
fn main() -> u64
effects []
{
var x: u64 = 1;
let r = mut x;
return 0;
}
@@ -0,0 +1,17 @@
// `*` is for scalar and struct referents; slices use s[i].
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.derefslice
fn first(s: slice<u64>) -> u64
effects []
{
return *s;
}
fn main() -> u64
effects []
{
return 0;
}
@@ -0,0 +1,11 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.indexscalar
fn main() -> u64
effects []
{
var x: u64 = 1;
return x[0];
}
@@ -0,0 +1,15 @@
// An active borrow cannot be shadowed by the same name in the same scope.
// expect: reject E7006
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.shadow
fn main() -> u64
effects []
{
var x: u64 = 1;
var y: u64 = 2;
ref r = x;
ref r = y;
return *r;
}
@@ -0,0 +1,16 @@
// After split_at the parent slice cannot be used while the halves live: E2101 from the verifier.
// expect: reject E2101
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.splitparent
fn main() -> u64
effects []
{
var buf: [u64; 4] = zero;
mut s = buf;
let (l, r) = s.split_at(2);
s[0] = 1;
l[0] = 2;
return 0;
}