Commit Graph

9954 Commits

Author SHA1 Message Date
yoff
1ae4033aae python: add consistency checks
Co-authored-by: aschackmull <aschackmull@github.com>
2026-05-04 15:34:33 +02:00
yoff
53b83ba4b6 Python: add pattern nodes
Co-authored-by: Copilot <copilot@github.com>
2026-05-04 15:31:24 +02:00
Taus
18cce8bbdb Cleanup, printCFG
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:59:11 +00:00
Taus
3144582fd8 WIP2 2026-04-28 14:12:26 +00:00
Taus
652a3890dd WIP 2026-04-28 14:12:26 +00:00
Taus
bdcab5204c Python: Handle dict unpacking in calls
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:25 +00:00
Taus
a62f8fae8e Python: Fix exception issue
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:25 +00:00
Taus
591640a02e Python: Fix match
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:25 +00:00
Taus
3aca70588d Python: Support match
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:25 +00:00
Taus
71cf38480a Python: More nodes
Not entirely sure about the `else:` blocks.

Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:25 +00:00
Taus
2dfbd5502d Python: Comprehensions
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:25 +00:00
Taus
b0257a50a5 Python: Add with
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:25 +00:00
Taus
2968cb9654 Python: More simple statements
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:24 +00:00
Taus
501500828f Python: assignments
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:24 +00:00
Taus
1bea68557b Python: Attributes
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:24 +00:00
Taus
25b4ac7748 Python: Function calls
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:24 +00:00
Taus
4985e9706b Python: Assert statements
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:24 +00:00
Taus
95ba5cc35d Python: Support various literals
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:24 +00:00
Taus
1c66aff59e Python: Ignore synthetic CFG nodes
We can only annotate the ones that correspond directly to AST nodes
anyway.

Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:24 +00:00
Taus
aa884f4698 Python: More AstNodeImpl improvements
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:24 +00:00
Taus
7c2978ec70 Python: Instantiate CFG tests with new CFG library
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:23 +00:00
Taus
e2dbb147c5 Python: Instantiate CFG module fully
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:23 +00:00
Taus
a24f85beb4 Python: Use fields everywhere in new AST classes
Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:23 +00:00
Taus
bb9b5dfdb9 Python: First stab at shared control-flow 2026-04-28 14:12:23 +00:00
Taus
89c2bcbe97 Python: Make CFG tests parameterised
Currently we only instantiate them with the old CFG library, but in the
future we'll want to do this with the new library as well.

Co-authored-by: yoff <yoff@github.com>
2026-04-28 14:12:23 +00:00
Taus
00f9d5c895 Python: Add ConsecutiveTimestamps test
This one is potentially a bit iffy -- it checks for a very powerful
propetry (that implies many of the other queries), but as the test
results show, it can produce false positives when there is in fact no
problem. We may want to get rid of it entirely, if it becomes too noisy.
2026-04-28 14:12:23 +00:00
Taus
ee6e033668 Python: Add NeverReachable test
This looks for nodes annotated with `t.never` in the test that are
reachable in the CFG. This should not happen (it messes with various
queries, e.g. the "mixed returns" query), but the test shows that in a
few particular cases (involving the `match` statement where all cases
contain `return`s), we _do_ have reachable nodes that shouldn't be.
2026-04-28 14:12:23 +00:00
Taus
4a5d37815f Python: Add BasicBlockOrdering test
This one demonstrates a bug in the current CFG. In a dictionary
comprehension `{k: v for k, v in d.items()}`, we evaluate the value
before the key, which is incorrect. (A fix for this bug has been
implemented in a separate PR.)
2026-04-28 14:12:23 +00:00
Taus
2a02a42bdb Python: Add some CFG-validation queries
These use the annotated, self-verifying test files to check various
consistency requirements.

Some of these may be expressing the same thing in different ways, but
it's fairly cheap to keep them around, so I have not attempted to
produce a minimal set of queries for this.
2026-04-28 14:12:23 +00:00
Taus
a95aaf177e Python: Add self-validating CFG tests
These tests consist of various Python constructions (hopefully a
somewhat comprehensive set) with specific timestamp annotations
scattered throughout. When the tests are run using the Python 3
interpreter, these annotations are checked and compared to the "current
timestamp" to see that they are in agreement. This is what makes the
tests "self-validating".

There are a few different kinds of annotations: the basic `t[4]` style
(meaning this is executed at timestamp 4), the `t.dead[4]` variant
(meaning this _would_ happen at timestamp 4, but it is in a dead
branch), and `t.never` (meaning this is never executed at all).

