-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Minor rewording of module documentation * Basics of pattern compilation This PR implements core functions to compile patterns and match expressions to simpler Nickel code that doesn't use patterns at all. This is a step toward allowing general pattern in match expressions. For now, this new implementation isn't actually used yet as it lacks a couple new primitive operations to work properly. The implementation also ignores contracts annotation in the pattern. * Add %field_is_defined% To safely check if a pattern matches a value (safely meaning without throwing an uncatchable error), we need a primitive operation to check if we can safely access the field of a record. To do so, we need the field to exists _and_ to have a definition. This is what the added `field_is_defined` checks. * Update pattern compilation to use field_is_defined * Use new with_env primop for pattern compilation * Add non exhaustive match error As match expressions are going to handle more general patterns, the existing NonExhaustiveMatch error - which was in fact specialized for enums - is renamed to NonExhaustiveMatchEnum, and the previous name is reused for a more general errors which doesn't assume that the pattern or the matched value are enums. * Fix bugs in pattern compil. and associated primops * Correctly handle record pattern tail The partial implementation of record pattern compilation didn't handle the record pattern tail yet: for example, a closed pattern `{foo, bar}` would match a larger record `{foo=1, bar=2, baz=3}`. This commit additionally keeps the current rest of the record being matched, that is the original record minus all the matched fields, to either check that it is empty at the end (closed pattern), or to bind this rest to an identifier if the pattern captures the rest with `{foo, bar, ..rest}`. * Fix record pattern compilation After doing some experimentation, fix a number of bugs observed in the compilation of record patterns: wrong order of arguments, wrong identifiers used, clash of the special rest field between patterns and sub-patterns, and so on. * with_env -> pattern_branch Rename the `with_env` primop to `pattern_branch` in order to avoid confusion about its scope and usage: this shouldn't be used as a general environment augmentation operation, although it kinda is, because of existing footguns. * pattern.rs -> pattern/mod.rs * split compile mod from pattern mod in its own file * Fix clippy and rustdoc warnings, remove unneeded code * Implement reviewer suggestions Co-authored-by: jneem <[email protected]> --------- Co-authored-by: jneem <[email protected]>
- Loading branch information
Showing
9 changed files
with
626 additions
and
6 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
Oops, something went wrong.