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_17 = const.u8 0 ret %c_17 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(%i_4) 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(%i_14: u64): %c_15 = const.u64 1 %t_16 = add.checked.u64 %i_14, %c_15 br @while_2(%t_16) 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_37 = task.join %t_10 task.scope.end %sc_8 br @endmatch_38(%acc_15) ok_17(%ok_18: u64): borrow.end %r_16 %t_21 = add.checked.u64 %acc_13, %ok_18 br @endmatch_34(%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_28, pending -> @pending_29 ok_22: br @after_12(%acc_13) pending_23(%pending_24: receiver): br @endmatch_25(%acc_13, %pending_24) endmatch_25(%acc_26: u64, %r_27: receiver): br @endmatch_34(%acc_26, %r_27) ok_28: br @after_12(%acc_13) pending_29(%pending_30: receiver): br @endmatch_31(%acc_13, %pending_30) endmatch_31(%acc_32: u64, %r_33: receiver): br @endmatch_34(%acc_32, %r_33) endmatch_34(%acc_35: u64, %r_36: receiver): br @loop_11(%acc_35, %r_36) endmatch_38(%match_39: u64): ret %match_39