-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Fix couple of bugs in handling returns in if blocks #2029
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
12 commits
Select commit
Hold shift + click to select a range
f0966bc
Fix couple of bugs in handling returns in if blocks
vaivaswatha 7586b4e
More fixes
vaivaswatha f0a910b
Finally something works
vaivaswatha 05408aa
Add test
vaivaswatha 0793e33
Merge branch 'master' into vaivaswtha/issue1663
vaivaswatha 024209f
Add if-let tests too
vaivaswatha 92c3bd5
DeterministicallyAborts: Optionally, don't go inside a callee
vaivaswatha b63baba
Remove Constant::eq which isn't used
vaivaswatha 4a4c6e3
Merge branch 'master' into vaivaswtha/issue1663
vaivaswatha e5559a5
Revert "DeterministicallyAborts: Optionally, don't go inside a callee"
vaivaswatha 84852d0
Do not use deterministically_aborts in IRGen
vaivaswatha 1a9a16b
Update sway-ir/src/block.rs
vaivaswatha 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
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
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_pass/language/impure_ifs/Forc.lock
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,14 @@ | ||
| [[package]] | ||
| name = 'const_inits' | ||
| source = 'root' | ||
| dependencies = ['std'] | ||
|
|
||
| [[package]] | ||
| name = 'core' | ||
| source = 'path+from-root-76FD265A93458D61' | ||
| dependencies = [] | ||
|
|
||
| [[package]] | ||
| name = 'std' | ||
| source = 'path+from-root-76FD265A93458D61' | ||
| dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/language/impure_ifs/Forc.toml
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,8 @@ | ||
| [project] | ||
| authors = ["Fuel Labs <[email protected]>"] | ||
| entry = "main.sw" | ||
| license = "Apache-2.0" | ||
| name = "const_inits" | ||
|
|
||
| [dependencies] | ||
| std = { path = "../../../../../../../sway-lib-std" } |
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_pass/language/impure_ifs/json_abi_oracle.json
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,14 @@ | ||
| [ | ||
| { | ||
| "inputs": [], | ||
| "name": "main", | ||
| "outputs": [ | ||
| { | ||
| "components": null, | ||
| "name": "", | ||
| "type": "u64" | ||
| } | ||
| ], | ||
| "type": "function" | ||
| } | ||
| ] |
90 changes: 90 additions & 0 deletions
90
test/src/e2e_vm_tests/test_programs/should_pass/language/impure_ifs/src/main.sw
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,90 @@ | ||
| script; | ||
|
|
||
| use std::{assert::assert, logging::log}; | ||
|
|
||
| enum Bool { | ||
| True: (), | ||
| False: (), | ||
| } | ||
|
|
||
| fn foo(b: bool) -> u64 { | ||
| if b { | ||
| 101 | ||
| } else { | ||
| 102 | ||
| } | ||
| } | ||
|
|
||
| fn bar(b: bool) -> u64 { | ||
| if b { | ||
| return 101; | ||
| } else { | ||
| return 102; | ||
| } | ||
| } | ||
|
|
||
| fn bell(b: bool) -> u64 { | ||
| if b { | ||
| return 101; | ||
| } else { | ||
| 102 | ||
| } | ||
| } | ||
|
|
||
| fn moo(b: bool) -> u64 { | ||
| if b { | ||
| 101 | ||
| } else { | ||
| return 102; | ||
| } | ||
| } | ||
|
|
||
| fn poo(b: Bool) -> u64 { | ||
| if let Bool::True = b { | ||
| 101 | ||
| } else { | ||
| return 102; | ||
| } | ||
| } | ||
|
|
||
| fn ran_out_of_names(b: Bool) -> u64 { | ||
| if let Bool::True = b { | ||
| return 101; | ||
| } else { | ||
| return 102; | ||
| } | ||
| } | ||
|
|
||
| fn another_fn(b: Bool) -> u64 { | ||
| if let Bool::True = b { | ||
| return 101; | ||
| } else { | ||
| 102 | ||
| } | ||
| } | ||
|
|
||
| fn thats_all(b: Bool) -> u64 { | ||
| if let Bool::True = b { | ||
| 101 | ||
| } else { | ||
| 102 | ||
| } | ||
| } | ||
|
|
||
| fn main() -> u64 { | ||
| assert(foo(true) == bar(true)); | ||
| assert(foo(false) == bar(false)); | ||
| assert(foo(true) == bell(true)); | ||
| assert(foo(false) == bell(false)); | ||
| assert(foo(true) == moo(true)); | ||
| assert(foo(false) == moo(false)); | ||
|
|
||
| assert(thats_all(Bool::True) == poo(Bool::True)); | ||
| assert(thats_all(Bool::False) == poo(Bool::False)); | ||
| assert(thats_all(Bool::True) == ran_out_of_names(Bool::True)); | ||
| assert(thats_all(Bool::False) == ran_out_of_names(Bool::False)); | ||
| assert(thats_all(Bool::True) == another_fn(Bool::True)); | ||
| assert(thats_all(Bool::False) == another_fn(Bool::False)); | ||
|
|
||
| 2 | ||
| } | ||
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.
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.
Nice change! Thanks.
Do you mind also adding a test case with
if letlike the one in the linked 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.
Done. But there's a failure in one of the vec tests. Let me try and debug that.