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

Case expression exhaustiveness & redundancy checking #1114

Merged
merged 170 commits into from
May 19, 2024

Conversation

pigumar1
Copy link
Contributor

@pigumar1 pigumar1 commented Sep 20, 2023

This pull request aims to implement the exhaustiveness checking feature mentioned in Live Pattern Matching with Typed Holes.

If a case expression is necessarily inexhaustive (i.e.: the expression will necessarily fail to match all values of the type of its scrutinee), the expression will be wrapped with an error hole like in Fig. 2b in the paper. This is planned to be done by introducing a new error_exp called InexhaustiveMatch (tentative), which behaves uniquely when supplied to CursorInspector.re. Like discussed in #1059, we probably need a corresponding Self.exp for the new expression error. Self.match() might be modified accordingly.

Exhaustiveness checking on a case expression relies on whether the final constraint for the rules can be entailed from truth (i.e.: all expressions of the type of the case expression’s scrutinee “determinately or indeterminately match any of the branches”). This final constraint for the rules is discovered in the process of typing the rules of the match expression, which is to be implemented by applying the sequence of rules to a type generator called ruls_to_info_map (tentative). It corresponds to the judgment TRules in the paper (ideally). ruls_to_info_map is going to be based on the list scheme List.fold_left instead of List.map since the info of rules will be dependent on each other in the redundancy checking.

The entailment check itself has already been implemented in #1094 as the function Incon.is_exhaustive.

After checking the exhaustiveness, the branches are yet to be checked for type consistency (should they be in sequential order? Or should two errors show up in the cursor inspector at the same time?) So the output of ruls_to_info_map probably contains a list of expression types for branches and the final constraint for the rules.

(Karan Anand got involved in editing the proposal)

DavidFangWJ and others added 30 commits July 9, 2023 21:54
# Conflicts:
#	INSTALL.md
#	src/haz3lcore/dynamics/Builtins.re
#	src/haz3lcore/dynamics/Builtins.rei
#	src/haz3lcore/dynamics/DH.re
#	src/haz3lcore/dynamics/Elaborator.re
#	src/haz3lcore/dynamics/Evaluator.re
#	src/haz3lcore/dynamics/EvaluatorPost.re
#	src/haz3lcore/dynamics/InvalidOperationError.rei
#	src/haz3lcore/lang/Form.re
#	src/haz3lcore/statics/Ctx.re
#	src/haz3lcore/statics/Info.re
#	src/haz3lcore/statics/MakeTerm.re
#	src/haz3lcore/statics/Mode.re
#	src/haz3lcore/statics/Self.re
#	src/haz3lcore/statics/Statics.re
#	src/haz3lcore/statics/Term.re
#	src/haz3lcore/statics/Typ.re
#	src/haz3lcore/statics/TypBase.re
#	src/haz3lcore/tiles/Segment.re
#	src/haz3lweb/Init.ml
#	src/haz3lweb/Keyboard.re
#	src/haz3lweb/Log.re
#	src/haz3lweb/Store.re
#	src/haz3lweb/Update.re
#	src/haz3lweb/UpdateAction.re
#	src/haz3lweb/view/CtxInspector.re
#	src/haz3lweb/view/CursorInspector.re
#	src/haz3lweb/view/EditorModeView.re
#	src/haz3lweb/view/ScratchMode.re
#	src/haz3lweb/view/Type.re
#	src/haz3lweb/view/dhcode/DHCode.re
#	src/haz3lweb/www/style.css
@pigumar1 pigumar1 requested a review from cyrus- April 14, 2024 20:31
@pigumar1 pigumar1 marked this pull request as ready for review May 5, 2024 20:45
id: Id.t,
typ: Typ.t,
/* Temporary variables. Better implementation is a TO-DO. */
nth: int,
Copy link
Member

Choose a reason for hiding this comment

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

same here

@pigumar1 pigumar1 requested a review from cyrus- May 14, 2024 18:02
@cyrus- cyrus- merged commit 3511a3b into dev May 19, 2024
2 checks passed
@cyrus- cyrus- deleted the haz3l-case-exhaustiveness branch May 19, 2024 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-polish for PRs that are substantially complete but need final polish
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants