-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Python: Move ControlFlowNode, Expr, and Module points-to to legacy module
#20722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Python: Move ControlFlowNode, Expr, and Module points-to to legacy module
#20722
Conversation
| not exists(ExprWithPointsTo left, ExprWithPointsTo right, Value val | | ||
| comp.compares(left, op, right) and | ||
| exists(ImmutableLiteral il | il.getLiteralValue() = val) | ||
| exists(ImmutableLiteral il | il = val.(ConstantObjectInternal).getLiteral()) |
Check warning
Code scanning / CodeQL
Expression can be replaced with a cast Warning
Moves the existing points-to predicates to the newly added class `ControlFlowNodeWithPointsTo` which resides in the `LegacyPointsTo` module. (Existing code that uses these predicates should import this module, and references to `ControlFlowNode` should be changed to `ControlFlowNodeWithPointsTo`.) Also updates all existing points-to based code to do just this.
This had only two uses in our libraries, so I simply inlined the predicate body in both places.
b2c9e72 to
d7a6b3f
Compare
d7a6b3f to
820d8e7
Compare
I wasn't entirely sure if this should be classified as `deprecated` or `breaking`, but seeing as these changes technically _could_ break existing queries (requiring a small rewrite), I opted for the latter.
ControlFlowNode, Expr, and Module points-to to legacy module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request removes points-to analysis predicates from ControlFlowNode, Expr, and Module classes, moving them to a new LegacyPointsTo module. This change enforces explicit opt-in to legacy points-to functionality by requiring imports of LegacyPointsTo and use of specialized wrapper classes (ControlFlowNodeWithPointsTo, ExprWithPointsTo, ModuleWithPointsTo).
Key changes:
- Created
LegacyPointsTo.qllmodule with wrapper classes for accessing points-to predicates - Removed points-to predicates from
ControlFlowNode,Expr, andModulebase classes - Updated all existing usages across test files, library files, and queries to use the new wrapper classes
Reviewed Changes
Copilot reviewed 107 out of 107 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
python/ql/lib/LegacyPointsTo.qll |
New module defining ControlFlowNodeWithPointsTo, ExprWithPointsTo, and ModuleWithPointsTo wrapper classes |
python/ql/lib/semmle/python/Flow.qll |
Removed points-to predicates from ControlFlowNode class |
python/ql/lib/semmle/python/Exprs.qll |
Removed points-to predicates from Expr class |
python/ql/lib/semmle/python/Module.qll |
Removed getAnExport() predicate from Module class |
| Test and library files (80+ files) | Added LegacyPointsTo imports and casts to wrapper classes where points-to predicates are used |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Should be reviewed commit-by-commit!
This is the first step towards hiding all of the existing hooks into the points-to API behind an explicit
LegacyPointsTomodule.This PR in particular removes all ways to access points-to from
ControlFlowNode,Expr, andModule.The approach taken is roughly the same in each case: for each points-to-related predicate on, say,
Expr, we transfer it to a subclass calledExprWithPointsTothat lives inside theLegacyPointsTomodule. All existing uses of these predicates must then be updated to refer toExprWithPointsToinstead, either by updating the type (in the case of a bound variable), or by inserting an inline cast to this class.Note that for some of these classes we additionally override
getAQlClassto not return any values. This is because a few tests were failing because they were seeing new (though really just duplicated) results forExprWithPointsToandModuleWithPointsTo. Simply making the methods empty for these classes seemed like the easiest solution.Finally, to head off a potential question:
LegacyPointsto.qllat the top level?It may seem a bit ugly to place this alongside
python.qllin this otherwise (mostly) pristine spot in the module hierarchy, but I think this could be construed as a feature. It is an ugly wart, and having it present front and centre might encourage us to actually do something about this fact. 😈