verifier: preserve resource obligations across CFG handoff

This commit is contained in:
dev committed 2026-10-08 17:17:08 +03:00
1 parent 0e98638bc6
commit 09fbf8a5bc
34 files changed
+1267 -67

No files matched your search

@@ -0,0 +1,41 @@
; The cancelled handle of task.join.cancel passed through an ordinary block argument keeps its loans.
; expect: reject E4302
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §34, §37
module test.cfg_provenance_cancel_arg
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%x = local.alloc u8
local.zero %x
%r = borrow.ref %x
%sc = task.scope.begin
%t = task.spawn %sc, @rd(%r)
task.join.cancel %t, ok -> @joined, cancelled -> @cancelled
joined(%v: u8):
task.scope.end %sc
borrow.end %r
ret %v
cancelled(%t1: task<u8>):
br @handle(%t1)
handle(%t2: task<u8>):
borrow.end %r
%v2 = task.join %t2
task.scope.end %sc
ret %v2
fn @rd(%p: ref<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,27 @@
; A guard passed through a block argument still depends on the mutex borrow it was locked through; ending that borrow while the guard is live is rejected.
; expect: reject E2102
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §40
module test.cfg_provenance_guard_parent
air 0
lang 0.1
features [cancellation, effects, ownership, sync, tasks]
fn @main() -> u64
effects [task.wait]
entry:
%z = const.u64 0
%m = mutex.make %z
%mr = borrow.ref %m
mutex.lock %mr, ok -> @locked, cancelled -> @out
locked(%g: guard<u64>):
br @next(%g)
next(%g2: guard<u64>):
borrow.end %mr
mutex.unlock %g2
%v = mutex.take %m
ret %v
out:
borrow.end %mr
%w = mutex.take %m
ret %w
@@ -0,0 +1,37 @@
; Parent store through the lent exclusive borrow races after a handle handoff.
; expect: reject E4101
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §34
module test.cfg_provenance_loan_access
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%x = local.alloc u8
local.zero %x
%r = borrow.mut %x
%sc = task.scope.begin
%t = task.spawn %sc, @rd(%r)
br @next(%t)
next(%t2: task<u8>):
%one = const.u8 1
store %r, %one
%v = task.join %t2
borrow.end %r
task.scope.end %sc
ret %v
fn @rd(%p: mut<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,42 @@
; The loop body lends the borrow to a new task and passes it back to the header; the exit sees that handle through the header parameter, so ending the borrow before its join is rejected.
; expect: reject E4302
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §34
module test.cfg_provenance_loan_backedge
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%x = local.alloc u8
local.zero %x
%r = borrow.ref %x
%sc = task.scope.begin
%t0 = task.spawn %sc, @zero()
br @head(%t0)
head(%t: task<u8>):
%c = const.bool false
cbr %c, @body(%t), @exit(%t)
body(%tb: task<u8>):
%old = task.join %tb
%t1 = task.spawn %sc, @rd(%r)
br @head(%t1)
exit(%te: task<u8>):
borrow.end %r
%v = task.join %te
task.scope.end %sc
ret %v
fn @rd(%p: ref<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,35 @@
; A task handle passed through an ordinary block argument keeps its loans: ending the lent borrow before the join is rejected.
; expect: reject E4302
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §34
module test.cfg_provenance_loan_br
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%x = local.alloc u8
local.zero %x
%r = borrow.ref %x
%sc = task.scope.begin
%t = task.spawn %sc, @rd(%r)
br @next(%t)
next(%t2: task<u8>):
borrow.end %r
%v = task.join %t2
task.scope.end %sc
ret %v
fn @rd(%p: ref<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,41 @@
; Both cbr targets receive the lent task; ending the borrow before the join on one target is rejected.
; expect: reject E4302
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §34
module test.cfg_provenance_loan_cbr
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%x = local.alloc u8
local.zero %x
%r = borrow.ref %x
%sc = task.scope.begin
%t = task.spawn %sc, @rd(%r)
%c = const.bool true
cbr %c, @early(%t), @late(%t)
early(%a: task<u8>):
borrow.end %r
%va = task.join %a
task.scope.end %sc
ret %va
late(%b: task<u8>):
%vb = task.join %b
borrow.end %r
task.scope.end %sc
ret %vb
fn @rd(%p: ref<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,41 @@
; One predecessor lends the borrow to its task and the other does not; after the join the handle may hold the loan, so ending the borrow first is rejected.
; expect: reject E4302
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §34
module test.cfg_provenance_loan_join
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%x = local.alloc u8
local.zero %x
%r = borrow.ref %x
%sc = task.scope.begin
%c = const.bool true
cbr %c, @lend(), @plain()
lend:
%t1 = task.spawn %sc, @rd(%r)
br @joined(%t1)
plain:
%t2 = task.spawn %sc, @zero()
br @joined(%t2)
joined(%t: task<u8>):
borrow.end %r
%v = task.join %t
task.scope.end %sc
ret %v
fn @rd(%p: ref<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,41 @@
; An integer switch hands the lent task to its targets; ending the borrow before the join on the default target is rejected.
; expect: reject E4302
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §34
module test.cfg_provenance_loan_switch
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%x = local.alloc u8
local.zero %x
%r = borrow.ref %x
%sc = task.scope.begin
%t = task.spawn %sc, @rd(%r)
%k = const.u8 7
switch.u8 %k, 0 -> @zero_case(%t), default -> @other(%t)
zero_case(%a: task<u8>):
%va = task.join %a
borrow.end %r
task.scope.end %sc
ret %va
other(%b: task<u8>):
borrow.end %r
%vb = task.join %b
task.scope.end %sc
ret %vb
fn @rd(%p: ref<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,31 @@
; Only the scope is passed through a block argument; its task is still unjoined when the renamed scope ends.
; expect: reject E4301
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §33
module test.cfg_provenance_scope_alone
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%sc = task.scope.begin
%t = task.spawn %sc, @zero()
br @next(%sc)
next(%s2: scope):
task.scope.end %s2
%v = const.u8 0
ret %v
fn @rd(%p: ref<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,31 @@
; The scope and its task are passed together through block arguments; the renamed scope ends while the renamed task is unjoined.
; expect: reject E4301
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §33
module test.cfg_provenance_scope_task
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> u8
effects [task.spawn, task.wait]
entry:
%sc = task.scope.begin
%t = task.spawn %sc, @zero()
br @next(%sc, %t)
next(%s2: scope, %t2: task<u8>):
task.scope.end %s2
%v = const.u8 0
ret %v
fn @rd(%p: ref<u8>) -> u8
effects []
entry:
%v = load %p
ret %v
fn @zero() -> u8
effects []
entry:
%z = const.u8 0
ret %z
@@ -0,0 +1,19 @@
; Shields passed through block arguments keep their nesting: ending the outer shield first is rejected.
; expect: reject E4305
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §37.3
module test.cfg_provenance_shield_order
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> void
effects []
entry:
%a = task.shield.begin
%b = task.shield.begin
br @next(%a, %b)
next(%outer: shield, %inner: shield):
task.shield.end %outer
task.shield.end %inner
ret
@@ -0,0 +1,21 @@
; Incoming stacks disagree; ending a first also violates the b-inside-a path.
; The two edges into a block pass the live shields in opposite nesting order, so the shield stack differs between edges (spec 04 §37.3).
; expect: reject E3002 E4305
; phase: 3
; spec: docs/spec/04-concurrency-and-atomics.md §37.3
module test.cfg_provenance_shield_stack_join
air 0
lang 0.1
features [cancellation, effects, ownership, tasks]
fn @main() -> void
effects []
entry:
%a = task.shield.begin
%b = task.shield.begin
%c = const.bool true
cbr %c, @joined(%a, %b), @joined(%b, %a)
joined(%x: shield, %y: shield):
task.shield.end %y
task.shield.end %x
ret