Open jjcnn opened 2 weeks ago
Comparing jjcnn/return_path_analysis_exit_fix
(8a777e9) with master
(7b07216)
⚡ 1
improvements
✅ 21
untouched benchmarks
Benchmark | master |
jjcnn/return_path_analysis_exit_fix |
Change | |
---|---|---|---|---|
⚡ | document_symbol |
5.2 ms | 4.3 ms | +20.82% |
Can we test this to validate some previously unhandled state at least?
I haven't been able to find an example where the old algorithm gave an incorrect result. I can keep looking if you want?
When I removed the rovers[0] != exit_point
check I got an error in this test case (as well as in a number of others):
That's the one I used to debug my algorithm.
Description
The return path analysis ensures that if a method must return a value then every path through a method returns a value. The analysis traverses the CFG of each method in a breadth-first manner from the (unique) entry point to the (unique) exit point. If there is ever a node in the graph that does not have outgoing edges, then an error is thrown.
So far the condition in the outer loop has been
!rovers.is_empty() && rovers[0] != exit_point
, whererovers
is the current set of nodes to be analyzed. The requirementrovers[0] != exit_point
potentially causes part of the CFG to not be traversed, but appears to have been added because of cases like the following:The CFG for
main
contains the CFG foreq
as a subgraph, but since the exit point foreq
does not have a path leading to the exit point ofmain
the analysis throws an error when the condition is removed. (It is not clear to me why this is, but based on my testing it happens consistently).This is clearly incorrect behavior since the edge leading into the
eq
CFG does not represent control flow.To solve this problem I have introduced a condition in the inner loop in which a node is ignored if it has been visited before, or if it represents a method declaration that is different from the entry point of the method currently under analysis.
Additionally I have changed the representation of
visited
to be aHashSet
instead of a vector. This should improve performance slightly.I have not been able to find a test program that causes the original algorithm to allow illegal programs to pass, but the new algorithm seems more obviously correct.
Checklist
Breaking*
orNew Feature
labels where relevant.