Commit 9d492db
committed
fix(pr-x2): split soa_struct! into unpadded + padded arms
P1 codex review on PR #169: unconditional `_logical_len` injection
turned previously all-public generated structs into structs with a
private field, breaking downstream code that constructs them via
struct literals (`MyBatch { a: vec![], b: vec![] }`) and exhaustive
pattern matches — even for callers who never use `#[soa(pad_to_lanes
= N)]`.
Fix: split `soa_struct!` into two arms.
Arm 1 — unpadded (no `#[soa(...)]` anywhere): byte-for-byte the
pre-PR-X2 emit. No `_logical_len` field. `len()` reads field lengths
under `debug_assert`. Struct-literal construction works exactly as
before. macro_rules! tries this arm first; if any field carries a
`#[soa(pad_to_lanes = N)]` attribute, the no-attribute pattern fails
to match and the macro falls through to arm 2.
Arm 2 — padded (at least one `#[soa(...)]`): the new PR-X2 B emit
with `_logical_len` + lane-padded `push`. Reached only when the
user opted in by tagging a field — struct-literal construction was
never going to work for these anyway because the user can't fill
the lane-padded `Vec` slots themselves.
The pre-existing `macro_public_visibility_passthrough` test is
restored to its original form (direct `s.x.push(...)` on the
unpadded `Soa3`) since arm 1 is byte-identical to pre-PR-X2.
Verified:
cargo test -p ndarray --lib hpc::soa 38 passed
cargo test --doc -p ndarray hpc::soa 14 passed
cargo fmt --check clean
cargo clippy --features approx,serde,rayon -- -D warnings clean
Resolves PR #169 P1 review thread r3272307622.1 parent 5ee172a commit 9d492db
1 file changed
Lines changed: 80 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
359 | 427 | | |
360 | 428 | | |
361 | 429 | | |
| |||
371 | 439 | | |
372 | 440 | | |
373 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
374 | 446 | | |
375 | 447 | | |
376 | 448 | | |
| |||
458 | 530 | | |
459 | 531 | | |
460 | 532 | | |
461 | | - | |
| 533 | + | |
| 534 | + | |
462 | 535 | | |
463 | 536 | | |
464 | 537 | | |
| |||
877 | 950 | | |
878 | 951 | | |
879 | 952 | | |
880 | | - | |
881 | | - | |
882 | | - | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
883 | 956 | | |
884 | | - | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
885 | 960 | | |
886 | | - | |
887 | | - | |
888 | | - | |
889 | | - | |
890 | 961 | | |
891 | 962 | | |
892 | 963 | | |
| |||
0 commit comments