Skip to content

Commit 9a26fc3

Browse files
authored
Merge pull request github#13573 from hvitved/ruby/inline-late-members
Ruby/Python: Use `inline_late` on member predicates
2 parents 7695694 + fa92e79 commit 9a26fc3

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
@@ -234,17 +234,6 @@ private predicate stepProj(TypeTrackingNode nodeFrom, StepSummary summary) {
234234
step(nodeFrom, _, summary)
235235
}
236236

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

259-
bindingset[nodeFrom, t]
260-
pragma[inline_late]
261-
pragma[noopt]
262-
private TypeTracker smallstepInlineLate(TypeTracker t, Node nodeFrom, Node nodeTo) {
263-
exists(StepSummary summary |
264-
smallstepProj(nodeFrom, summary) and
265-
result = t.append(summary) and
266-
smallstep(nodeFrom, nodeTo, summary)
267-
)
268-
}
269-
270248
/**
271249
* Holds if `nodeFrom` is being written to the `content` of the object in `nodeTo`.
272250
*
@@ -531,9 +509,26 @@ class TypeTracker extends TTypeTracker {
531509
* Gets the summary that corresponds to having taken a forwards
532510
* heap and/or inter-procedural step from `nodeFrom` to `nodeTo`.
533511
*/
534-
pragma[inline]
512+
bindingset[nodeFrom, this]
513+
pragma[inline_late]
514+
pragma[noopt]
535515
TypeTracker step(TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
536-
result = stepInlineLate(this, nodeFrom, nodeTo)
516+
exists(StepSummary summary |
517+
stepProj(nodeFrom, summary) and
518+
result = this.append(summary) and
519+
step(nodeFrom, nodeTo, summary)
520+
)
521+
}
522+
523+
bindingset[nodeFrom, this]
524+
pragma[inline_late]
525+
pragma[noopt]
526+
private TypeTracker smallstepNoSimpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
527+
exists(StepSummary summary |
528+
smallstepProj(nodeFrom, summary) and
529+
result = this.append(summary) and
530+
smallstep(nodeFrom, nodeTo, summary)
531+
)
537532
}
538533

539534
/**
@@ -562,7 +557,7 @@ class TypeTracker extends TTypeTracker {
562557
*/
563558
pragma[inline]
564559
TypeTracker smallstep(Node nodeFrom, Node nodeTo) {
565-
result = smallstepInlineLate(this, nodeFrom, nodeTo)
560+
result = this.smallstepNoSimpleLocalFlowStep(nodeFrom, nodeTo)
566561
or
567562
simpleLocalFlowStep(nodeFrom, nodeTo) and
568563
result = this
@@ -589,34 +584,10 @@ private predicate backStepProj(TypeTrackingNode nodeTo, StepSummary summary) {
589584
step(_, nodeTo, summary)
590585
}
591586

592-
bindingset[nodeTo, t]
593-
pragma[inline_late]
594-
pragma[noopt]
595-
private TypeBackTracker backStepInlineLate(
596-
TypeBackTracker t, TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo
597-
) {
598-
exists(StepSummary summary |
599-
backStepProj(nodeTo, summary) and
600-
result = t.prepend(summary) and
601-
step(nodeFrom, nodeTo, summary)
602-
)
603-
}
604-
605587
private predicate backSmallstepProj(TypeTrackingNode nodeTo, StepSummary summary) {
606588
smallstep(_, nodeTo, summary)
607589
}
608590

609-
bindingset[nodeTo, t]
610-
pragma[inline_late]
611-
pragma[noopt]
612-
private TypeBackTracker backSmallstepInlineLate(TypeBackTracker t, Node nodeFrom, Node nodeTo) {
613-
exists(StepSummary summary |
614-
backSmallstepProj(nodeTo, summary) and
615-
result = t.prepend(summary) and
616-
smallstep(nodeFrom, nodeTo, summary)
617-
)
618-
}
619-
620591
/**
621592
* A summary of the steps needed to back-track a use of a value to a given dataflow node.
622593
*
@@ -698,9 +669,26 @@ class TypeBackTracker extends TTypeBackTracker {
698669
* Gets the summary that corresponds to having taken a backwards
699670
* heap and/or inter-procedural step from `nodeTo` to `nodeFrom`.
700671
*/
701-
pragma[inline]
672+
bindingset[nodeTo, result]
673+
pragma[inline_late]
674+
pragma[noopt]
702675
TypeBackTracker step(TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
703-
this = backStepInlineLate(result, nodeFrom, nodeTo)
676+
exists(StepSummary summary |
677+
backStepProj(nodeTo, summary) and
678+
this = result.prepend(summary) and
679+
step(nodeFrom, nodeTo, summary)
680+
)
681+
}
682+
683+
bindingset[nodeTo, result]
684+
pragma[inline_late]
685+
pragma[noopt]
686+
private TypeBackTracker smallstepNoSimpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
687+
exists(StepSummary summary |
688+
backSmallstepProj(nodeTo, summary) and
689+
this = result.prepend(summary) and
690+
smallstep(nodeFrom, nodeTo, summary)
691+
)
704692
}
705693

706694
/**
@@ -729,7 +717,7 @@ class TypeBackTracker extends TTypeBackTracker {
729717
*/
730718
pragma[inline]
731719
TypeBackTracker smallstep(Node nodeFrom, Node nodeTo) {
732-
this = backSmallstepInlineLate(result, nodeFrom, nodeTo)
720+
this = this.smallstepNoSimpleLocalFlowStep(nodeFrom, nodeTo)
733721
or
734722
simpleLocalFlowStep(nodeFrom, nodeTo) and
735723
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
@@ -234,17 +234,6 @@ private predicate stepProj(TypeTrackingNode nodeFrom, StepSummary summary) {
234234
step(nodeFrom, _, summary)
235235
}
236236

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

259-
bindingset[nodeFrom, t]
260-
pragma[inline_late]
261-
pragma[noopt]
262-
private TypeTracker smallstepInlineLate(TypeTracker t, Node nodeFrom, Node nodeTo) {
263-
exists(StepSummary summary |
264-
smallstepProj(nodeFrom, summary) and
265-
result = t.append(summary) and
266-
smallstep(nodeFrom, nodeTo, summary)
267-
)
268-
}
269-
270248
/**
271249
* Holds if `nodeFrom` is being written to the `content` of the object in `nodeTo`.
272250
*
@@ -531,9 +509,26 @@ class TypeTracker extends TTypeTracker {
531509
* Gets the summary that corresponds to having taken a forwards
532510
* heap and/or inter-procedural step from `nodeFrom` to `nodeTo`.
533511
*/
534-
pragma[inline]
512+
bindingset[nodeFrom, this]
513+
pragma[inline_late]
514+
pragma[noopt]
535515
TypeTracker step(TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
536-
result = stepInlineLate(this, nodeFrom, nodeTo)
516+
exists(StepSummary summary |
517+
stepProj(nodeFrom, summary) and
518+
result = this.append(summary) and
519+
step(nodeFrom, nodeTo, summary)
520+
)
521+
}
522+
523+
bindingset[nodeFrom, this]
524+
pragma[inline_late]
525+
pragma[noopt]
526+
private TypeTracker smallstepNoSimpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
527+
exists(StepSummary summary |
528+
smallstepProj(nodeFrom, summary) and
529+
result = this.append(summary) and
530+
smallstep(nodeFrom, nodeTo, summary)
531+
)
537532
}
538533

539534
/**
@@ -562,7 +557,7 @@ class TypeTracker extends TTypeTracker {
562557
*/
563558
pragma[inline]
564559
TypeTracker smallstep(Node nodeFrom, Node nodeTo) {
565-
result = smallstepInlineLate(this, nodeFrom, nodeTo)
560+
result = this.smallstepNoSimpleLocalFlowStep(nodeFrom, nodeTo)
566561
or
567562
simpleLocalFlowStep(nodeFrom, nodeTo) and
568563
result = this
@@ -589,34 +584,10 @@ private predicate backStepProj(TypeTrackingNode nodeTo, StepSummary summary) {
589584
step(_, nodeTo, summary)
590585
}
591586

592-
bindingset[nodeTo, t]
593-
pragma[inline_late]
594-
pragma[noopt]
595-
private TypeBackTracker backStepInlineLate(
596-
TypeBackTracker t, TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo
597-
) {
598-
exists(StepSummary summary |
599-
backStepProj(nodeTo, summary) and
600-
result = t.prepend(summary) and
601-
step(nodeFrom, nodeTo, summary)
602-
)
603-
}
604-
605587
private predicate backSmallstepProj(TypeTrackingNode nodeTo, StepSummary summary) {
606588
smallstep(_, nodeTo, summary)
607589
}
608590

609-
bindingset[nodeTo, t]
610-
pragma[inline_late]
611-
pragma[noopt]
612-
private TypeBackTracker backSmallstepInlineLate(TypeBackTracker t, Node nodeFrom, Node nodeTo) {
613-
exists(StepSummary summary |
614-
backSmallstepProj(nodeTo, summary) and
615-
result = t.prepend(summary) and
616-
smallstep(nodeFrom, nodeTo, summary)
617-
)
618-
}
619-
620591
/**
621592
* A summary of the steps needed to back-track a use of a value to a given dataflow node.
622593
*
@@ -698,9 +669,26 @@ class TypeBackTracker extends TTypeBackTracker {
698669
* Gets the summary that corresponds to having taken a backwards
699670
* heap and/or inter-procedural step from `nodeTo` to `nodeFrom`.
700671
*/
701-
pragma[inline]
672+
bindingset[nodeTo, result]
673+
pragma[inline_late]
674+
pragma[noopt]
702675
TypeBackTracker step(TypeTrackingNode nodeFrom, TypeTrackingNode nodeTo) {
703-
this = backStepInlineLate(result, nodeFrom, nodeTo)
676+
exists(StepSummary summary |
677+
backStepProj(nodeTo, summary) and
678+
this = result.prepend(summary) and
679+
step(nodeFrom, nodeTo, summary)
680+
)
681+
}
682+
683+
bindingset[nodeTo, result]
684+
pragma[inline_late]
685+
pragma[noopt]
686+
private TypeBackTracker smallstepNoSimpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
687+
exists(StepSummary summary |
688+
backSmallstepProj(nodeTo, summary) and
689+
this = result.prepend(summary) and
690+
smallstep(nodeFrom, nodeTo, summary)
691+
)
704692
}
705693

706694
/**
@@ -729,7 +717,7 @@ class TypeBackTracker extends TTypeBackTracker {
729717
*/
730718
pragma[inline]
731719
TypeBackTracker smallstep(Node nodeFrom, Node nodeTo) {
732-
this = backSmallstepInlineLate(result, nodeFrom, nodeTo)
720+
this = this.smallstepNoSimpleLocalFlowStep(nodeFrom, nodeTo)
733721
or
734722
simpleLocalFlowStep(nodeFrom, nodeTo) and
735723
this = result

0 commit comments

Comments
 (0)