ruff/crates/red_knot_python_semantic
Douglas Creager 4dae09ecff
[red-knot] Better handling of visibility constraint copies (#16276)
Two related changes.  For context:

1. We were maintaining two separate arenas of `Constraint`s in each
use-def map. One was used for narrowing constraints, and the other for
visibility constraints. The visibility constraint arena was interned,
ensuring that we always used the same ID for any particular
`Constraint`. The narrowing constraint arena was not interned.

2. The TDD code relies on _all_ TDD nodes being interned and reduced.
This is an important requirement for TDDs to be a canonical form, which
allows us to use a single int comparison to test for "always true/false"
and to compare two TDDs for equivalence. But we also need to support an
individual `Constraint` having multiple values in a TDD evaluation (e.g.
to handle a `while` condition having different values the first time
it's evaluated vs later times). Previously, we handled that by
introducing a "copy" number, which was only there as a disambiguator, to
allow an interned, deduplicated constraint ID to appear in the TDD
formula multiple times.

A better way to handle (2) is to not intern the constraints in the
visibility constraint arena! The caller now gets to decide: if they add
a `Constraint` to the arena more than once, they get distinct
`ScopedConstraintId`s — which the TDD code will treat as distinct
variables, allowing them to take on different values in the ternary
function.

With that in place, we can then consolidate on a single (non-interned)
arena, which is shared for both narrowing and visibility constraints.

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
2025-02-21 09:16:25 -05:00
..
resources [red-knot] Method calls and the descriptor protocol (#16121) 2025-02-20 23:22:26 +01:00
src [red-knot] Better handling of visibility constraint copies (#16276) 2025-02-21 09:16:25 -05:00
tests red_knot_test: add support for diagnostic snapshotting 2025-02-05 13:02:54 -05:00
build.rs Modernize build scripts (#13837) 2024-10-20 22:35:35 +01:00
Cargo.toml Fix missing serde feature for red_knot_python_semantic (#16169) 2025-02-14 20:31:55 +00:00
mdtest.py [red-knot] Fix possible TOCTOU mistake in mdtest runner (#15673) 2025-01-22 15:24:25 +00:00
mdtest.py.lock [red-knot] Markdown test runner (#15632) 2025-01-21 14:06:35 +01:00