Skip to content

Commit fa92e79

Browse files
committed
Ruby/Python: Use inline_late on member predicates
1 parent 56a5a57 commit fa92e79

File tree

3 files changed

+88
-115
lines changed

3 files changed

+88
-115
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/TypeTracker.qll

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,6 @@ private predicate stepProj(TypeTrackingNode nodeFrom, StepSummary summary) {
235235
step(nodeFrom, _, summary)
236236
}
237237

238-
bindingset[nodeFrom, t]
239-
pragma[inline_late]
240-
pragma[noopt]
241-
private TypeTracker stepInlineLate(TypeTracker t, TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
242-
exists(StepSummary summary |
243-
stepProj(nodeFrom, summary) and
244-
result = t.append(summary) and
245-
step(nodeFrom, nodeTo, summary)
246-
)
247-
}
248-
249238
private predicate smallstep(Node nodeFrom, TypeTrackingNode nodeTo, StepSummary summary) {
250239
smallstepNoCall(nodeFrom, nodeTo, summary)
251240
or
@@ -257,17 +246,6 @@ private predicate smallstepProj(Node nodeFrom, StepSummary summary) {
257246
smallstep(nodeFrom, _, summary)
258247
}
259248

260-
bindingset[nodeFrom, t]
261-
pragma[inline_late]
262-
pragma[noopt]
263-
private TypeTracker smallstepInlineLate(TypeTracker t, Node nodeFrom, Node nodeTo) {
264-
exists(StepSummary summary |
265-
smallstepProj(nodeFrom, summary) and
266-
result = t.append(summary) and
267-
smallstep(nodeFrom, nodeTo, summary)
268-
)
269-
}
270-
271249
/**
272250
* Holds if `nodeFrom` is being written to the `content` of the object in `nodeTo`.
273251
*
@@ -501,9 +479,26 @@ class TypeTracker extends TTypeTracker {
501479
* Gets the summary that corresponds to having taken a forwards
502480
* heap and/or inter-procedural step from `nodeFrom` to `nodeTo`.
503481
*/
504-
pragma[inline]
482+
bindingset[nodeFrom, this]
483+
pragma[inline_late]
484+
pragma[noopt]
505485
TypeTracker step(TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
506-
result = stepInlineLate(this, nodeFrom, nodeTo)
486+
exists(StepSummary summary |
487+
stepProj(nodeFrom, summary) and
488+
result = this.append(summary) and
489+
step(nodeFrom, nodeTo, summary)
490+
)
491+
}
492+
493+
bindingset[nodeFrom, this]
494+
pragma[inline_late]
495+
pragma[noopt]
496+
private TypeTracker smallstepNoSimpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
497+
exists(StepSummary summary |
498+
smallstepProj(nodeFrom, summary) and
499+
result = this.append(summary) and
500+
smallstep(nodeFrom, nodeTo, summary)
501+
)
507502
}
508503

509504
/**
@@ -532,7 +527,7 @@ class TypeTracker extends TTypeTracker {
532527
*/
533528
pragma[inline]
534529
TypeTracker smallstep(Node nodeFrom, Node nodeTo) {
535-
result = smallstepInlineLate(this, nodeFrom, nodeTo)
530+
result = this.smallstepNoSimpleLocalFlowStep(nodeFrom, nodeTo)
536531
or
537532
simpleLocalFlowStep(nodeFrom, nodeTo) and
538533
result = this
@@ -552,34 +547,10 @@ private predicate backStepProj(TypeTrackingNode nodeTo, StepSummary summary) {
552547
step(_, nodeTo, summary)
553548
}
554549

555-
bindingset[nodeTo, t]
556-
pragma[inline_late]
557-
pragma[noopt]
558-
private TypeBackTracker backStepInlineLate(
559-
TypeBackTracker t, TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo
560-
) {
561-
exists(StepSummary summary |
562-
backStepProj(nodeTo, summary) and
563-
result = t.prepend(summary) and
564-
step(nodeFrom, nodeTo, summary)
565-
)
566-
}
567-
568550
private predicate backSmallstepProj(TypeTrackingNode nodeTo, StepSummary summary) {
569551
smallstep(_, nodeTo, summary)
570552
}
571553

572-
bindingset[nodeTo, t]
573-
pragma[inline_late]
574-
pragma[noopt]
575-
private TypeBackTracker backSmallstepInlineLate(TypeBackTracker t, Node nodeFrom, Node nodeTo) {
576-
exists(StepSummary summary |
577-
backSmallstepProj(nodeTo, summary) and
578-
result = t.prepend(summary) and
579-
smallstep(nodeFrom, nodeTo, summary)
580-
)
581-
}
582-
583554
/**
584555
* A summary of the steps needed to back-track a use of a value to a given dataflow node.
585556
*
@@ -661,9 +632,26 @@ class TypeBackTracker extends TTypeBackTracker {
661632
* Gets the summary that corresponds to having taken a backwards
662633
* heap and/or inter-procedural step from `nodeTo` to `nodeFrom`.
663634
*/
664-
pragma[inline]
635+
bindingset[nodeTo, result]
636+
pragma[inline_late]
637+
pragma[noopt]
665638
TypeBackTracker step(TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
666-
this = backStepInlineLate(result, nodeFrom, nodeTo)
639+
exists(StepSummary summary |
640+
backStepProj(nodeTo, summary) and
641+
this = result.prepend(summary) and
642+
step(nodeFrom, nodeTo, summary)
643+
)
644+
}
645+
646+
bindingset[nodeTo, result]
647+
pragma[inline_late]
648+
pragma[noopt]
649+
private TypeBackTracker smallstepNoSimpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
650+
exists(StepSummary summary |
651+
backSmallstepProj(nodeTo, summary) and
652+
this = result.prepend(summary) and
653+
smallstep(nodeFrom, nodeTo, summary)
654+
)
667655
}
668656

