Did the fix work ?
.. anvil-playground::
:playground-url: https://anvil.kisp-lab.org
chan foobar_ch {
left req : (logic[8]@res),
right res : (logic[8]@#1)
}
func is_even(x){
x & 8'd1 == 8'd0
}
func answer_to_universe(x){
if (call is_even(x)){
8'd42
}
else{
8'd0
}
}
proc Foo(ep : left foobar_ch) {
reg cycle_count : logic[8];
reg ans : logic[8];
loop {
let x = recv ep.req >>
if(call is_even(x)){
dprint"[Cycle %d] Received even number %d : Should get answer 42 in 3 cycles" (*cycle_count, x) >>
cycle 2 >>
set ans := call answer_to_universe(x)
}
else{
dprint"[Cycle %d] Received odd number %d : Should get answer 0 in 4 cycles" (*cycle_count, x) >>
cycle 3 >>
set ans := call answer_to_universe(x)
} >>
send ep.res (*ans) >>
cycle 1
}
loop{
set cycle_count := *cycle_count + 8'd1
}
}
proc Top(){
chan ep_le -- ep_ri : foobar_ch;
spawn Foo(ep_le);
reg input : logic[8];
reg counter : logic[8];
loop {
send ep_ri.req (*input) >>
let data = recv ep_ri.res >>
set input:= *input + 8'd1 >>
dprint"[Cycle %d] The answer to the universe is %d" (*counter, data) >>
cycle 1
}
loop{
set counter := *counter + 8'd1
}
loop{
cycle 10 >>
dfinish
}
}
.. raw:: html
```
This change produces a different type error: `Top` uses `data` after its lifetime expires. The response lifetime, `@#1`, guarantees validity for only one cycle after the send of `res`. Any use of `data` must therefore occur within one cycle of the receive.
The code instead uses `data` after `set`. Because `set` consumes one cycle, it delays that use beyond the permitted lifetime. The type checker therefore rejects the program.
To use `data` within its lifetime, it must be consumed before any operation advances the cycle. Moving `set` after `dprint` ensures that the print uses `data` in time:
```{eval-rst}
.. raw:: html