Skip to content

Fix two infinite loops in codegen#1779

Merged
seanyoung merged 2 commits intohyperledger-solang:mainfrom
smoelius:fix-codegen
May 11, 2025
Merged

Fix two infinite loops in codegen#1779
seanyoung merged 2 commits intohyperledger-solang:mainfrom
smoelius:fix-codegen

Conversation

@smoelius
Copy link
Contributor

@smoelius smoelius commented Apr 9, 2025

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:

while let Some(block_no) = blocks_todo.iter().next() {
let block_no = *block_no;

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:

while let Some(block_no) = blocks_todo.iter().next() {
let block_no = *block_no;

In both cases, the problem appears to be that edges are added to the blocks_todo queue unconditionally.

My understanding of these algorithms is that they try to iterate to a fixpoint. Hence, I changed each loop so that:

  • a flag records whether a state change has occurred
  • at the end of each loop iteration, the edge is added to the queue only if the flag is set

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.

Signed-off-by: Samuel Moelius <sam@moeli.us>
Copy link
Contributor

@seanyoung seanyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally makes sense. Thank you very much @smoelius

@seanyoung seanyoung merged commit c6db2ac into hyperledger-solang:main May 11, 2025
15 of 17 checks passed
@smoelius
Copy link
Contributor Author

Thank you, @seanyoung!

@smoelius smoelius deleted the fix-codegen branch May 12, 2025 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants