Skip to content

Commit 9e95f6e

Browse files
authored
Python: Remove typePreservingStep
This requires a bit of explanation, so strap in. Firstly, because we use `LocalSourceNode`s as the start and end points of our `StepSummary::step` relation, there's no need to include `simpleLocalFlowStep` (via `typePreservingStep`) in `smallstep`. Indeed, since the successor node for a `step` is a `LocalSourceNode`, and local sources never have incoming flow, this is entirely futile -- we can find values for `mid` and `nodeTo` that satisfy the body of `step`, but `nodeTo` will never be a `LocalSourceNode`. With this in mind, we can simplify `smallstep` to only refer to `jumpStep`. This then brings the other uses of `typePreservingStep` into question. The only other place we use this predicate is in the `TypeTracker` and `TypeBackTracker` `smallstep` predicates. Note, however, that here we no longer need `jumpStep` to be part of `typeTrackingStep` (as it is already accounted for in `StepSummary::smallstep`) so we can simplify to `simpleLocalFlowStep`. At this point, `typePreservingStep` is unused. Finally, because of the way `smallstep` is used in `step` (inside `StepSummary`), `nodeTo` must always be a `LocalSourceNode`, so I have propagated this restriction to `smallstep` as well. We can always lift this restriction later, but for now it seems like it's likely to cause fewer surprises to have made this explicit.
1 parent 7cdf439 commit 9e95f6e

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

python/ql/src/experimental/typetracking/TypeTracker.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ module StepSummary {
7171
* Unlike `StepSummary::step`, this predicate does not compress
7272
* type-preserving steps.
7373
*/
74-
predicate smallstep(Node nodeFrom, Node nodeTo, StepSummary summary) {
75-
typePreservingStep(nodeFrom, nodeTo) and
74+
predicate smallstep(Node nodeFrom, LocalSourceNode nodeTo, StepSummary summary) {
75+
jumpStep(nodeFrom, nodeTo) and
7676
summary = LevelStep()
7777
or
7878
callStep(nodeFrom, nodeTo) and summary = CallStep()
@@ -225,7 +225,7 @@ class TypeTracker extends TTypeTracker {
225225
* heap and/or inter-procedural step from `nodeFrom` to `nodeTo`.
226226
*/
227227
pragma[inline]
228-
TypeTracker step(LocalSourceNode nodeFrom, Node nodeTo) {
228+
TypeTracker step(LocalSourceNode nodeFrom, LocalSourceNode nodeTo) {
229229
exists(StepSummary summary |
230230
StepSummary::step(nodeFrom, nodeTo, summary) and
231231
result = this.append(summary)
@@ -263,7 +263,7 @@ class TypeTracker extends TTypeTracker {
263263
result = this.append(summary)
264264
)
265265
or
266-
typePreservingStep(nodeFrom, nodeTo) and
266+
simpleLocalFlowStep(nodeFrom, nodeTo) and
267267
result = this
268268
}
269269
}
@@ -406,7 +406,7 @@ class TypeBackTracker extends TTypeBackTracker {
406406
this = result.prepend(summary)
407407
)
408408
or
409-
typePreservingStep(nodeFrom, nodeTo) and
409+
simpleLocalFlowStep(nodeFrom, nodeTo) and
410410
this = result
411411
}
412412
}

python/ql/src/experimental/typetracking/TypeTrackerPrivate.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ class Node = DataFlowPublic::Node;
66

77
class LocalSourceNode = DataFlowPublic::LocalSourceNode;
88

9-
/** Holds if it's reasonable to expect the data flow step from `nodeFrom` to `nodeTo` to preserve types. */
10-
predicate typePreservingStep(Node nodeFrom, Node nodeTo) {
11-
DataFlowPrivate::simpleLocalFlowStep(nodeFrom, nodeTo) or
12-
DataFlowPrivate::jumpStep(nodeFrom, nodeTo)
13-
}
9+
predicate simpleLocalFlowStep = DataFlowPrivate::simpleLocalFlowStep/2;
10+
11+
predicate jumpStep = DataFlowPrivate::jumpStep/2;
1412

1513
/**
1614
* Gets the name of a possible piece of content. For Python, this is currently only attribute names,

0 commit comments

Comments
 (0)