Stream: compiler development

Topic: lambda sets: compiled


view this post on Zulip Ayaz Hafiz (Aug 15 2024 at 02:48):

Alright I have a present for you all
I built a compiler that properly compiles lambda sets. The key insight is making sure to solve the type of lambda captures, transitively

See this example that solves a long-standing lambda set bug and enables effect interpreters in my compiler
The issue it solves is https://github.com/roc-lang/roc/issues/5464
If you want to study the source code, which is quite small but many passes, it is here https://github.com/ayazhafiz/cor/tree/base/experiments/lss

This is a proper monomorphizing compiler. I don't emit machine code or anything like that but the low-level IR pass is first-order and is trivial to compile to C or asm

view this post on Zulip Sam Mohr (Aug 15 2024 at 02:51):

Holy shit

view this post on Zulip Luke Boswell (Aug 15 2024 at 02:51):

Sam Mohr said:

Holy shit

Well said

view this post on Zulip Sam Mohr (Aug 15 2024 at 02:51):

Wait, so we don't need type erasure, do we??

view this post on Zulip Sam Mohr (Aug 15 2024 at 02:55):

If that's the case, I'd be happy to help with the translation of this work to the Roc compiler! Super exciting

view this post on Zulip Luke Boswell (Aug 15 2024 at 03:12):

Likewise, if there is anything we need on the platform side, like updating Brendan's POC I'm happy to help too.

view this post on Zulip Richard Feldman (Aug 15 2024 at 12:22):

omg omg omg

view this post on Zulip Richard Feldman (Aug 15 2024 at 12:23):

THIS IS THE BEST NEWS!!!!!!!

view this post on Zulip Richard Feldman (Aug 15 2024 at 12:24):

:star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck:

view this post on Zulip Brendan Hansknecht (Aug 15 2024 at 21:59):

I can't wait for when this lands in Roc! Will unlock so much stuff!!!

view this post on Zulip Brendan Hansknecht (Aug 15 2024 at 21:59):

I can't wait for true async effect interpreters

view this post on Zulip Brendan Hansknecht (Aug 15 2024 at 22:00):

Also should unblocks some random complex code like my sqlite improvements for basic-webserver and the better version of encode and decode.

view this post on Zulip Luke Boswell (Aug 15 2024 at 23:12):

There's a nice long list of really awesome things this should enable. I'm so excited to hear this news. Thank you Ayaz for sharing :grinning_face_with_smiling_eyes:

view this post on Zulip Ayaz Hafiz (Aug 18 2024 at 03:23):

I've also partially implemented type erasure, as needed for Map2 - Map2 example here

view this post on Zulip Richard Feldman (Sep 20 2024 at 22:33):

quick note - I'm gonna take on the implementation of this!

view this post on Zulip Brendan Hansknecht (Sep 21 2024 at 01:25):

Infinitely excited :laughing:

view this post on Zulip Agus Zubiaga (Sep 21 2024 at 02:56):

Let’s gooo

view this post on Zulip Ayaz Hafiz (Dec 29 2024 at 00:24):

I was going to implement part of this in the Roc codebase the past couple days but I figured it would probably be a better use of my time to describe the implementation in significant detail, so that it can be discussed and hopefully easy for anyone to contribute to.

Here's a doc with the compilation process in significant detail - it's the same code as I shared before, but this time well-annotated (PR, doc). Please let comments/critiques/let me know where I'm using confusing language/what could be more clear/etc, I will address them.

I'll get to the remaining detailed sections on function lifting, function solving, and function specialization tonight and in the next few days.

Of note, I still think that switching to have all recursive types required to be nominal would make much of this simpler and more efficient in the long term. See https://github.com/roc-lang/rfcs/blob/ayaz/compile-with-lambda-sets/0102-compiling-lambda-sets.md


Last updated: Jul 06 2025 at 12:14 UTC