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:
1 parent
0fdd04179b
commit
eca30f817a
28 files changed
+1157
-73
No files matched your search
@@ -0,0 +1,48 @@
|
||||
module demo.proven
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, effects, ownership]
|
||||
|
||||
fn @get(%s_1: slice<u64>, %i_2: usize) -> u64
|
||||
effects []
|
||||
entry:
|
||||
%len_3 = slice.len %s_1
|
||||
%cmp_4 = lt.usize %i_2, %len_3
|
||||
cbr %cmp_4, @then_5(), @else_6()
|
||||
then_5:
|
||||
%e_7 = borrow.index.proven %s_1, %i_2
|
||||
%v_8 = load %e_7
|
||||
borrow.end %e_7
|
||||
ret %v_8
|
||||
else_6:
|
||||
br @endif_9()
|
||||
endif_9:
|
||||
%c_10 = const.u64 0
|
||||
ret %c_10
|
||||
|
||||
fn @main() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%d_1 = local.alloc array<u64, 2>
|
||||
local.zero %d_1
|
||||
%c_2 = const.u64 9
|
||||
%d_3 = borrow.mut %d_1
|
||||
%c_4 = const.usize 1
|
||||
%e_5 = borrow.index %d_3, %c_4
|
||||
store %e_5, %c_2
|
||||
borrow.end %e_5
|
||||
borrow.end %d_3
|
||||
%d_6 = borrow.ref %d_1
|
||||
%s_7 = slice.make %d_6
|
||||
%c_8 = const.usize 1
|
||||
%get_9 = call @get(%s_7, %c_8)
|
||||
borrow.end %s_7
|
||||
borrow.end %d_6
|
||||
%d_10 = borrow.ref %d_1
|
||||
%s_11 = slice.make %d_10
|
||||
%c_12 = const.usize 5
|
||||
%get_13 = call @get(%s_11, %c_12)
|
||||
borrow.end %s_11
|
||||
borrow.end %d_10
|
||||
%t_14 = add.checked.u64 %get_9, %get_13
|
||||
ret %t_14
|
||||
Reference in new issue
Block a user