Python: Improve performance of FileNotClosed query by using an explicit fastTC#19411
Merged
joefarebrother merged 1 commit intogithub:mainfrom Apr 30, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves performance of the FileNotClosed query by replacing the built-in transitive closure calls with an explicit fastTC implementation.
- Replaces getASuccessor* calls with dedicated predicates (cfgGetASuccessorStar and cfgGetASuccessorPlus) using fastTC
- Introduces helper predicates (cfgGetASuccessor, cfgGetASuccessorPlus, cfgGetASuccessorStar) to clearly define control flow transitions
Comments suppressed due to low confidence (1)
python/ql/src/Resources/FileNotAlwaysClosedQuery.qll:67
- [nitpick] Consider adding a brief inline comment to explain the purpose of cfgGetASuccessorPlus and how fastTC improves performance in this context.
pragma[inline] private predicate cfgGetASuccessorPlus(ControlFlowNode src, ControlFlowNode sink) = fastTC(cfgGetASuccessor/2)(src, sink)
| fastTC(cfgGetASuccessor/2)(src, sink) | ||
|
|
||
| pragma[inline] | ||
| private predicate cfgGetASuccessorStar(ControlFlowNode src, ControlFlowNode sink) { |
There was a problem hiding this comment.
[nitpick] It may be helpful to add documentation clarifying the base condition 'src = sink' in cfgGetASuccessorStar to outline its role in implementing the transitive closure.
Suggested change
| private predicate cfgGetASuccessorStar(ControlFlowNode src, ControlFlowNode sink) { | |
| private predicate cfgGetASuccessorStar(ControlFlowNode src, ControlFlowNode sink) { | |
| // Base condition: A node is always reachable from itself, ensuring reflexivity. |
tausbn
approved these changes
Apr 29, 2025
Contributor
tausbn
left a comment
There was a problem hiding this comment.
Looks good to me (assuming the performance test is okay).
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.
Thanks to @nickrolfe and @alexet for help on slack.