Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let rec patterns #2031

Merged
merged 7 commits into from
Sep 12, 2024
Merged

Let rec patterns #2031

merged 7 commits into from
Sep 12, 2024

Conversation

jneem
Copy link
Member

@jneem jneem commented Sep 6, 2024

Depends on #2010

Allows let rec bindings to contain patterns. Also fixes a bug in lsp completions, where pattern bindings were accidentally already treated as recursive.

The destructuring is no longer desugared to a match block (which allows for slightly better diagnostics), but it is still as eager as a match block destructuring and it still uses the same pattern compilation under the hood. The motivations for destructuring eagerly,

  • to share code with pattern compilation for match bindings,
  • to have similar behavior in match blocks and let bindings, and
  • to catch errors earlier (with lazy destructuring, let 'Foo = 'Bar in true won't error)

@github-actions github-actions bot temporarily deployed to pull request September 6, 2024 12:33 Inactive
Copy link
Contributor

github-actions bot commented Sep 6, 2024

🐰Bencher

ReportThu, September 12, 2024 at 01:47:17 UTC
Projectnickel
Branch2031/merge
Testbedubuntu-latest

⚠️ WARNING: The following Measure does not have a Threshold. Without a Threshold, no Alerts will ever be generated!

  • Latency (latency)

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds CLI flag.

Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns)
fibonacci 10➖ (view plot)487,690.00
pidigits 100➖ (view plot)3,233,900.00
product 30➖ (view plot)805,260.00
scalar 10➖ (view plot)1,474,600.00
sum 30➖ (view plot)803,210.00

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

@github-actions github-actions bot temporarily deployed to pull request September 6, 2024 13:08 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 6, 2024 14:04 Inactive
@jneem jneem mentioned this pull request Sep 10, 2024
Copy link

dpulls bot commented Sep 10, 2024

🎉 All dependencies have been resolved !

@yannham
Copy link
Member

yannham commented Sep 10, 2024

@jneem once it's rebased could please tag me, and I'll take a look!

@github-actions github-actions bot temporarily deployed to pull request September 11, 2024 03:11 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 11, 2024 03:23 Inactive
@jneem
Copy link
Member Author

jneem commented Sep 11, 2024

@yannham it's ready for a look

@github-actions github-actions bot temporarily deployed to pull request September 11, 2024 04:01 Inactive
Copy link
Member

@yannham yannham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like where this goes - although it's slightly harder to express than using a simple surface language desugaring, it's still very close (and a reasonable transformation, and a similar semantics). Plus the fact that the errors are now nicer.

core/src/pretty.rs Outdated Show resolved Hide resolved
let attrs = LetAttrs {
binding_type: BindingType::Normal,
rec: false,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think this is the Default implementation of LetAttrs. But if you spell the values out on purpose to be more explicit that's fair too.

core/src/transform/desugar_destructuring.rs Outdated Show resolved Hide resolved
core/src/transform/desugar_destructuring.rs Outdated Show resolved Hide resolved
core/src/transform/desugar_destructuring.rs Show resolved Hide resolved
let attrs = LetAttrs {
binding_type: BindingType::Normal,
rec,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(another Default instance)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has a rec...

Comment on lines 179 to 181
/// The type of each "leaf" identifier will be assigned based on the `mode`
/// argument. The current possibilities are for each leaf to have type
/// `Dyn`, or to be assigned a fresh unification variable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this comment change? Have we changed anything about type annotations in record patterns?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood, but it seemed to me that the code has only two cases (Dyn for TypecheckMode::Walk, and a unification variable for TypecheckMode::Enforce). The previous comment made it sound like there were three cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the third case is something like match x { {foo : Number, bar: String} => ...}, where we take the type from the annotation instead. Or at least so I recall.

@github-actions github-actions bot temporarily deployed to pull request September 12, 2024 01:41 Inactive
@jneem jneem added this pull request to the merge queue Sep 12, 2024
Merged via the queue into master with commit 3663b0a Sep 12, 2024
7 checks passed
@jneem jneem deleted the let-rec-patterns branch September 12, 2024 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants