1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use collect_ready;
use multiplatform_test;
// TODO(inline): commented out, not yet supported in dfir_syntax! (intra-tick cycle)
// #[multiplatform_test]
// pub fn test_zip_loop() {
// let (result_send, mut result_recv) = dfir_rs::util::unbounded_channel::<(char, usize)>();
//
// let mut df = dfir_syntax! {
// source_iter("Hello World".chars()) -> [0]my_zip;
// source_iter(0..5) -> rhs;
//
// rhs = union() -> tee();
// rhs -> [1]my_zip;
// rhs -> filter_map(|x: usize| x.checked_sub(1)) -> rhs; // Loop
//
// my_zip = zip() -> for_each(|pair| result_send.send(pair).unwrap());
// };
// df.run_available_sync();
//
// let result: Vec<_> = collect_ready(&mut result_recv);
// assert_eq!(
// &[
// ('H', 0),
// ('e', 1),
// ('l', 2),
// ('l', 3),
// ('o', 4),
// (' ', 0),
// ('W', 1),
// ('o', 2),
// ('r', 3),
// ('l', 0),
// ('d', 1)
// ],
// &*result
// );
// }
// TODO(inline): commented out, not yet supported in dfir_syntax! (loop {} blocks)
// #[multiplatform_test(wasm, test, env_tracing)]
// pub fn test_loop_lifetime() {
// let (send_nn, mut recv_nn) = dfir_rs::util::unbounded_channel::<_>();
// let (send_nl, mut recv_nl) = dfir_rs::util::unbounded_channel::<_>();
// let (send_ln, mut recv_ln) = dfir_rs::util::unbounded_channel::<_>();
// let (send_ll, mut recv_ll) = dfir_rs::util::unbounded_channel::<_>();
//
// let mut df = dfir_syntax! {
// a = source_iter(0..2);
// x = source_iter(0..4);
// loop {
// b = a -> batch() -> tee();
// y = x -> batch() -> tee();
// loop {
// b -> repeat_n(2) -> [0]znn;
// y -> all_once() -> [1]znn;
// znn = zip::<'none, 'none>() -> for_each(|v| send_nn.send((context.loop_iter_count(), v)).unwrap());
//
// b -> repeat_n(2) -> [0]znl;
// y -> all_once() -> [1]znl;
// znl = zip::<'none, 'loop>() -> for_each(|v| send_nl.send((context.loop_iter_count(), v)).unwrap());
//
// b -> repeat_n(2) -> [0]zln;
// y -> all_once() -> [1]zln;
// zln = zip::<'loop, 'none>() -> for_each(|v| send_ln.send((context.loop_iter_count(), v)).unwrap());
//
// b -> repeat_n(2) -> [0]zll;
// y -> all_once() -> [1]zll;
// zll = zip::<'loop, 'loop>() -> for_each(|v| send_ll.send((context.loop_iter_count(), v)).unwrap());
// };
// };
// };
//
// df.run_available_sync();
//
// assert_eq!(
// &[(0, (0, 0)), (0, (1, 1))],
// &*collect_ready::<Vec<_>, _>(&mut recv_nn)
// );
// assert_eq!(
// &[(0, (0, 0)), (0, (1, 1)), (1, (0, 2)), (1, (1, 3))],
// &*collect_ready::<Vec<_>, _>(&mut recv_nl)
// );
// assert_eq!(
// &[(0, (0, 0)), (0, (1, 1))],
// &*collect_ready::<Vec<_>, _>(&mut recv_ln)
// );
// assert_eq!(
// &[(0, (0, 0)), (0, (1, 1)), (1, (0, 2)), (1, (1, 3))],
// &*collect_ready::<Vec<_>, _>(&mut recv_ll)
// );
// }