; The same owned value appears in two send arms: it is consumed only on the ; edge of the arm that runs; every other edge hands it back as a parameter. ; expect: run ; grant: heap=mem.alloc:64 ; schedules: 20 ; result: 42 ; phase: 3 ; spec: docs/spec/04-concurrency-and-atomics.md module test.select_same_value air 0 lang 0.1 features [cancellation, capabilities, channels, effects, heap, ownership, resources, tasks] fn @main(%heap: cap) -> u64 effects [mem.alloc, task.wait] entry: %one = const.usize 1 channel.make own, %one, %heap, ok -> @a_made, err -> @oom a_made(%ta: sender>, %ra: receiver>): channel.make own, %one, %heap, ok -> @b_made, err -> @oom2 b_made(%tb: sender>, %rb: receiver>): %v = const.u64 42 own.new %v, %heap, ok -> @owned, err -> @oom3 owned(%x: own): %tab = borrow.mut %ta %tbb = borrow.mut %tb select [send %tab, %x, ok -> @sent, closed -> @back], [send %tbb, %x, ok -> @sent, closed -> @back], cancelled -> @back back(%returned: own): trap sent: borrow.end %tab borrow.end %tbb %rab = borrow.mut %ra %rbb = borrow.mut %rb select [recv %rab, ok -> @got, closed -> @none], [recv %rbb, ok -> @got, closed -> @none], cancelled -> @none got(%o: own): borrow.end %rab borrow.end %rbb %r = own.take %o ; senders stay open until now: an empty channel whose senders are closed ; would make its receive arm ready with `closed` channel.close_sender %ta channel.close_sender %tb channel.close_receiver %ra, ok -> @ca, pending -> @stuck ca: channel.close_receiver %rb, ok -> @cb, pending -> @stuck2 cb: ret %r none: trap stuck(%p: receiver>): trap stuck2(%p2: receiver>): trap oom(%e: alloc_error): trap oom2(%e2: alloc_error): trap oom3(%e3: alloc_error): trap