module demo.producerconsumer air 0 lang 0.1 features [cancellation, capabilities, channels, effects, heap, ownership, resources, tasks] fn @produce(%tx: sender, %n: u64) -> u8 effects [task.wait] entry: %c_1 = const.u64 0 br @while_2(%c_1) while_2(%i_4: u64): %cmp_5 = ne.u64 %i_4, %n cbr %cmp_5, @body_6(), @after_3() after_3: channel.close_sender %tx %c_16 = const.u8 0 ret %c_16 body_6: %tx_7 = borrow.mut %tx channel.send %tx_7, %i_4, ok -> @ok_8, closed -> @closed_9, cancelled -> @cancelled_11 ok_8: borrow.end %tx_7 br @endmatch_13() closed_9(%closed_10: u64): borrow.end %tx_7 br @after_3() cancelled_11(%cancelled_12: u64): borrow.end %tx_7 br @after_3() endmatch_13: %c_14 = const.u64 1 %t_15 = add.checked.u64 %i_4, %c_14 br @while_2(%t_15) fn @main(%heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] entry: %c_1 = const.usize 2 channel.make u64, %c_1, %heap, ok -> @ok_2, err -> @err_5 ok_2(%ok_3: sender, %ok_4: receiver): %c_7 = const.u64 0 %sc_8 = task.scope.begin %c_9 = const.u64 5 %t_10 = task.spawn %sc_8, @produce(%ok_3, %c_9) br @loop_11(%c_7, %ok_4) err_5(%err_6: alloc_error): trap loop_11(%acc_13: u64, %r_14: receiver): %r_16 = borrow.mut %r_14 channel.recv %r_16, ok -> @ok_17, closed -> @closed_19, cancelled -> @cancelled_20 after_12(%acc_15: u64): %r_35 = task.join %t_10 task.scope.end %sc_8 br @endmatch_36(%acc_15) ok_17(%ok_18: u64): borrow.end %r_16 %t_21 = add.checked.u64 %acc_13, %ok_18 br @endmatch_32(%t_21, %r_14) closed_19: borrow.end %r_16 channel.close_receiver %r_14, ok -> @ok_22, pending -> @pending_23 cancelled_20: borrow.end %r_16 channel.close_receiver %r_14, ok -> @ok_27, pending -> @pending_28 ok_22: br @after_12(%acc_13) pending_23(%pending_24: receiver): br @endmatch_25(%pending_24) endmatch_25(%r_26: receiver): br @endmatch_32(%acc_13, %r_26) ok_27: br @after_12(%acc_13) pending_28(%pending_29: receiver): br @endmatch_30(%pending_29) endmatch_30(%r_31: receiver): br @endmatch_32(%acc_13, %r_31) endmatch_32(%acc_33: u64, %r_34: receiver): br @loop_11(%acc_33, %r_34) endmatch_36(%match_37: u64): ret %match_37