Skip to content

Conversation

yoff
Copy link
Contributor

@yoff yoff commented Jan 17, 2023

Hacky PoC for captured parameters

  • we added parameters to capturing function definitions.
    Capturing is detected via ScopeEntryDefinitions.
    These only exist for the inner-most nested function (see tests)
    We should make these exist at all levels to thread the values through.
    Right now, we cannot reach further nested functions (see m in tests).
  • parameters currently need to be NameNodes,
    so we select the first mention inside the function body.
    That also only exists in the inner-most nested function
    (if that is the only one to mention hte captured variable)
    so this should be replaced with a synthetic node.
  • we needed to extend ParameterNodeImpl
    and implement isParameterOf to make the data flow library connect them.
  • we added arguments to calls to capturing functions
    (referencing the call graph)
  • These should be current value of the variable at the call site
    This is currently approximated by the latest use before the call site
    which is further approximated by any variable of the same name in the same basic block as the call
    The right thing to do is to make the call a useand let SSA handle it.
  • every captured variable has been given position -3
    this should be based on the variable name instead.
    That will be easy once we rebase on the new call graph PR,
    as it has genralised positions.

yoff added 3 commits January 13, 2023 10:55
- we added parameters to capturing function definitions.
  Capturing is detected via `ScopeEntryDefinitions`.
  These only exist for the inner-most nested function (see tests)
  We should make these exist at all levels to thread the values through.
  Right now, we cannot reach further nested functions (see `m` in tests).
- parameters currently need to be  `NameNode`s,
  so we select the first mention inside the function body.
  That also only exists in the inner-most nested function
  (if that is the only one to mention hte captured variable)
  so this should be replaced with a synthetic node.
- we needed to extend `ParameterNodeImpl`
  and implement `isParameterOf` to make the data flow library connect them.
- we added arguments to calls to capturing functions
  (referencing the call graph)
- These should be current value of the variable at the call site
This is currently approximated by the latest use before the call site
which is further approximated by any variable of the same name in the same basic block as the call
The right thing to do is to make the call a useand let SSA handle it.
- every captured variable has been given position -3
   this should be based on the variable name instead.
   That will be easy once we rebase on the new call graph PR,
   as it has genralised positions.
)
or
// captured variable
exists(string name, ScopeEntryDefinition def, NameNode var |

Check warning

Code scanning / CodeQL

Omittable 'exists' variable

This exists variable can be omitted by using a don't-care expression [in this argument](1).
)
or
// captured variable
exists(CallableValue callable, string name, ScopeEntryDefinition def |

Check warning

Code scanning / CodeQL

Omittable 'exists' variable

This exists variable can be omitted by using a don't-care expression [in this argument](1).
)
or
// captured variable
exists(CallableValue callable, string name, ScopeEntryDefinition def |

Check warning

Code scanning / CodeQL

Omittable 'exists' variable

This exists variable can be omitted by using a don't-care expression [in this argument](1).
@@ -0,0 +1,27 @@
import python
import semmle.python.essa.Essa

Check warning

Code scanning / CodeQL

Redundant import

Redundant import, the module is already imported inside [python](1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant