verifier: account finite anonymous type sizes exactly

This commit is contained in:
dev committed 2026-10-09 13:26:17 +03:00
1 parent 03614c9bef
commit 111a3861f9
16 files changed
+226 -8

No files matched your search

@@ -0,0 +1,13 @@
; Anonymous nested arrays account exactly one MiB.
; expect: accept
; phase: 1
; spec: docs/spec/08-verifier.md
module test.nested_size
air 0
lang 0.1
features [arrays, ownership]
fn @f(%x: array<array<u8, 1024>, 1024>) -> void
effects []
entry:
ret
@@ -0,0 +1,13 @@
; Budget arithmetic on an invalid cycle stays bounded and reports excess value size first.
; expect: reject E5101
; phase: 1
; spec: docs/spec/08-verifier.md §7.1; docs/spec/07-air.md §8.6
module test.nested_size_cycle
air 0
lang 0.1
features [arrays, ownership]
type @A = struct { n: u8, x: array<@A, 4294967296> }
fn @f() -> void
effects []
entry:
ret
@@ -0,0 +1,15 @@
; Each local fits; one extra byte exceeds the frame limit.
; expect: reject E5101
; phase: 1
; spec: docs/spec/08-verifier.md
module test.nested_size
air 0
lang 0.1
features [arrays, ownership]
fn @f() -> void
effects []
entry:
%a = local.alloc array<array<u8, 1024>, 1024>
%b = local.alloc u8
ret
@@ -0,0 +1,14 @@
; An unrelated nominal declaration cannot hide a one-GiB anonymous value.
; expect: reject E5101
; phase: 1
; spec: docs/spec/08-verifier.md
module test.nested_size
air 0
lang 0.1
features [arrays, ownership]
type @Unused = struct { n: u8 }
fn @f(%x: array<array<array<u8, 1024>, 1024>, 1024>) -> void
effects []
entry:
ret
@@ -0,0 +1,13 @@
; Mutex accounting includes its array content even without nominal declarations.
; expect: reject E5101
; phase: 1
; spec: docs/spec/08-verifier.md
module test.nested_size
air 0
lang 0.1
features [arrays, cancellation, capabilities, effects, ownership, resources, sync, tasks]
fn @f(%x: mutex<array<u8, 1048576>>) -> mutex<array<u8, 1048576>>
effects []
entry:
ret %x
@@ -0,0 +1,13 @@
; Anonymous nested-array size overflows checked u64 arithmetic.
; expect: reject E5101
; phase: 1
; spec: docs/spec/08-verifier.md
module test.nested_size
air 0
lang 0.1
features [arrays, ownership]
fn @f(%x: array<array<array<u64, 4294967296>, 4294967296>, 1>) -> void
effects []
entry:
ret
@@ -0,0 +1,13 @@
; Finite anonymous nesting must not truncate an oversized value.
; expect: reject E5101
; phase: 1
; spec: docs/spec/08-verifier.md
module test.nested_size
air 0
lang 0.1
features [arrays, ownership]
fn @f(%x: array<array<u8, 1024>, 1025>) -> void
effects []
entry:
ret
@@ -0,0 +1,29 @@
; The nested array requires exactly 32 accounted bytes.
; expect: run
; result: 0
; grant: heap=mem.alloc:31
; fuel: 100
; phase: 2
; spec: docs/spec/03-memory-model.md §19; docs/spec/08-verifier.md §7.1
module test.nested_heap_size
air 0
lang 0.1
features [arrays, capabilities, effects, heap, ownership, resources]
type @Record = struct { data: array<array<u64, 2>, 2> }
fn @main(%heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
entry:
%v = const.u64 7
%inner = array.splat array<u64, 2> %v
%outer = array.splat array<array<u64, 2>, 2> %inner
%record = struct.make @Record(%outer)
own.new %record, %heap, ok -> @ok, err -> @err
ok(%owned: own<@Record>):
own.free %owned
%yes = const.u64 1
ret %yes
err(%e: alloc_error):
%no = const.u64 0
ret %no
@@ -0,0 +1,29 @@
; The nested array requires exactly 32 accounted bytes.
; expect: run
; result: 1
; grant: heap=mem.alloc:32
; fuel: 100
; phase: 2
; spec: docs/spec/03-memory-model.md §19; docs/spec/08-verifier.md §7.1
module test.nested_heap_size
air 0
lang 0.1
features [arrays, capabilities, effects, heap, ownership, resources]
type @Record = struct { data: array<array<u64, 2>, 2> }
fn @main(%heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
entry:
%v = const.u64 7
%inner = array.splat array<u64, 2> %v
%outer = array.splat array<array<u64, 2>, 2> %inner
%record = struct.make @Record(%outer)
own.new %record, %heap, ok -> @ok, err -> @err
ok(%owned: own<@Record>):
own.free %owned
%yes = const.u64 1
ret %yes
err(%e: alloc_error):
%no = const.u64 0
ret %no
@@ -0,0 +1,7 @@
// Anonymous nested arrays retain exact value-size accounting.
// expect: accept
// phase: 6
// spec: docs/spec/08-verifier.md §7.1; docs/spec/15-source-language.md §10
module nested_size
fn unused(data: [[u8; 1024]; 1024]) -> void effects [] {}
fn main() -> void effects [] {}
@@ -0,0 +1,7 @@
// Anonymous nested arrays retain exact value-size accounting.
// expect: reject E5101
// phase: 6
// spec: docs/spec/08-verifier.md §7.1; docs/spec/15-source-language.md §10
module nested_size
fn unused(data: [[u8; 1024]; 1025]) -> void effects [] {}
fn main() -> void effects [] {}
+1 -1
View File
@@ -33,7 +33,7 @@ with tempfile.TemporaryDirectory(prefix='aji-nominal-queries-') as directory:
records = [json.loads(line) for line in diagnostics.splitlines()]
assert all(d['file'] == str(source) for d in records), records
if source.stem == 'cycle':
assert (records[0]['code'], records[0]['type'], records[0]['line']) == ('E1003', 'N0', 5)
assert (records[0]['code'], records[0]['type'], records[0]['line']) == ('E1003', 'N0', 6)
elif source.stem == 'constraint_depth':
assert records[0]['reason'] == 'implementation_limit'
elif source.stem == 'diamond_21_u64':