Commit cde4779
authored
[mypyc] Fix non-deterministic class struct layout under
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.separate=True (#21530)1 parent 6f0e77b commit cde4779
2 files changed
Lines changed: 31 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
427 | 432 | | |
428 | | - | |
| 433 | + | |
429 | 434 | | |
430 | 435 | | |
431 | | - | |
| 436 | + | |
432 | 437 | | |
433 | 438 | | |
434 | 439 | | |
435 | 440 | | |
436 | | - | |
437 | | - | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments