Skip to content

Commit 79713e0

Browse files
committed
a bit more caching
1 parent 7643aac commit 79713e0

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

python/ql/lib/semmle/python/internal/CachedStages.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ module Stages {
140140
private import semmle.python.Flow as Flow
141141
private import semmle.python.objects.ObjectInternal as ObjectInternal
142142
private import semmle.python.objects.ObjectAPI as ObjectAPI
143+
private import semmle.python.pointsto.PointsTo as PointsTo
143144

144145
/**
145146
* DONT USE!
@@ -166,6 +167,8 @@ module Stages {
166167
exists(any(Flow::ControlFlowNode c).toString())
167168
or
168169
exists(any(ObjectInternal::ObjectInternal o).toString())
170+
or
171+
PointsTo::AttributePointsTo::variableAttributePointsTo(_, _, _, _, _)
169172
}
170173
}
171174

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import semmle.python.pointsto.PointsToContext
66
private import semmle.python.pointsto.MRO
77
private import semmle.python.types.Builtins
88
private import semmle.python.types.Extensions
9+
private import semmle.python.internal.CachedStages
910

1011
/* Use this version for speed */
1112
class CfgOrigin extends @py_object {
@@ -2555,10 +2556,11 @@ module AttributePointsTo {
25552556
f.isLoad() and var.getASourceUse() = f.(AttrNode).getObject(name)
25562557
}
25572558

2558-
pragma[nomagic]
2559+
cached
25592560
predicate variableAttributePointsTo(
25602561
EssaVariable var, Context context, string name, ObjectInternal value, CfgOrigin origin
25612562
) {
2563+
Stages::DataFlow::ref() and
25622564
definitionAttributePointsTo(var.getDefinition(), context, name, value, origin)
25632565
or
25642566
exists(EssaVariable prev |

python/ql/lib/semmle/python/types/Object.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ class Object extends @py_object {
7575
* For more information, see
7676
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
7777
*/
78+
cached
7879
predicate hasLocationInfo(
7980
string filepath, int startline, int startcolumn, int endline, int endcolumn
8081
) {
82+
Stages::DataFlow::ref() and
8183
this.hasOrigin() and
8284
this.getOrigin()
8385
.getLocation()
@@ -95,7 +97,9 @@ class Object extends @py_object {
9597
Builtin asBuiltin() { result = this }
9698

9799
/** Gets a textual representation of this element. */
100+
cached
98101
string toString() {
102+
Stages::DataFlow::ref() and
99103
not this = undefinedVariable() and
100104
not this = unknownValue() and
101105
exists(ClassObject type | type.asBuiltin() = this.asBuiltin().getClass() |

0 commit comments

Comments
 (0)