669657
/**
@@ -692,7 +680,7 @@ class TypeBackTracker extends TTypeBackTracker {
692680
*/
693681
pragma[inline]
694682
TypeBackTracker smallstep(Node nodeFrom, Node nodeTo) {
695-
this = backSmallstepInlineLate(result, nodeFrom, nodeTo)
683+
this = this.smallstepNoSimpleLocalFlowStep(nodeFrom, nodeTo)
696684
or
697685
simpleLocalFlowStep(nodeFrom, nodeTo) and
698686
this = result

ruby/ql/lib/codeql/Locations.qll

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
import files.FileSystem
44

5-
bindingset[loc]
6-
pragma[inline_late]
7-
private string locationToString(Location loc) {
8-
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
9-
loc.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
10-
result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
11-
)
12-
}
13-
145
/**
156
* A location as given by a file, a start line, a start column,
167
* an end line, and an end column.
@@ -37,8 +28,14 @@ class Location extends @location_default {
3728
int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 }
3829

3930
/** Gets a textual representation of this element. */
40-
pragma[inline]
41-
string toString() { result = locationToString(this) }
31+
bindingset[this]
32+
pragma[inline_late]
33+
string toString() {
34+
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
35+
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
36+
result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
37+
)
38+
}
4239

4340
/**
4441
* Holds if this element is at the specified location.

ruby/ql/lib/codeql/ruby/typetracking/TypeTracker.qll

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,6 @@ private predicate stepProj(TypeTrackingNode nodeFrom, StepSummary summary) {
235235
step(nodeFrom, _, summary)
236236
}
237237

238-
bindingset[nodeFrom, t]
239-
pragma[inline_late]
240-
pragma[noopt]
241-
private TypeTracker stepInlineLate(TypeTracker t, TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
242-
exists(StepSummary summary |
243-
stepProj(nodeFrom, summary) and
244-
result = t.append(summary) and
245-
step(nodeFrom, nodeTo, summary)
246-
)
247-
}
248-
249238
private predicate smallstep(Node nodeFrom, TypeTrackingNode nodeTo, StepSummary summary) {
250239
smallstepNoCall(nodeFrom, nodeTo, summary)
251240
or
@@ -257,17 +246,6 @@ private predicate smallstepProj(Node nodeFrom, StepSummary summary) {
257246
smallstep(nodeFrom, _, summary)
258247
}
259248

260-
bindingset[nodeFrom, t]
261-
pragma[inline_late]
262-
pragma[noopt]
263-
private TypeTracker smallstepInlineLate(TypeTracker t, Node nodeFrom, Node nodeTo) {
264-
exists(StepSummary summary |
265-
smallstepProj(nodeFrom, summary) and
266-
result = t.append(summary) and
267-
smallstep(nodeFrom, nodeTo, summary)
268-
)
269-
}
270-
271249
/**
272250
* Holds if `nodeFrom` is being written to the `content` of the object in `nodeTo`.
273251
*
@@ -501,9 +479,26 @@ class TypeTracker extends TTypeTracker {
501479
* Gets the summary that corresponds to having taken a forwards
502480
* heap and/or inter-procedural step from `nodeFrom` to `nodeTo`.
503481
*/
504-
pragma[inline]
482+
bindingset[nodeFrom, this]
483+
pragma[inline_late]
484+
pragma[noopt]
505485
TypeTracker step(TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
506-
result = stepInlineLate(this, nodeFrom, nodeTo)
486+
exists(StepSummary summary |
487+
stepProj(nodeFrom, summary) and
488+
result = this.append(summary) and
489+
step(nodeFrom, nodeTo, summary)
490+
)
491+
}
492+
493+
bindingset[nodeFrom, this]
494+
pragma[inline_late]
495+
pragma[noopt]
496+
private TypeTracker smallstepNoSimpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
497+
exists(StepSummary summary |
498+
smallstepProj(nodeFrom, summary) and
499+
result = this.append(summary) and
500+
smallstep(nodeFrom, nodeTo, summary)
501+
)
507502
}
508503

509504
/**
@@ -532,7 +527,7 @@ class TypeTracker extends TTypeTracker {
532527
*/
533528
pragma[inline]
534529
TypeTracker smallstep(Node nodeFrom, Node nodeTo) {
535-
result = smallstepInlineLate(this, nodeFrom, nodeTo)
530+
result = this.smallstepNoSimpleLocalFlowStep(nodeFrom, nodeTo)
536531
or
537532
simpleLocalFlowStep(nodeFrom, nodeTo) and
538533
result = this
@@ -552,34 +547,10 @@ private predicate backStepProj(TypeTrackingNode nodeTo, StepSummary summary) {
552547
step(_, nodeTo, summary)
553548
}
554549

555-
bindingset[nodeTo, t]
556-
pragma[inline_late]
557-
pragma[noopt]
558-
private TypeBackTracker backStepInlineLate(
559-
TypeBackTracker t, TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo
560-
) {
561-
exists(StepSummary summary |
562-
backStepProj(nodeTo, summary) and
563-
result = t.prepend(summary) and
564-
step(nodeFrom, nodeTo, summary)
565-
)
566-
}
567-
568550
private predicate backSmallstepProj(TypeTrackingNode nodeTo, StepSummary summary) {
569551
smallstep(_, nodeTo, summary)
570552
}
571553

572-
bindingset[nodeTo, t]
573-
pragma[inline_late]
574-
pragma[noopt]
575-
private TypeBackTracker backSmallstepInlineLate(TypeBackTracker t, Node nodeFrom, Node nodeTo) {
576-
exists(StepSummary summary |
577-
backSmallstepProj(nodeTo, summary) and
578-
result = t.prepend(summary) and
579-
smallstep(nodeFrom, nodeTo, summary)
580-
)
581-
}
582-
583554
/**
584555
* A summary of the steps needed to back-track a use of a value to a given dataflow node.
585556
*
@@ -661,9 +632,26 @@ class TypeBackTracker extends TTypeBackTracker {
661632
* Gets the summary that corresponds to having taken a backwards
662633
* heap and/or inter-procedural step from `nodeTo` to `nodeFrom`.
663634
*/
664-
pragma[inline]
635+
bindingset[nodeTo, result]
636+
pragma[inline_late]
637+
pragma[noopt]
665638
TypeBackTracker step(TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
666-
this = backStepInlineLate(result, nodeFrom, nodeTo)
639+
exists(StepSummary summary |
640+
backStepProj(nodeTo, summary) and
641+
this = result.prepend(summary) and
642+
step(nodeFrom, nodeTo, summary)
643+
)
644+
}
645+
646+
bindingset[nodeTo, result]
647+
pragma[inline_late]
648+
pragma[noopt]
649+
private TypeBackTracker smallstepNoSimpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
650+
exists(StepSummary summary |
651+
backSmallstepProj(nodeTo, summary) and
652+
this = result.prepend(summary) and
653+
smallstep(nodeFrom, nodeTo, summary)
654+
)
667655
}
668656

669657
/**
@@ -692,7 +680,7 @@ class TypeBackTracker extends TTypeBackTracker {
692680
*/
693681
pragma[inline]
694682
TypeBackTracker smallstep(Node nodeFrom, Node nodeTo) {
695-
this = backSmallstepInlineLate(result, nodeFrom, nodeTo)
683+
this = this.smallstepNoSimpleLocalFlowStep(nodeFrom, nodeTo)
696684
or
697685
simpleLocalFlowStep(nodeFrom, nodeTo) and
698686
this = result

0 commit comments

Comments
 (0)