Python: Align implementations of awaited.

This commit is contained in:
Rasmus Lerchedahl Petersen
2021-09-28 16:42:19 +02:00
parent 3c1206f873
commit a5912ff76d
2 changed files with 18 additions and 16 deletions

View File

@@ -500,21 +500,21 @@ module API {
or
// `async for x in l`
// - `awaitedValue` is `l`
// - `result` is `l` (should perhaps be `x`)
// - `result` is `l` (should perhaps be `x`, but that should really be a read)
exists(AsyncFor asyncFor |
result.asExpr() = asyncFor.getTarget() and
// Morally, we should perhaps use asyncFor.getIter() = awaitedValue.asExpr()
// but that does not work.
// Morally, we should perhaps use asyncFor.getIter() = awaitedValue.asExpr(),
// but that is actually behind a read step rather than a flow step.
asyncFor.getTarget() = awaitedValue.asExpr()
)
or
// `async with x as y`
// - `awaitedValue` is `x`
// - `result` is `x` (should probably be `y`)
// - `result` is `x` (should probably be `y` but it might not exist)
exists(AsyncWith asyncWith |
result.asExpr() = asyncWith.getContextExpr() and
// Morally, we should perhaps use asyncWith.getOptionalVars() = awaitedValue.asExpr()
// but that does not work.
// Morally, we should perhaps use asyncWith.getOptionalVars() = awaitedValue.asExpr(),
// but that might not exist.
asyncWith.getContextExpr() = awaitedValue.asExpr()
)
}

View File

@@ -42,29 +42,31 @@ private module Asyncpg {
* Holds if `result` is the result of awaiting `n`.
*/
pragma[inline]
DataFlow::Node awaited(DataFlow::Node n) {
DataFlow::Node awaited(DataFlow::Node awaitedValue) {
// `await` x
// - `awaitedValue` is `x`
// - `result` is `await x`
exists(Await await |
result.asExpr() = await and
await.getValue() = n.asExpr()
await.getValue() = awaitedValue.asExpr()
)
or
// `async for x in l`
// - `awaitedValue` is `l`
// - `result` is `x`
exists(AsyncFor asyncFor |
// - `awaitedValue` is local source of `l`
// - `result` is `l`
exists(AsyncFor asyncFor, DataFlow::Node awaited |
result.asExpr() = asyncFor.getTarget() and
asyncFor.getIter() = n.asExpr()
asyncFor.getIter() = awaited.asExpr() and
awaited.getALocalSource() = awaitedValue
)
or
// `async with x as y`
// - `awaitedValue` is `x`
// - `result` is `y`
exists(AsyncWith asyncWith |
// - `awaitedValue` is local source of `x`
// - `result` is `x`
exists(AsyncWith asyncWith, DataFlow::Node awaited |
result.asExpr() = asyncWith.getContextExpr() and
asyncWith.getOptionalVars() = n.asExpr()
asyncWith.getOptionalVars() = awaited.asExpr() and
awaited.getALocalSource() = awaitedValue
)
}