roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.45k stars 312 forks source link

`specialize_external` needs to support zero argument thunks #3517

Closed bhansconnect closed 2 years ago

bhansconnect commented 2 years ago

Currently specialize_external does not support zero argument thunks. Specifically, this match statement needs to be expanded.

It currently has ZeroArgumentThunk as unreachable, but this is not accurate. It can be reached when returning a union from the main function. For example:

mainForHost : [Some I32, None] as Option

Or:

mainForHost : [I32Cont ((I32 -> Continuation) as Cont1), F32Cont ((F32 -> Continuation) as Cont2), Done I32] as Continuation

In the first example, it is technically possible to remove the as Option and get Roc to generate functioning code. That being said, in this second example, the as Continuation is definitely needed because the type must be named to be self recursive.

According to @folkertdev, we should only need to generate a size function for these types. Other functions should not need to be generated.

ayazhafiz commented 2 years ago

I had a patch that did this in https://github.com/rtfeldman/roc/pull/2729, but I forgot why I didn't end up working.

bhansconnect commented 2 years ago

Any help would be greatly appreciated. I want to continue testing using Roc with async future. For now, they will be directly returned via a tagged union with a continuation. So I need that feature or another work around.

ayazhafiz commented 2 years ago

i can take a look tomorrow