Repository navigation
Fix inlining copying a record literal to each use #9493
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5482bf5
Fix inlining copying a record literal to each use
cknitt bf8b52d
Repeat a nested none argument of an inlined function
cknitt d4edf3f
Add Lambda unit tests for constant arguments and switches
cknitt 0682c69
Give the right reason why repeating a nested none is safe
cknitt 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 @@ | ||
| - Fix inlining that built a record, tuple or option literal argument again at each use of the parameter. |
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
48 changes: 9 additions & 39 deletions
48
tests/compiler_tests/src/inline_condition_with_pattern_matching.mjs
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 |
|---|---|---|
| @@ -1,61 +1,31 @@ | ||
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
|
||
|
|
||
| let person1 = { | ||
| let Test1_person1 = { | ||
| TAG: "Teacher", | ||
| age: 12345 | ||
| }; | ||
|
|
||
| let message; | ||
|
|
||
| if (person1.TAG === "Teacher") { | ||
| message = "b"; | ||
| } else { | ||
| let tmp = 12345; | ||
| message = typeof tmp !== "object" || tmp.TAG === "Vacations" ? "a" : "b"; | ||
| } | ||
|
|
||
| let Test1 = { | ||
| person1: person1, | ||
| message: message | ||
| person1: Test1_person1, | ||
| message: "b" | ||
| }; | ||
|
|
||
| let person2 = { | ||
| let message = `Hello Jane.`; | ||
|
|
||
| let Test2_person2 = { | ||
| TAG: "Teacher", | ||
| name: "Jane", | ||
| age: 12345 | ||
| }; | ||
|
|
||
| let message$1; | ||
|
|
||
| if (person2.TAG === "Teacher") { | ||
| message$1 = `Hello Jane.`; | ||
| } else { | ||
| let name = "Jane"; | ||
| let match = person2.reportCard; | ||
| if (match.passing) { | ||
| message$1 = `Congrats ${name}, nice GPA of ${match.gpa.toString()} you got there!`; | ||
| } else { | ||
| let exit = 0; | ||
| let tmp$1 = 12345; | ||
| if (typeof tmp$1 !== "object") { | ||
| message$1 = tmp$1 === "Sick" ? `How are you feeling?` : `Good luck next semester ${name}!`; | ||
| } else { | ||
| exit = 1; | ||
| } | ||
| if (exit === 1) { | ||
| message$1 = person2.reportCard.gpa !== 0.0 ? `Good luck next semester ${name}!` : `Come back in ${(12345)._0.toString()} days!`; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let Test2 = { | ||
| person2: person2, | ||
| message: message$1 | ||
| person2: Test2_person2, | ||
| message: message | ||
| }; | ||
|
|
||
| export { | ||
| Test1, | ||
| Test2, | ||
| } | ||
| /* message Not a pure module */ | ||
| /* No side effect */ |
53 changes: 53 additions & 0 deletions
53
tests/compiler_tests/src/inline_literal_arg_identity_test.mjs
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,53 @@ | ||
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
|
||
| import * as Mocha from "mocha"; | ||
| import * as Test_utils from "./test_utils.mjs"; | ||
|
|
||
| function same(b) { | ||
| return b === b; | ||
| } | ||
|
|
||
| function samePair(p) { | ||
| return p === p; | ||
| } | ||
|
|
||
| function sameOption(o) { | ||
| return o === o; | ||
| } | ||
|
|
||
| function sum(b) { | ||
| return b.x + b.y | 0; | ||
| } | ||
|
|
||
| Mocha.describe("Inline_literal_arg_identity_test", () => { | ||
| Mocha.test("a record literal", () => { | ||
| let b = { | ||
| x: 1, | ||
| y: 2 | ||
| }; | ||
| Test_utils.ok("File \"inline_literal_arg_identity_test.res\", line 22, characters 36-43", b === b); | ||
| }); | ||
| Mocha.test("a tuple literal", () => { | ||
| let p = [ | ||
| 1, | ||
| 2 | ||
| ]; | ||
| Test_utils.ok("File \"inline_literal_arg_identity_test.res\", line 23, characters 35-42", p === p); | ||
| }); | ||
| Mocha.test("an option of a record literal", () => { | ||
| let o = { | ||
| x: 1, | ||
| y: 2 | ||
| }; | ||
| Test_utils.ok("File \"inline_literal_arg_identity_test.res\", line 24, characters 49-56", o === o); | ||
| }); | ||
| Mocha.test("fields of a record literal", () => Test_utils.eq("File \"inline_literal_arg_identity_test.res\", line 25, characters 46-53", 3, 3)); | ||
| }); | ||
|
|
||
| export { | ||
| same, | ||
| samePair, | ||
| sameOption, | ||
| sum, | ||
| } | ||
| /* Not a pure module */ |
26 changes: 26 additions & 0 deletions
26
tests/compiler_tests/src/inline_literal_arg_identity_test.res
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,26 @@ | ||
| open Mocha | ||
| open Test_utils | ||
|
|
||
| // An inlined function reads a literal argument as one value: the literal is | ||
| // built once, not at each use of the parameter. | ||
|
|
||
| type xy = {x: int, y: int} | ||
|
|
||
| @inline | ||
| let same = (b: xy) => b === b | ||
|
|
||
| @inline | ||
| let samePair = (p: (int, int)) => p === p | ||
|
|
||
| @inline | ||
| let sameOption = (o: option<xy>) => o === o | ||
|
|
||
| @inline | ||
| let sum = (b: xy) => b.x + b.y | ||
|
|
||
| describe(__MODULE__, () => { | ||
| test("a record literal", () => ok(__LOC__, same({x: 1, y: 2}))) | ||
| test("a tuple literal", () => ok(__LOC__, samePair((1, 2)))) | ||
| test("an option of a record literal", () => ok(__LOC__, sameOption(Some({x: 1, y: 2})))) | ||
| test("fields of a record literal", () => eq(__LOC__, sum({x: 1, y: 2}), 3)) | ||
| }) |
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
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.