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,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
|
||||
@@ -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
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E4302
|
||||
// phase: 6
|
||||
// spec: docs/spec/04-concurrency-and-atomics.md §37
|
||||
// AIR twin: phase3/reject/cancel_join_keeps_loans.air
|
||||
module test.twins.cancel_join_keeps_loans
|
||||
|
||||
fn work(p: ref<u8>) -> u8 effects [] {
|
||||
return *p;
|
||||
}
|
||||
|
||||
fn main() -> u8 effects [task.spawn, task.wait] {
|
||||
var data: u8 = zero;
|
||||
scope sc {
|
||||
let t = {
|
||||
ref part = data; // diagnostic here
|
||||
let t = task.spawn(sc, work, part); // task spawn here
|
||||
match task.join_cancel(move t) {
|
||||
ok(n) => {
|
||||
return n;
|
||||
} cancelled(t) => {
|
||||
move t
|
||||
}
|
||||
}
|
||||
};
|
||||
return task.join(move t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E4302
|
||||
// phase: 6
|
||||
// spec: docs/spec/04-concurrency-and-atomics.md §37
|
||||
// AIR twin: phase3/reject/cancel_join_twice_keeps_spawn.air
|
||||
module test.twins.cancel_join_twice_keeps_spawn
|
||||
|
||||
fn work(p: ref<u8>) -> u8 effects [] {
|
||||
return *p;
|
||||
}
|
||||
|
||||
fn main() -> u8 effects [task.spawn, task.wait] {
|
||||
var data: u8 = zero;
|
||||
scope sc {
|
||||
let t = {
|
||||
ref part = data; // diagnostic here
|
||||
let t = task.spawn(sc, work, part); // task spawn here
|
||||
match task.join_cancel(move t) {
|
||||
ok(n) => {
|
||||
return n;
|
||||
} cancelled(t) => {
|
||||
match task.join_cancel(move t) {
|
||||
ok(n) => {
|
||||
return n;
|
||||
} cancelled(t) => {
|
||||
move t
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return task.join(move t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// expect: run
|
||||
// schedules: 20
|
||||
// result: 7
|
||||
// phase: 6
|
||||
// spec: docs/spec/04-concurrency-and-atomics.md §34
|
||||
module test.cfg_provenance.cancel_task_block
|
||||
|
||||
fn read(p: ref<u8>) -> u8 effects [] {
|
||||
return *p;
|
||||
}
|
||||
|
||||
fn main() -> u8 effects [task.spawn, task.wait] {
|
||||
var data: u8 = 7u8;
|
||||
ref part = data;
|
||||
scope sc {
|
||||
let t = {
|
||||
let child = task.spawn(sc, read, part);
|
||||
match task.join_cancel(move child) {
|
||||
ok(n) => {
|
||||
return n;
|
||||
} cancelled(back) => {
|
||||
move back
|
||||
}
|
||||
}
|
||||
};
|
||||
return task.join(move t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// expect: run
|
||||
// schedules: 20
|
||||
// result: 7
|
||||
// phase: 6
|
||||
// spec: docs/spec/04-concurrency-and-atomics.md §34
|
||||
module test.cfg_provenance.task_block
|
||||
|
||||
fn read(p: ref<u8>) -> u8 effects [] {
|
||||
return *p;
|
||||
}
|
||||
|
||||
fn main() -> u8 effects [task.spawn, task.wait] {
|
||||
var data: u8 = 7u8;
|
||||
ref part = data;
|
||||
scope sc {
|
||||
let t = {
|
||||
let child = task.spawn(sc, read, part);
|
||||
move child
|
||||
};
|
||||
return task.join(move t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// expect: run
|
||||
// schedules: 20
|
||||
// result: 7
|
||||
// phase: 6
|
||||
// spec: docs/spec/04-concurrency-and-atomics.md §34
|
||||
module test.cfg_provenance.task_branch
|
||||
|
||||
fn read(p: ref<u8>) -> u8 effects [] {
|
||||
return *p;
|
||||
}
|
||||
|
||||
fn main() -> u8 effects [task.spawn, task.wait] {
|
||||
var data: u8 = 7u8;
|
||||
ref part = data;
|
||||
scope sc {
|
||||
let t = if true {
|
||||
task.spawn(sc, read, part)
|
||||
} else {
|
||||
task.spawn(sc, read, part)
|
||||
};
|
||||
return task.join(move t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// expect: reject E4302
|
||||
// phase: 6
|
||||
// spec: docs/spec/04-concurrency-and-atomics.md §34
|
||||
// AIR twin: phase3/reject/tasks_end_lent_borrow.air
|
||||
module test.twins.tasks_end_lent_borrow
|
||||
|
||||
fn work(p: mut<u64>) -> u64 effects [] {
|
||||
return *p;
|
||||
}
|
||||
|
||||
fn main() -> u64 effects [task.spawn] {
|
||||
var data: u64 = zero;
|
||||
scope sc {
|
||||
let t = {
|
||||
mut part = data; // diagnostic here
|
||||
task.spawn(sc, work, part) // task spawn here
|
||||
};
|
||||
return task.join(move t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Resource handoff, exact loan origins and source/package/AIR diagnostics."""
|
||||
from collections import Counter
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
AJI = REPO / 'zig-out/bin/aji'
|
||||
CORPUS = REPO / 'tests/conformance'
|
||||
checks = 0
|
||||
|
||||
|
||||
def records(*args, code=0):
|
||||
global checks
|
||||
result = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True)
|
||||
assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr)
|
||||
checks += 1
|
||||
def unique(pairs):
|
||||
out = {}
|
||||
for key, value in pairs:
|
||||
assert key not in out, ('duplicate diagnostic field', key)
|
||||
out[key] = value
|
||||
return out
|
||||
return [json.loads(line, object_pairs_hook=unique) for line in result.stdout.splitlines()]
|
||||
|
||||
|
||||
def lower(*args):
|
||||
global checks
|
||||
result = subprocess.run([str(AJI), 'lower', *map(str, args)], capture_output=True, text=True)
|
||||
assert result.returncode == 0, result
|
||||
checks += 1
|
||||
return result.stdout
|
||||
|
||||
|
||||
def marker(source, text, token):
|
||||
lines = [(i + 1, line) for i, line in enumerate(source.splitlines()) if text in line]
|
||||
assert len(lines) == 1, lines
|
||||
line, contents = lines[0]
|
||||
return line, contents.index(token) + 1
|
||||
|
||||
|
||||
def rejection(root, path, *args, file=None):
|
||||
source = path.read_text()
|
||||
expected = marker(source, '// diagnostic here', 'part')
|
||||
# Binding diagnostics use the ref/mut keyword, not the bound name.
|
||||
line = source.splitlines()[expected[0] - 1]
|
||||
expected = expected[0], len(line) - len(line.lstrip()) + 1
|
||||
spawn = marker(source, '// task spawn here', 'task.spawn')
|
||||
ds = records('check', *args, code=1)
|
||||
assert len(ds) == 1 and ds[0]['code'] == 'E4302', ds
|
||||
d = ds[0]
|
||||
assert (d['file'], d['line'], d['col']) == (file or str(path), *expected), d
|
||||
related, = d['related_locations']
|
||||
assert (related['file'], related['line'], related['col']) == (file or str(path), *spawn), related
|
||||
assert related['role'] == 'task_spawn' and related['value'] == d['task'], d
|
||||
for command in ('run', 'report', 'explore'):
|
||||
assert records(command, *args, code=1) == ds
|
||||
canonical = lower(*args)
|
||||
assert canonical == lower(*args)
|
||||
lines = canonical.splitlines()
|
||||
assert lines[d['air_line'] - 1].strip().startswith('borrow.end '), d
|
||||
assert ' = task.spawn ' in lines[related['air_line'] - 1], related
|
||||
raw = root / 'lowered.air'
|
||||
raw.write_text(canonical)
|
||||
raw_d, = records('check', raw, code=1)
|
||||
assert (raw_d['line'], raw_d['col']) == (d['air_line'], d['air_col']), raw_d
|
||||
raw_related, = raw_d['related_locations']
|
||||
assert (raw_related['line'], raw_related['col']) == (related['air_line'], related['air_col'])
|
||||
assert raw_d['task'] == d['task'] and raw_related['value'] == d['task']
|
||||
return ds
|
||||
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix='aji-cfg-provenance-') as directory:
|
||||
root = Path(directory)
|
||||
sources = sorted((CORPUS / 'source/cfg_provenance').glob('*.aji'))
|
||||
rejected = 0
|
||||
for path in sources:
|
||||
source = path.read_text()
|
||||
if '// expect: reject' in source:
|
||||
rejected += 1
|
||||
ds = rejection(root, path, path)
|
||||
twin = re.search(r'^// AIR twin: (.+)$', source, re.MULTILINE)
|
||||
assert twin, path
|
||||
expected = records('check', CORPUS / twin[1], code=1)
|
||||
assert Counter(d['code'] for d in ds) == Counter(d['code'] for d in expected)
|
||||
else:
|
||||
assert not records('check', path)
|
||||
raw = root / 'accepted.air'
|
||||
raw.write_text(lower(path))
|
||||
assert not records('check', raw)
|
||||
for seed in range(8):
|
||||
for quantum in (1, 7):
|
||||
options = ('--fuel', 100000, '--schedule-seed', seed, '--quantum', quantum)
|
||||
result, = records('run', *options, path)
|
||||
reference, = records('run', *options, raw)
|
||||
assert result == reference, (path, result, reference)
|
||||
assert result['value'] == 7, result
|
||||
|
||||
# Explicitly execute the other tuple permutation; scheduler seeds alone
|
||||
# cannot change a constant branch condition.
|
||||
permuted = root / 'permuted.air'
|
||||
source = (CORPUS / 'phase3/run/cfg_provenance_correlated_scopes.air').read_text()
|
||||
permuted.write_text(source.replace('const.bool true', 'const.bool false'))
|
||||
assert not records('check', permuted)
|
||||
for seed in range(8):
|
||||
result, = records('run', '--fuel', 100000, '--schedule-seed', seed, '--quantum', 1, permuted)
|
||||
assert result['value'] == 21, result
|
||||
|
||||
# Package/generic specialization retains the provider's factual positions.
|
||||
library = root / 'library.aji'
|
||||
source = (CORPUS / 'source/cfg_provenance/cancel_join_twice_keeps_spawn.aji').read_text()
|
||||
source = re.sub(r'^module .+$', 'module app.library', source, flags=re.MULTILINE)
|
||||
library.write_text(source.replace('fn main()', 'fn bad<T: Copy>()'))
|
||||
(root / 'entry.aji').write_text('''module app.entry
|
||||
import app.library;
|
||||
fn main() -> u8 effects [task.spawn, task.wait] {
|
||||
return app.library.bad::<u8>();
|
||||
}
|
||||
''')
|
||||
manifest = root / 'aji.toml'
|
||||
manifest.write_text('''[package]
|
||||
name = "provenance"
|
||||
version = "1"
|
||||
entry = "entry.aji"
|
||||
[modules]
|
||||
app.library = "library.aji"
|
||||
''')
|
||||
rejection(root, library, '--manifest', manifest, file='library.aji')
|
||||
shield = records('check', CORPUS / 'phase3/reject/cfg_provenance_shield_stack_join.air', code=1)
|
||||
assert [d['code'] for d in shield] == ['E3002', 'E4305'], shield
|
||||
assert shield[0]['resource'].startswith('%'), shield
|
||||
|
||||
assert rejected == 3, rejected
|
||||
print(f'source CFG provenance: {checks} CLI checks, {rejected} loan rejection twins')
|
||||
Reference in new issue
Block a user