Fix two infinite loops in codegen#1779
Merged
seanyoung merged 2 commits intohyperledger-solang:mainfrom May 11, 2025
Merged
Conversation
Signed-off-by: Samuel Moelius <sam@moeli.us>
Contributor
Author
|
Thank you, @seanyoung! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes infinite lops in the reaching definitions and dead storage code.
The two added test files are based on ones from Solidity:
If you add
dbg!(block_no)between the next two lines and run Solang on either of the test files, you will find that a block is visited repeatedly:solang/src/codegen/reaching_definitions.rs
Lines 56 to 57 in 279ee91
If you fix that infinite loop and add
dbg!(block_no)between the next two lines, you will again find that a block is visited repeatedly:solang/src/codegen/dead_storage.rs
Lines 109 to 110 in 279ee91
In both cases, the problem appears to be that edges are added to the
blocks_todoqueue unconditionally.My understanding of these algorithms is that they try to iterate to a fixpoint. Hence, I changed each loop so that:
Furthermore, I analyzed each loop to try to determine what constitutes a state change. On this point, I invite scrutiny.
Nits are welcome on anything, though.