Skip to content

Commit 831850f

Browse files
author
Mark Shannon
authored
Merge pull request #1435 from aeyerstaylor/python-points-to-performance
Python: Improve points-to performance on large databases.
2 parents 28741dd + f04bc26 commit 831850f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

python/ql/src/semmle/python/pointsto/PointsTo.qll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ module PointsTo {
170170

171171
cached module PointsToInternal {
172172

173+
pragma[noinline]
174+
cached predicate importCtxPointsTo(ControlFlowNode f, ObjectInternal value, ControlFlowNode origin) {
175+
PointsToInternal::pointsTo(f, any(Context ctx | ctx.isImport()), value, origin)
176+
}
177+
173178
/** INTERNAL -- Use `f.refersTo(value, origin)` instead. */
174179
cached predicate pointsTo(ControlFlowNode f, PointsToContext context, ObjectInternal value, ControlFlowNode origin) {
175180
points_to_candidate(f, context, value, origin) and
@@ -695,7 +700,7 @@ private module InterModulePointsTo {
695700
predicate ofInterestInExports(ModuleObjectInternal mod, string name) {
696701
exists(ImportStarNode imp, ImportStarRefinement def, EssaVariable var |
697702
imp = def.getDefiningNode() and
698-
PointsToInternal::pointsTo(imp.getModule(), any(Context ctx | ctx.isImport()), mod, _) and
703+
PointsToInternal::importCtxPointsTo(imp.getModule(), mod, _) and
699704
var = def.getVariable()
700705
|
701706
if var.isMetaVariable() then (
@@ -878,7 +883,7 @@ module InterProceduralPointsTo {
878883
/** Helper for parameter_points_to */
879884
pragma [noinline]
880885
private predicate default_parameter_points_to(ParameterDefinition def, PointsToContext context, ObjectInternal value, ControlFlowNode origin) {
881-
exists(PointsToContext imp | imp.isImport() | PointsToInternal::pointsTo(def.getDefault(), imp, value, origin)) and
886+
PointsToInternal::importCtxPointsTo(def.getDefault(), value, origin) and
882887
context_for_default_value(def, context)
883888
}
884889

@@ -2198,7 +2203,7 @@ cached module ModuleAttributes {
21982203
private predicate importStarDef(ImportStarRefinement def, EssaVariable input, ModuleObjectInternal mod) {
21992204
exists(ImportStarNode imp |
22002205
def.getVariable().getName() = "$" and imp = def.getDefiningNode() and
2201-
input = def.getInput() and PointsToInternal::pointsTo(imp.getModule(), any(Context ctx | ctx.isImport()), mod, _)
2206+
input = def.getInput() and PointsToInternal::importCtxPointsTo(imp.getModule(), mod, _)
22022207
)
22032208
}
22042209

0 commit comments

Comments
 (0)