In addition to this, there is a query, MissingAnnotations, which checks
whether we have applied these annotations maximally. Many expression
nodes are not actually annotatable, so there is a sizeable list of
excluded nodes for that query.
2026-04-28 14:12:22 +00:00
Owen Mansel-Chan
6efb21314a Merge pull request #21523 from owen-mc/docs/mad/barriers
Document models-as-data barriers and barrier guards and add change notes
2026-04-21 13:49:19 +01:00
Michael B. Gale
58e9bad0a0 Merge pull request #21737 from github/post-release-prep/codeql-cli-2.25.3
Post-release preparation for codeql-cli-2.25.3
2026-04-21 11:48:30 +02:00
Taus
b108e173a5 Merge pull request #21695 from github/tausbn/python-add-support-for-pep-798
Python: Add support for PEP-798
2026-04-20 15:01:01 +02:00
github-actions[bot]
a0bab539bb Post-release preparation for codeql-cli-2.25.3 2026-04-20 12:40:34 +00:00
github-actions[bot]
c861d99802 Release preparation for version 2.25.3 2026-04-20 09:27:23 +00:00
Taus
ac23e16786 Python: Move Python 3.15 data-flow tests to a separate file
We won't be able to run these tests until Python 3.15 is actually out
(and our CI is using it), so it seemed easiest to just put them in their
own test directory.
2026-04-17 13:16:46 +00:00
Taus
dc36609743 Python: Add data-flow tests
Alas, all these demonstrate is that we already don't fully support the
desugared `yield from` form.
2026-04-17 12:15:04 +00:00
Taus
6c675fcede Python: Consolidate duplicated code 2026-04-16 21:14:42 +00:00
Owen Mansel-Chan
8f17b73796 Fix link formatting in change notes 2026-04-14 15:27:37 +01:00
Owen Mansel-Chan
c86ba38a4e Add change notes 2026-04-14 15:27:31 +01:00
Henry Mercer
43c9b95e6f Merge branch 'main' into post-release-prep/codeql-cli-2.25.2 2026-04-14 13:56:52 +01:00
Taus
8b1ecf05c9 Python: Update test output
This change reflects the `(value, key)` to `(key, value)` fix in an
earlier commit.
2026-04-14 13:27:31 +02:00
Taus
15790aa00c Python: Add change note 2026-04-14 13:27:31 +02:00
Taus
de900fc3b5 Python: Add QL test for comprehensions with unpacking 2026-04-14 13:27:31 +02:00
Taus
fc5b3562c3 Python: Add parser test for comprehensions with unpacking 2026-04-14 13:27:31 +02:00
Taus
90b64616f7 Python: Also fix (value, key) bug in old parser 2026-04-14 13:27:31 +02:00
Taus
91d4cf6624 Python: Update python.tsg
First, we extend the various location overriding hacks to also accept
list and dict splats in various places. Having done this, we then have
to tackle how to actually desugar these new comprehension forms (as this
is what we currently do for the old forms).

As a reminder, a list comprehension like `[x for x in y]` currently gets
desugared into a small local function, something like

```python
def listcomp(a):
    for x in a:
        yield x
listcomp(y)
```

For `[*x for x in y]`, the behaviour we want is that we unpack `x`
before yielding its elements in turn. This is essentially what we would
get if we were to use `yield from x` instead of `yield x` in the above
desugaring, so that's what we do. This also works for set
comprehensions.

For dict comprehensions, it's slightly more complicated. Here, the
generator function instead yields a stream of `(key, value)` tuples.
(And apparently the old parser got this wrong and emitted `(value, key)`
pairs instead, which we faithfully recreated in the new parser as well.
We fix that bug in both parsers while we're at it). So, a bare `yield
from` is not enough, we also need a `.items()` call to get the
double-starred expression to emit its items as a stream of tuples (that
we then `yield from`.

To make this (hopefully) less verbose in the implementation, we defer
the decision of whether to use `yield` or `yield from` by introducing a
`yield_kind` scoped variable that determines the type of the actual AST
node. And of course for dict comprehensions with unpacking we need to
synthesise the extra machinery mentioned above.

On the plus side, this means we don't have to mess with control-flow, as
the existing machinery should be able to handle the desugared syntax
just fine.
2026-04-14 13:27:31 +02:00
Taus
97086c3cc9 Python: Regenerate parser files 2026-04-14 13:27:31 +02:00
Taus
4b5ff0b89e Python: Support unpacking in comprehensions in tree-sitter-python
This is the easy part -- we just allow `dictionary_splat` or
`list_splat` to appear in the same place as the expression.
2026-04-14 13:27:31 +02:00
Taus
c748fdf8ee Merge pull request #21694 from github/tausbn/python-add-support-for-pep-810
Python: Add support for PEP 810
2026-04-14 13:27:08 +02:00