Stream: compiler development

Topic: alias optional record destructure


view this post on Zulip Trevor Settles (Apr 03 2024 at 04:19):

I've been working on https://github.com/roc-lang/roc/issues/6532, and I've got a representation question. The two options I see for the AST to represent something like {x: x1 ? 0.0} is to:

  1. Create a new kind of node, something like Pattern::AliasedOptionalField that holds a references to x, x1 as a Pattern::Identifier, and 0.0 as an Expr.
  2. Have the Pattern::RequiredField hold a reference to a Patter::OptionalField in this case.

Option 1 seems to be more semantically correct, while option 2 seems like an easier change. I'm inclined to go with option 1, but wanted to get some feedback before I get too far. Is there another option I'm missing here?

@Brendan Hansknecht and @Luke Boswell, you may have some input here as I mentioned this a different stream. I didn't want to derail that, so I thought I should move the conversation here

view this post on Zulip Luke Boswell (Apr 03 2024 at 04:21):

I'm barely qualified to comment on this, but I feel like I'd try Option 1 first.

view this post on Zulip Luke Boswell (Apr 03 2024 at 04:22):

I'm not sure how it flows through to Can and later stages... so that would be where i would be looking to see what makes the most sense.

view this post on Zulip Trevor Settles (Apr 10 2024 at 21:43):

I'm getting stuck trying to figure out parsing for this one. Is anyone familiar with the parser able to help?
I've modified the roc_parse::parse::record_pattern_help so that it can parse the new syntax in a test, but when I try to run the whole compiler, the new code doesn't seem to get run. It seems like another part of the parser is recognizing it. I've also tried looking for other uses of collection_trailing_sep_e, but the only other usage that seemed similar was in the record_type function

view this post on Zulip Brendan Hansknecht (Apr 10 2024 at 22:19):

@Joshua Warner and @Ayaz Hafiz know the most about the parser. Maybe @Folkert de Vries has some idea as well?

view this post on Zulip Luke Boswell (Apr 11 2024 at 00:43):

I can probably help, but not until tomorrow sometime.

view this post on Zulip Luke Boswell (Apr 11 2024 at 00:43):

Do you have a WIP branch?

view this post on Zulip Trevor Settles (Apr 11 2024 at 00:58):

Ok, cool. I've got this PR. I've done a few more exploratory changes, but nothing that I've committed and pushed

view this post on Zulip Luke Boswell (Apr 11 2024 at 01:42):

Cool. I'm quite terrible I think with the parser, but I have spent the last couple of weeks looking at it trying to figure out how it works.

view this post on Zulip Luke Boswell (Apr 11 2024 at 01:42):

So hopefully I cant help

view this post on Zulip Joshua Warner (Apr 15 2024 at 18:51):

You should be able to run with --features=parse_debug_trace, and it'll print out a bunch of useful debug information about what the parser is doing

view this post on Zulip Trevor Settles (Apr 15 2024 at 19:38):

Yeah, I did end up finding that, as well. That's what allowed me to figure out exactly what was running. Great tip!


Last updated: Jul 06 2025 at 12:14 UTC