Phase 1: frame storage, second-class borrows, arrays (P1-3..P1-10)
- air: types local/ref/mut/array/slice/slice_mut, from-returns, multi-result binding, 18 new instructions; feature gating reports E0006 feature_not_declared; borrow-typed block parameters gated by borrow_joins; printer and round-trip tests for all new forms - verifier: second-class and zeroable type rules (E1001); local.alloc only in entry (E5002); frame size accounting (E5101); stages init (E1010), borrow (E2101, E2102, E2105-E2108) and bounds facts (E2103); value types shared between stages - interp: frame cells, places, slices, deep copies between storage and SSA values, T0008 bounds traps - features arrays and ownership supported; implemented_phase = 1 - conformance: 5 accept, 18 reject, 11 run tests for Phase 1, including the file-copy core exit program; 6000 mutants without a crash
This commit is contained in:
1 parent
be9dd0e1ed
commit
1ae6b485d8
50 files changed
+2376
-37
No files matched your search
@@ -0,0 +1,18 @@
|
||||
; local.alloc in a loop body would make the frame dynamic.
|
||||
; expect: reject E5002
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.alloc_outside_entry
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f(%c: bool) -> void
|
||||
effects []
|
||||
entry:
|
||||
br @loop()
|
||||
loop:
|
||||
%x = local.alloc u8
|
||||
cbr %c, @loop(), @out()
|
||||
out:
|
||||
ret
|
||||
@@ -0,0 +1,15 @@
|
||||
; Borrow-typed block parameters need the reserved feature borrow_joins.
|
||||
; expect: reject E0006
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.borrow_block_parameter
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f(%p: ref<u8>) -> void
|
||||
effects []
|
||||
entry:
|
||||
br @next(%p)
|
||||
next(%q: ref<u8>):
|
||||
ret
|
||||
@@ -0,0 +1,15 @@
|
||||
; Borrows are second-class and cannot be struct fields.
|
||||
; expect: reject E1001
|
||||
; phase: 1
|
||||
; spec: docs/spec/07-air.md
|
||||
module test.borrow_in_struct
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
type @Holder = struct { r: ref<u8> }
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
ret
|
||||
@@ -0,0 +1,17 @@
|
||||
; A borrow is still live at ret.
|
||||
; expect: reject E2105
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.borrow_not_ended
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
local.zero %x
|
||||
|
||||
%r = borrow.ref %x
|
||||
ret
|
||||
@@ -0,0 +1,15 @@
|
||||
; A function returns a borrow without naming its source.
|
||||
; expect: reject E2102
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.borrow_return_without_from
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f(%s: slice<u8>) -> ref<u8>
|
||||
effects []
|
||||
entry:
|
||||
%z = const.usize 0
|
||||
%e = borrow.index %s, %z
|
||||
ret %e
|
||||
@@ -0,0 +1,19 @@
|
||||
; Borrows cannot be copied.
|
||||
; expect: reject E1001
|
||||
; phase: 1
|
||||
; spec: docs/spec/07-air.md
|
||||
module test.copy_borrow
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
local.zero %x
|
||||
|
||||
%r = borrow.ref %x
|
||||
%r2 = copy %r
|
||||
borrow.end %r
|
||||
ret
|
||||
@@ -0,0 +1,22 @@
|
||||
; slice.copy with source and destination in the same range is rejected: it is not a memmove.
|
||||
; expect: reject E2101
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.copy_overlapping
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc array<u8, 8>
|
||||
local.zero %x
|
||||
%m = borrow.mut %x
|
||||
%s = slice.make %m
|
||||
%src = borrow.ref %s
|
||||
slice.copy %s, %src
|
||||
borrow.end %src
|
||||
borrow.end %s
|
||||
borrow.end %m
|
||||
ret
|
||||
@@ -0,0 +1,14 @@
|
||||
; A callee ends a borrow it was lent.
|
||||
; expect: reject E2107
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.end_lent_parameter
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f(%p: ref<u8>) -> void
|
||||
effects []
|
||||
entry:
|
||||
borrow.end %p
|
||||
ret
|
||||
@@ -0,0 +1,20 @@
|
||||
; The parent borrow is ended while its child is live.
|
||||
; expect: reject E2102
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.end_parent_first
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
local.zero %x
|
||||
|
||||
%m = borrow.mut %x
|
||||
%r = borrow.ref %m
|
||||
borrow.end %m
|
||||
borrow.end %r
|
||||
ret
|
||||
@@ -0,0 +1,14 @@
|
||||
; local.alloc belongs to ownership, which the module does not declare.
|
||||
; expect: reject E0006
|
||||
; phase: 1
|
||||
; spec: docs/spec/07-air.md
|
||||
module test.feature_not_declared
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
ret
|
||||
@@ -0,0 +1,17 @@
|
||||
; A borrow of frame storage is returned.
|
||||
; expect: reject E2108
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.frame_escape
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f(%p: ref<u8>) -> ref<u8> from %p
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
local.zero %x
|
||||
|
||||
%r = borrow.ref %x
|
||||
ret %r
|
||||
@@ -0,0 +1,14 @@
|
||||
; 2 MiB of frame storage exceeds max_local_frame.
|
||||
; expect: reject E5101
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.frame_too_large
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc array<u8, 2097152>
|
||||
ret
|
||||
@@ -0,0 +1,24 @@
|
||||
; The borrow is ended on one edge into the join but not on the other.
|
||||
; expect: reject E2105
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.join_mismatch
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f(%c: bool) -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
local.zero %x
|
||||
|
||||
%r = borrow.ref %x
|
||||
cbr %c, @a(), @b()
|
||||
a:
|
||||
borrow.end %r
|
||||
br @join()
|
||||
b:
|
||||
br @join()
|
||||
join:
|
||||
trap
|
||||
@@ -0,0 +1,22 @@
|
||||
; i <= len(s) does not prove i < len(s).
|
||||
; expect: reject E2103
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.le_is_not_a_fact
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f(%s: slice<u8>, %i: usize) -> u8
|
||||
effects []
|
||||
entry:
|
||||
%n = slice.len %s
|
||||
%c = le.usize %i, %n
|
||||
cbr %c, @in(), @out()
|
||||
in:
|
||||
%e = borrow.index.proven %s, %i
|
||||
%v = load %e
|
||||
borrow.end %e
|
||||
ret %v
|
||||
out:
|
||||
trap
|
||||
@@ -0,0 +1,20 @@
|
||||
; A shared borrow is created while an exclusive one is live.
|
||||
; expect: reject E2101
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.mut_and_shared
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
local.zero %x
|
||||
|
||||
%m = borrow.mut %x
|
||||
%r = borrow.ref %x
|
||||
borrow.end %r
|
||||
borrow.end %m
|
||||
ret
|
||||
@@ -0,0 +1,15 @@
|
||||
; The local is read before it is initialized.
|
||||
; expect: reject E1010
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.read_uninitialized
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f() -> u8
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
%v = local.load %x
|
||||
ret %v
|
||||
@@ -0,0 +1,19 @@
|
||||
; A borrow is used after borrow.end.
|
||||
; expect: reject E2106
|
||||
; phase: 1
|
||||
; spec: docs/spec/08-verifier.md
|
||||
module test.use_after_end
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
fn @f() -> u8
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
local.zero %x
|
||||
|
||||
%r = borrow.ref %x
|
||||
borrow.end %r
|
||||
%v = load %r
|
||||
ret %v
|
||||
@@ -0,0 +1,17 @@
|
||||
; Enums are not zeroable.
|
||||
; expect: reject E1001
|
||||
; phase: 1
|
||||
; spec: docs/spec/07a-air-instructions.md
|
||||
module test.zero_enum
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
type @E = enum { A, B }
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
%x = local.alloc @E
|
||||
local.zero %x
|
||||
ret
|
||||
Reference in new issue
Block a user