mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-23 22:45:14 +00:00
![]() Suppose we have a when expression ``` 15 if foo -> <b1> b if bar -> <b2> _ -> <b3> ``` that may have a decision tree like ``` 15? \true => foo? \true => <b1> \false => bar? \true => <b2> \false => <b3> \false => bar? \true => <b2> \false => <b3> ``` In this case, the guard "bar?" appears twice in the compiled decision tree. We need to materialize the guard expression in both locations in the compiled tree, which means we cannot as-is stamp a compiled `bar?` twice in each location. The reason is that - the compiled joinpoint for each `bar?` guard needs to have a unique ID - the guard expression might have call which needs unique call spec IDs, or other joins that need unique joinpoint IDs. So, save the expression as we build up the decision tree and materialize the guard each time we need it. In practice the guards should be quite small, so duplicating should be fine. We could avoid duplication, but it's not clear to me how to do that exactly since the branches after the guard might end up being different. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |