mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Do not drop uninhabited captures from lambda sets
Previously, we would drop uninhabited captures from lambda sets' runtime
representations, which meant sets like
```
[L1 {a: Str}, L2 {a: []}]
```
had runtime representation
```
{Str}
```
rather than
```
Union({Str}, {[]})
```
if we drop unreachable lambdas from the representation, then the
reachable lambdas are somewhat more efficient to compile (as there are
less material tag options), but the compiler complexity increases
because we must represent voided capture sets in the lambda set.
Even if a lambda has voided captures, we must specialize it, because
failing to do so opens us up to losing relevant specializations needed
later on. See 2f7020aa31
for a
previous occurence of that.
As such, simply keep voided layouts in place during lambda set
compilation. The optimizer should elide them anyway.
This commit is contained in:
parent
e27a06849d
commit
a5e1558a6e
3 changed files with 253 additions and 10 deletions
|
@ -3216,3 +3216,47 @@ fn linked_list_filter() {
|
|||
"#
|
||||
)
|
||||
}
|
||||
|
||||
#[mono_test]
|
||||
fn capture_void_layout_task() {
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
Fx a : {} -> a
|
||||
|
||||
Task ok err : Fx (Result ok err)
|
||||
|
||||
succeed : ok -> Task ok *
|
||||
succeed = \ok -> \{} -> Ok ok
|
||||
|
||||
after : Fx a, (a -> Fx b) -> Fx b
|
||||
after = \fx, toNext ->
|
||||
afterInner = \{} ->
|
||||
fxOut = fx {}
|
||||
next = toNext fxOut
|
||||
next {}
|
||||
|
||||
afterInner
|
||||
|
||||
await : Task a err, (a -> Task b err) -> Task b err
|
||||
await = \fx, toNext ->
|
||||
inner = after fx \result ->
|
||||
when result is
|
||||
Ok a ->
|
||||
bFx = toNext a
|
||||
bFx
|
||||
Err e -> (\{} -> Err e)
|
||||
inner
|
||||
|
||||
forEach : List a, (a -> Task {} err) -> Task {} err
|
||||
forEach = \list, fromElem ->
|
||||
List.walk list (succeed {}) \task, elem ->
|
||||
await task \{} -> fromElem elem
|
||||
|
||||
main : Task {} []
|
||||
main =
|
||||
forEach [] \_ -> succeed {}
|
||||
"#
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue