Skip to content

Dedupe triplicated wire-size/pack/unpack field lists via WireRecord#17

Open
gavdoubleu wants to merge 6 commits into
IDAS-Durham:mainfrom
gavdoubleu:wire_record_dedup
Open

Dedupe triplicated wire-size/pack/unpack field lists via WireRecord#17
gavdoubleu wants to merge 6 commits into
IDAS-Durham:mainfrom
gavdoubleu:wire_record_dedup

Conversation

@gavdoubleu

Copy link
Copy Markdown
Contributor

Summary

  • Single WireRecord field-list drives size/pack/unpack for MPI wire structs, replacing triplicated manual lists
  • Compile-time tripwires guard against WireRecord field-list drift; runtime check replaces non-portable offsetof tripwire on CoordinatedEncounter
  • Minor fix: stale comment/dead line for home_array_index in applyOnePendingInfection

Test plan

  • CI build + lint (clang-format applied)
  • tests/test_domain_communicator_detail.cpp covers WireRecord pack/unpack

gavdoubleu and others added 5 commits July 15, 2026 18:45
Proposal/Reply/PendingInfection/CoordinatedEncounter/Visitor each hand-listed
their fields separately in a size constant, pack, and unpack. Add WireRecord
seam (single field list -> size/pack/unpack derived); refactor all five to
use it. status_byte, variable-length tails stay hand-composed around it.
applyOnePendingInfection now takes const PendingInfection& instead of 8 args.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ngInfection

Comment claimed a post-unpack lookup set home_array_index; no such lookup
exists, it was always hardcoded to -1 (already its default, since it's
excluded from kInfectionWire). Corrected comment, dropped the redundant
assignment/copy.
WireRecord (f8ca6ae) derives each MPI record's wire size/pack/unpack from a
single field list, but nothing checked that list still covers every
wire-relevant field of its struct - a field added later and forgotten in
the list would silently stop going over the wire, with no build or test
failure.

Add a static_assert next to each kXWire definition:
- EncounterProposal/EncounterReply/PendingInfection are all-scalar, so
  sizeof(T) is a workable drift proxy.
- CoordinatedEncounter and VisitorData end in a std::set/std::vector tail
  packed manually outside WireRecord, so sizeof(T) is dominated by the
  container's own layout instead; use offsetof(T, tail_member) up to where
  the WireRecord-covered header ends instead.

Coarser than an exact field-by-field checksum (a same-or-smaller field
landing in existing trailing padding could still slip through unnoticed),
but needs no hand-maintained field list, so it does not reintroduce the
triplicated-listing failure mode WireRecord was written to remove. Verified
by temporarily adding an unlisted field to EncounterProposal and confirming
the build breaks.
…time check

CoordinatedEncounter is non-standard-layout (std::set<PersonId> member), so
static_assert(offsetof(CoordinatedEncounter, participants) == 32) relied on
conditionally-supported behaviour: compiles under GCC/Clang w/ a
-Winvalid-offsetof warning today, but the computed offset isn't a portable
guarantee across standard libraries (README lists Clang 10+ as supported,
not just GCC/libstdc++). Swap it for a runtime check in
test_domain_communicator_detail.cpp using well-defined pointer subtraction
on a real object, which needs no standard-layout assumption. Also add a
static_assert(is_standard_layout_v<VisitorData>) guard next to the
still-legitimate offsetof tripwire in domain_communicator.cpp, so VisitorData
gaining a similarly non-standard-layout member fails loudly at compile time
instead of quietly regressing the same way.
Reflow arg/initialiser-list wrapping and static_assert indentation
across wire-record and event-logging call sites; no semantic change.
@gavdoubleu
gavdoubleu requested a review from mtcorread as a code owner July 15, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants