Skip to content

Commit 6e4011d

Browse files
committed
Python: rename sythetic nodes
Avoid the term "closure" as it is somewhat academic.
1 parent c0b3d98 commit 6e4011d

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ private import semmle.python.dataflow.new.internal.TypeTracker::CallGraphConstru
4242
newtype TParameterPosition =
4343
/** Used for `self` in methods, and `cls` in classmethods. */
4444
TSelfParameterPosition() or
45+
/**
46+
* This is used for tracking flow through captured variables, and
47+
* we use separate parameter/argument positions in order to distinguish
48+
* "lambda self" from "normal self", as lambdas may also access outer `self`
49+
* variables (through variable capture).
50+
*/
4551
TLambdaSelfParameterPosition() or
4652
TPositionalParameterPosition(int index) {
4753
index = any(Parameter p).getPosition()
@@ -135,6 +141,12 @@ class ParameterPosition extends TParameterPosition {
135141
newtype TArgumentPosition =
136142
/** Used for `self` in methods, and `cls` in classmethods. */
137143
TSelfArgumentPosition() or
144+
/**
145+
* This is used for tracking flow through captured variables, and
146+
* we use separate parameter/argument positions in order to distinguish
147+
* "lambda self" from "normal self", as lambdas may also access outer `self`
148+
* variables (through variable capture).
149+
*/
138150
TLambdaSelfArgumentPosition() or
139151
TPositionalArgumentPosition(int index) {
140152
exists(any(CallNode c).getArg(index))
@@ -1521,20 +1533,19 @@ abstract class ParameterNodeImpl extends Node {
15211533
}
15221534

15231535
/**
1524-
* The value of a closure itself at function entry, viewed as a node in the data
1525-
* flow graph.
1536+
* A sythetic parameter representing the values of the variables captured
1537+
* by the callable being called. This parameter represents a single object
1538+
* where all the values are stored as attributes.
1539+
* This is also known as the environment part of a closure.
15261540
*
1527-
* This is used for tracking flow through captured variables, and we use
1528-
* separate argument/parameter nodes at their own parameter/argument positions in order to distinguish
1529-
* "lambda self" from "normal self", as lambdas may also access outer `self`
1530-
* variables (through variable capture).
1541+
* This is used for tracking flow through captured variables.
15311542
*/
1532-
class SynthCapturingClosureParameterNode extends ParameterNodeImpl,
1533-
TSynthCapturingClosureParameterNode
1543+
class SynthCapturedVariablesParameterNode extends ParameterNodeImpl,
1544+
TSynthCapturedVariablesParameterNode
15341545
{
15351546
private Function callable;
15361547

1537-
SynthCapturingClosureParameterNode() { this = TSynthCapturingClosureParameterNode(callable) }
1548+
SynthCapturedVariablesParameterNode() { this = TSynthCapturedVariablesParameterNode(callable) }
15381549

15391550
final Function getCallable() { result = callable }
15401551

@@ -1627,13 +1638,12 @@ private class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNodeImpl
16271638
}
16281639

16291640
/**
1630-
* The value of a closure itself being passed to the funciton, viewed as a
1631-
* node in the data flow graph.
1641+
* A sythetic argument representing the values of the variables captured
1642+
* by the callable being called. This argument represents a single object
1643+
* where all the values are stored as attributes.
1644+
* This is also known as the environment part of a closure.
16321645
*
1633-
* This is used for tracking flow through captured variables, and we use a
1634-
* separate node and parameter/argument positions in order to distinguish
1635-
* "lambda self" from "normal self", as lambdas may also access outer `self`
1636-
* variables (through variable capture).
1646+
* This is used for tracking flow through captured variables.
16371647
*
16381648
* TODO:
16391649
* We might want a synthetic node here, but currently that incurs problems
@@ -1642,10 +1652,10 @@ private class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNodeImpl
16421652
* `CallGraphConstruction::Make` in staed of
16431653
* `CallGraphConstruction::Simple::Make` appropriately.
16441654
*/
1645-
class CapturingClosureArgumentNode extends CfgNode, ArgumentNode {
1655+
class CapturedVariablesArgumentNode extends CfgNode, ArgumentNode {
16461656
CallNode callNode;
16471657

1648-
CapturingClosureArgumentNode() {
1658+
CapturedVariablesArgumentNode() {
16491659
node = callNode.getFunction() and
16501660
exists(Function target | resolveCall(callNode, target, _) |
16511661
target = any(VariableCapture::CapturedVariable v).getACapturingScope()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ predicate allowParameterReturnInSelf(ParameterNode p) {
10621062
or
10631063
exists(Function f |
10641064
VariableCapture::Flow::heuristicAllowInstanceParameterReturnInSelf(f) and
1065-
p = TSynthCapturingClosureParameterNode(f)
1065+
p = TSynthCapturedVariablesParameterNode(f)
10661066
)
10671067
}
10681068

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ newtype TNode =
118118
/** A synthetic node representing a captured variable. */
119119
TSynthCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn) or
120120
/** A synthetic node representing the heap of a function. Used for variable capture. */
121-
TSynthCapturingClosureParameterNode(Function f) {
121+
TSynthCapturedVariablesParameterNode(Function f) {
122122
f = any(VariableCapture::CapturedVariable v).getACapturingScope() and
123123
// TODO: Remove this restriction when adding proper support for captured variables in the body of the function we generate for comprehensions
124124
exists(TFunction(f))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private Flow::ClosureNode asClosureNode(Node n) {
133133
result.(Flow::ParameterNode).getParameter().getCfgNode() = n.(CfgNode).getNode()
134134
or
135135
result.(Flow::ThisParameterNode).getCallable() =
136-
n.(SynthCapturingClosureParameterNode).getCallable()
136+
n.(SynthCapturedVariablesParameterNode).getCallable()
137137
}
138138

139139
predicate storeStep(Node nodeFrom, CapturedVariableContent c, Node nodeTo) {

0 commit comments

Comments
 (0)