SIGN IN SIGN UP

[mypyc] Fix non-deterministic class struct layout under `separate=True` (#21530)

The helper function `detect_undefined_bitmap` builds the list of
attributes that need a per-instance "is set?" bit (`cl.bitmap_attrs`).
It walks from a subclass up into its base and `.append()`s entries.

The walk dedupes within one call via `seen`, but the function is called
once per SCC; Under `separate=True`, every subclass of a shared base
lives in its own SCC, so the base is visited multiple times and gets the
same entries re-appended on every pass.

After N visits, `base.bitmap_attrs` contains N duplicate copies of the
same names, so attribute offsets shift between builds and not-rebuilt
subclasses end up reading the wrong bytes. The added test case shows
that on master branch `base.bitmap_attrs` has been populated with `["i"]
* 11`

The fix: Build a fresh local list and assign once at the end. The
function becomes idempotent and the struct layout remains identical
after each incremental build.
V
Vaggelis Danias committed
cde4779e2347e7fc665717d288591b03138467fd
Parent: 6f0e77b
Committed by GitHub <noreply@github.com> on 5/21/2026, 3:59:17 PM