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.
Fix #63
Hi,
The problem is described in the referenced issue. I've fixed it by linking nodes doing infinite loops to the dummy exit node. Since the problem comes from an optimisation of Python, I wasn't sure whether indirect infinite loops could occur in the bytecode, so I dealt with that case too, just in case.
Example of an indirect infinite loop (even if I don't know if it's possible to create it except artificially):
If this can't happen, we could simplify the code and just link the nodes that are their only successors (
{node} == cfg.get_successors(node)
) to the dummy exit node.The resulting augmented graph looks like that (to compare with the graph of the issue):
I still wonder whether this is a good solution or not because I saw that there was an assertion that prevents code from being executed when it detects a "while true" loop with no exit node. The difference with this case is that the infinite loop only occurs under certain circumstances because of an if statement. If we block this kind of case with an assertion too, it will prevent testing the other branch of the if statement, so it's not perfect either. I've also noticed that the problem can occur in functions, so to fix the original issue, we would have needed to allow disabling the
if __name__ == "__main__"
as well as certain functions that have "while true" loops to fix that perfectly.So what do you think, I'm not really an expert in this kind of graph but I hope my solution suits you. Don't hesitate if you have any comments or questions.
Have a nice day!