Repository navigation
Drop leftover conditions and empty branches from if statements #9024
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
Merged
+231
−89
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Stop emitting bare conditions like `x === null;` and empty `if`/`else` branches. |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Fix negated float comparisons with NaN: `!(x < 0.0)` compiled to `x >= 0.0`, which is `false` for NaN. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
|
||
| import * as Mocha from "mocha"; | ||
| import * as Test_utils from "./test_utils.mjs"; | ||
|
|
||
| function notLt(x, y) { | ||
| return !(x < y); | ||
| } | ||
|
|
||
| function notLe(x, y) { | ||
| return !(x <= y); | ||
| } | ||
|
|
||
| function notGt(x, y) { | ||
| return !(x > y); | ||
| } | ||
|
|
||
| function notGe(x, y) { | ||
| return !(x >= y); | ||
| } | ||
|
|
||
| let log = { | ||
| contents: /* [] */0 | ||
| }; | ||
|
|
||
| function ifNotLt(x) { | ||
| if (!(x < 0.0)) { | ||
| log.contents = {hd: "then", tl: log.contents}; | ||
| } | ||
| return log.contents; | ||
| } | ||
|
|
||
| function condNotLt(x) { | ||
| if (x < 0.0) { | ||
| return "else"; | ||
| } else { | ||
| return "then"; | ||
| } | ||
| } | ||
|
|
||
| Mocha.describe("Negated_float_comparison_test", () => { | ||
| Mocha.test("negated comparisons with NaN", () => { | ||
| let nan = NaN; | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 25, characters 7-14", true, !(nan < 0.0)); | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 26, characters 7-14", true, !(nan <= 0.0)); | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 27, characters 7-14", true, !(nan > 0.0)); | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 28, characters 7-14", true, !(nan >= 0.0)); | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 29, characters 7-14", true, !(0.0 < nan)); | ||
| }); | ||
| Mocha.test("negated comparisons with numbers", () => { | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 32, characters 7-14", false, false); | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 33, characters 7-14", true, true); | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 34, characters 7-14", false, false); | ||
| }); | ||
| Mocha.test("negated comparison as a condition", () => { | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 37, characters 7-14", {hd: "then", tl: /* [] */0}, ifNotLt(NaN)); | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 38, characters 7-14", "then", condNotLt(NaN)); | ||
| Test_utils.eq("File \"negated_float_comparison_test.res\", line 39, characters 7-14", "else", "else"); | ||
| }); | ||
| }); | ||
|
|
||
| export { | ||
| notLt, | ||
| notLe, | ||
| notGt, | ||
| notGe, | ||
| log, | ||
| ifNotLt, | ||
| condNotLt, | ||
| } | ||
| /* Not a pure module */ |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| open Mocha | ||
| open Test_utils | ||
|
|
||
| // Negating a float comparison must not flip its operator: for NaN, | ||
| // !(x < y) is true while x >= y is false. | ||
| let notLt = (x: float, y: float) => !(x < y) | ||
| let notLe = (x: float, y: float) => !(x <= y) | ||
| let notGt = (x: float, y: float) => !(x > y) | ||
| let notGe = (x: float, y: float) => !(x >= y) | ||
|
|
||
| let log = ref(list{}) | ||
|
|
||
| let ifNotLt = (x: float) => { | ||
| if !(x < 0.0) { | ||
| log := list{"then", ...log.contents} | ||
| } | ||
| log.contents | ||
| } | ||
|
|
||
| let condNotLt = (x: float) => !(x < 0.0) ? "then" : "else" | ||
|
|
||
| describe(__MODULE__, () => { | ||
| test("negated comparisons with NaN", () => { | ||
| let nan = Float.Constants.nan | ||
| eq(__LOC__, true, notLt(nan, 0.0)) | ||
| eq(__LOC__, true, notLe(nan, 0.0)) | ||
| eq(__LOC__, true, notGt(nan, 0.0)) | ||
| eq(__LOC__, true, notGe(nan, 0.0)) | ||
| eq(__LOC__, true, notLt(0.0, nan)) | ||
| }) | ||
| test("negated comparisons with numbers", () => { | ||
| eq(__LOC__, false, notLt(-1.0, 0.0)) | ||
| eq(__LOC__, true, notLt(1.0, 0.0)) | ||
| eq(__LOC__, false, notGe(1.0, 0.0)) | ||
| }) | ||
| test("negated comparison as a condition", () => { | ||
| eq(__LOC__, list{"then"}, ifNotLt(Float.Constants.nan)) | ||
| eq(__LOC__, "then", condNotLt(Float.Constants.nan)) | ||
| eq(__LOC__, "else", condNotLt(-1.0)) | ||
| }) | ||
| }) |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.