43 lines
1.0 KiB
LLVM
43 lines
1.0 KiB
LLVM
; 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
|