verifier: preserve resource obligations across CFG handoff
This commit is contained in:
1 parent
0e98638bc6
commit
09fbf8a5bc
34 files changed
+1267
-67
No files matched your search
@@ -0,0 +1,38 @@
|
||||
; The cancelled handle of task.join.cancel may travel through an ordinary block argument; joining it before ending the lent borrow is valid.
|
||||
; expect: run
|
||||
; schedules: 20
|
||||
; result: 5
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md §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
|
||||
%five = const.u8 5
|
||||
local.store %x, %five
|
||||
%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>):
|
||||
%v2 = task.join %t2
|
||||
task.scope.end %sc
|
||||
borrow.end %r
|
||||
ret %v2
|
||||
|
||||
fn @rd(%p: ref<u8>) -> u8
|
||||
effects []
|
||||
entry:
|
||||
%v = load %p
|
||||
ret %v
|
||||
@@ -0,0 +1,41 @@
|
||||
; Two scopes and their tasks are permuted together on the two edges into a block; each renamed task belongs to the renamed scope beside it, so joining and ending them pairwise is valid.
|
||||
; expect: run
|
||||
; schedules: 20
|
||||
; result: 12
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md §33
|
||||
module test.cfg_provenance_correlated_scopes
|
||||
air 0
|
||||
lang 0.1
|
||||
features [cancellation, effects, ownership, tasks]
|
||||
|
||||
fn @main() -> u8
|
||||
effects [task.spawn, task.wait]
|
||||
entry:
|
||||
%s1 = task.scope.begin
|
||||
%s2 = task.scope.begin
|
||||
%t1 = task.spawn %s1, @one()
|
||||
%t2 = task.spawn %s2, @two()
|
||||
%c = const.bool true
|
||||
cbr %c, @next(%s1, %s2, %t1, %t2), @next(%s2, %s1, %t2, %t1)
|
||||
next(%pa: scope, %pb: scope, %ta: task<u8>, %tb: task<u8>):
|
||||
%va = task.join %ta
|
||||
task.scope.end %pa
|
||||
%vb = task.join %tb
|
||||
task.scope.end %pb
|
||||
%ten = const.u8 10
|
||||
%hi = mul.checked.u8 %va, %ten
|
||||
%r = add.checked.u8 %hi, %vb
|
||||
ret %r
|
||||
|
||||
fn @one() -> u8
|
||||
effects []
|
||||
entry:
|
||||
%v = const.u8 1
|
||||
ret %v
|
||||
|
||||
fn @two() -> u8
|
||||
effects []
|
||||
entry:
|
||||
%v = const.u8 2
|
||||
ret %v
|
||||
@@ -0,0 +1,33 @@
|
||||
; A guard may be passed through a block argument; borrowing through it, unlocking and only then ending the mutex borrow is valid.
|
||||
; expect: run
|
||||
; schedules: 20
|
||||
; result: 7
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md §40
|
||||
module test.cfg_provenance_guard_handoff
|
||||
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>):
|
||||
%p = mutex.borrow %g2
|
||||
%seven = const.u64 7
|
||||
store %p, %seven
|
||||
borrow.end %p
|
||||
mutex.unlock %g2
|
||||
borrow.end %mr
|
||||
%v = mutex.take %m
|
||||
ret %v
|
||||
out:
|
||||
borrow.end %mr
|
||||
%w = mutex.take %m
|
||||
ret %w
|
||||
@@ -0,0 +1,39 @@
|
||||
; Joining the renamed handle returns its exclusive loan before parent reuse.
|
||||
; expect: run
|
||||
; schedules: 20
|
||||
; result: 0
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md §34
|
||||
module test.cfg_provenance_loan_returned
|
||||
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>):
|
||||
%v = task.join %t2
|
||||
%one = const.u8 1
|
||||
store %r, %one
|
||||
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,22 @@
|
||||
; Shields may be passed through block arguments and ended innermost first.
|
||||
; expect: run
|
||||
; schedules: 20
|
||||
; result: 4
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md §37.3
|
||||
module test.cfg_provenance_shield_handoff
|
||||
air 0
|
||||
lang 0.1
|
||||
features [cancellation, effects, ownership, tasks]
|
||||
|
||||
fn @main() -> u8
|
||||
effects []
|
||||
entry:
|
||||
%a = task.shield.begin
|
||||
%b = task.shield.begin
|
||||
br @next(%a, %b)
|
||||
next(%outer: shield, %inner: shield):
|
||||
task.shield.end %inner
|
||||
task.shield.end %outer
|
||||
%v = const.u8 4
|
||||
ret %v
|
||||
@@ -0,0 +1,42 @@
|
||||
; A loop lends a borrow to a new task each iteration and joins it at the header; the borrow ends only after the last join.
|
||||
; expect: run
|
||||
; schedules: 20
|
||||
; result: 3
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md §34
|
||||
module test.cfg_provenance_task_loop
|
||||
air 0
|
||||
lang 0.1
|
||||
features [cancellation, effects, ownership, tasks]
|
||||
|
||||
fn @main() -> u8
|
||||
effects [task.spawn, task.wait]
|
||||
entry:
|
||||
%x = local.alloc u8
|
||||
%one = const.u8 1
|
||||
local.store %x, %one
|
||||
%r = borrow.ref %x
|
||||
%sc = task.scope.begin
|
||||
%t0 = task.spawn %sc, @rd(%r)
|
||||
%zero = const.u8 0
|
||||
br @head(%t0, %zero, %zero)
|
||||
head(%t: task<u8>, %acc: u8, %i: u8):
|
||||
%v = task.join %t
|
||||
%acc2 = add.checked.u8 %acc, %v
|
||||
%i2 = add.checked.u8 %i, %one
|
||||
%three = const.u8 3
|
||||
%more = lt.u8 %i2, %three
|
||||
cbr %more, @body(%acc2, %i2), @exit(%acc2)
|
||||
body(%a: u8, %n: u8):
|
||||
%t1 = task.spawn %sc, @rd(%r)
|
||||
br @head(%t1, %a, %n)
|
||||
exit(%total: u8):
|
||||
task.scope.end %sc
|
||||
borrow.end %r
|
||||
ret %total
|
||||
|
||||
fn @rd(%p: ref<u8>) -> u8
|
||||
effects []
|
||||
entry:
|
||||
%v = load %p
|
||||
ret %v
|
||||
Reference in new issue
Block a user