Commit 6163a98
committed
[mypyc] Fix non-deterministic class struct layout under separate=True
detect_undefined_bitmap() was extending cl.bitmap_attrs in place. Under
separate=True each SCC's analyze_always_defined_attrs is invoked once per
group, and detect_undefined_bitmap recurses through cl.base_mro from the
subclass into its base classes. The seen set passed in dedupes within one
call but is fresh per call, so every subclass-group call re-extends the
shared base class's bitmap_attrs with another copy of the contributions.
The base class's emitted ObjectStruct then grows by one bitmap field per
~32 subclasses processed in the same build. The exact final length is a
function of how many SCCs went through compile_scc_to_ir this run:
- clean build: every SCC fresh -> base bitmap_attrs accumulates fully
- incremental build affecting N subclasses: base accumulates a fraction
- second incremental: yet another count
Subclasses not rebuilt this round still see their base's old, larger
struct layout. Any attribute access on the base segfaults with a
mismatched bitmap-field offset.
Pre-existing in mypyc; only manifested once the prior over-conservative
44-file always-rebuild was lifted (1.20.0.post5), because that wasteful
behavior kept rebuild sets self-consistent.
Fix: compute a fresh local list and assign at the end. The function
becomes naturally idempotent across repeated calls — same input, same
output, regardless of how many groups have visited the class. No new
fields, no serialization changes.
Verified against sqlglot[c] (separate=True, ~100 modules):
Edit: add a method to MySQLParser (a class with 7 dialect subclasses)
Before: parser.h struct layout differs between clean and incremental
builds; make unitc segfaults at first parser-using test.
After: parser.h identical between clean and incremental;
make unitc passes (1163 tests, 0 segfaults).1 parent 25996f1 commit 6163a98
1 file changed
Lines changed: 16 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
427 | 438 | | |
428 | | - | |
| 439 | + | |
429 | 440 | | |
430 | 441 | | |
431 | | - | |
| 442 | + | |
432 | 443 | | |
433 | 444 | | |
434 | 445 | | |
435 | 446 | | |
436 | | - | |
437 | | - | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
0 commit comments