forked from tweag/nickel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uniformize destruct and pattern matching logic (tweag#1907)
* Uniformize destruct and pattern matching logic When patterns were first introduced, only let-destructuring existed, and match expressions weren't a thing. Rather than to manually generate code that would check that a pattern does match the destructured value, we piggy-backed on contracts instead, which was easier and provided better error messages. Up to now, this was still how destructuring worked: a contract is elaborated from the pattern and applied to the matched value, and should report any error if the value doesn't match. Then, destructuring is desugared to a series of let-bindings that assume that the destucture value has the right shape. The generated code is thus quite simple, as it doesn't have any error handling to do. When pattern matching landed, we kept the old destructuring infrastructure, because it was there and worked well. However, there is duplication: the compilation of match expressions does a work quite similar to destructuring. What's more, we're at risk of having a diverging semantics. Some questions aren't trivial to answer for destructuring, in particular with respect to lazyness: should `let _ = x in null` force `x`? What about `let 'Foo _ = x in null`, or `let 'Foo 5 = x in null`? After some discussion, we decided to give destructuring a simple semantics in term of pattern matching: `let <pat> = <matched> in <body>` should be strictly equivalent to `<matched> |> match { <pat> => <body> }`. Indeed, `match` has a clear semantics around forcing values in lazy languages. This also agrees with intuition, or at least gives a reasonable semantics for most cases. This commit implements this change in practice, by getting rid of the ad-hoc desugaring of destructuring and rewriting let-destructuring to actual pattern matching instead. * Update core/src/term/pattern/compile.rs Co-authored-by: jneem <[email protected]> --------- Co-authored-by: jneem <[email protected]>
- Loading branch information
Showing
22 changed files
with
97 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.