-
Notifications
You must be signed in to change notification settings - Fork 471
Heuristic for pattern matching untagged variants. #7128
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
Changes from 1 commit
c825694
693fedf
fc6f9e9
6913da9
b12f189
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
|
||
|
|
||
| function f(x) { | ||
| if (x !== null) { | ||
| return; | ||
| } | ||
| console.log("abc"); | ||
| } | ||
|
|
||
| function ff(x) { | ||
| if (x === "G" || x === "F" || x === "E" || x === "D" || x === "C" || x === "B" || x === "A") { | ||
|
||
| return; | ||
| } | ||
| console.log("abc"); | ||
| } | ||
|
|
||
| export { | ||
| f, | ||
| ff, | ||
| } | ||
| /* No side effect */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| let f = (x: JSON.t) => | ||
| switch x { | ||
| | Null => Console.log("abc") | ||
| | _ => () | ||
| } | ||
|
|
||
| @unboxed | ||
| type t = | ||
| | A | ||
| | B | ||
| | C | ||
| | D | ||
| | E | ||
| | F | ||
| | G | ||
| | Int(int) | ||
|
|
||
| let ff = (x: t) => | ||
| switch x { | ||
| | Int(_) => Console.log("abc") | ||
| | _ => () | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cristianoc Thanks a lot for looking into this so quickly!
Most cases look better now. But this one still feels a bit weird as the lhs of the && is obviously unnecessary.
Is it possible to improve it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and it's not related to this PR.
You're asking for a back end code simplification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, then I think this PR is ready to go and we can track the above case in a different issue. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_literal_cases:
without_literal_cases:
So it is true that it generates the smaller expression (the former).
The second one must be simplified in the back-end, and not the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added extra simplification directly to this PR.