diff --git a/docs/adr/0034-lineage-archive.md b/docs/adr/0034-lineage-archive.md index e743b3c..d929287 100644 --- a/docs/adr/0034-lineage-archive.md +++ b/docs/adr/0034-lineage-archive.md @@ -29,6 +29,18 @@ type offers no way to forget, so no caller and no later change can delete a reco by choosing to. Retention is a property of the interface rather than a rule someone has to remember. +Forgetting has forms that are not named like removal, so the copy and move policy +is part of that interface rather than left to the defaults. Assignment discards +every record the target holds, which is deletion however it is spelled, and it +would also allow a copy taken earlier to be written back, restoring an organism +the archive had already recorded as dead. Both forms of assignment are therefore +deleted, which also makes the archive unswappable, since swapping needs them. +Declaring the copy constructor suppresses the implicit moves, so a move decays to +a copy and a moved-from archive still holds every record rather than being emptied +the way a moved-from container would be. Copying itself stays available: a clone +takes nothing from the original, and GENOME_MODEL expects migrations to be +rehearsed on cloned worlds. + A genome is admitted only if its parent is already present, so ancestry is always walkable and no link dangles. That ordering also makes the parent graph acyclic by construction: admitting a cycle would require one of its members to be admitted @@ -57,6 +69,13 @@ durability are M7 and M8 work, and this bound is a fixture limit, not a policy. ## Alternatives Considered +Leaving the copy and move policy to the defaults was the original mistake here: +the type had no method named like removal and still forgot everything on +assignment. Deleting the move constructor as well would have been stricter but +would stop an archive being returned from a function, so it is left to decay to a +copy. Forbidding copies entirely would block the cloned-world rehearsal the +documents call for while preventing nothing, since a copy removes nothing. + Pruning lineages with no living carrier is the named risk, and is wrong even as an optimisation: an absent lineage is the evidence that something happened. A `extinct` status would claim a conclusion the archive cannot support. Allowing a diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 5d94834..63eb9a3 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -682,6 +682,21 @@ genomes are now stored directly and identified by their own `id()`. The redundan per-genome carrier tally was dropped in the same change: carriers are counted from the organism records, so there is no second tally that could drift. +Review of `8020347` found one defect (2026-09-23): the retention claim covered +methods named like removal and nothing else, so `archive = LineageArchive{}` +discarded every record, and assigning a copy taken before a death restored that +organism's living state. Both forms of assignment are now deleted, which also +makes the archive unswappable, and the copy constructor is declared so the +implicit moves are suppressed and a move decays to a copy. Copying stays available +because a clone removes nothing and GENOME_MODEL expects cloned-world rehearsals. + +The interface tests now cover assignment, replacement from a temporary and +swapping as well as the named methods, each with a std::vector positive control, +and check at runtime that a copy taken before a death does not disturb the +original's terminal record and that a moved-from archive still holds everything. +All four static assertions were confirmed to fail with the deleted assignments +removed. + Nothing is serialized, so no history survives a process, and no fixture calls any of this. Terminal extinction is not claimed anywhere, durable retention and migration are M7 and M8, and NPC mutation remains undecided. Golden diff --git a/include/evo/biology/lineage.hpp b/include/evo/biology/lineage.hpp index e6e8d74..20c6107 100644 --- a/include/evo/biology/lineage.hpp +++ b/include/evo/biology/lineage.hpp @@ -35,6 +35,19 @@ inline constexpr std::size_t max_archived_organisms = 65'536; // this interface rather than a rule a caller has to remember. class LineageArchive { public: + LineageArchive() = default; + // Copyable: cloning an archive takes nothing away from the original, and + // GENOME_MODEL expects migrations to be rehearsed on cloned worlds. + // Declaring the copy constructor also suppresses the implicit moves, so a + // move decays to a copy and a moved-from archive still holds every record. + LineageArchive(const LineageArchive&) = default; + // Not assignable, in either form. Assignment is a removal operation that is + // simply not named like one: it discards every record the target holds. It + // would also let a copy taken earlier be written back, restoring an organism + // already recorded as dead, and death is terminal. + LineageArchive& operator=(const LineageArchive&) = delete; + LineageArchive& operator=(LineageArchive&&) = delete; + // A parent must already be present, so ancestry never dangles and the parent // graph cannot contain a cycle: a cycle would need a member admitted first. [[nodiscard]] std::expected admit(const Genome& genome); diff --git a/tests/lineage_tests.cpp b/tests/lineage_tests.cpp index ad345a2..16200ce 100644 --- a/tests/lineage_tests.cpp +++ b/tests/lineage_tests.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace { @@ -179,6 +180,42 @@ template concept clears = requires(Archive& archive) { archive.clear(); }; template concept prunes = requires(Archive& archive) { archive.prune(); }; +// Forgetting has forms that are not named like removal. Replacing an archive +// wholesale discards every record it held, and swapping needs the same +// assignment that makes replacement possible. +template +concept replaceable = requires(Archive& archive) { archive = Archive{}; }; +template +concept exchangeable = requires(Archive& left, Archive& right) { std::swap(left, right); }; + +void the_archive_cannot_be_replaced_or_rewound() { + static_assert(!replaceable); + static_assert(!exchangeable); + static_assert(!std::is_copy_assignable_v); + static_assert(!std::is_move_assignable_v); + // These checks are live: an ordinary container admits all of them. + static_assert(replaceable>); + static_assert(exchangeable>); + // Copying stays available, because a clone takes nothing from the original. + static_assert(std::is_copy_constructible_v); + auto archive = branching(); + CHECK(archive.record_birth(800, 3, evo::Tick{1})); + const auto taken_while_living = archive; // A copy from before the death. + CHECK(archive.record_death(800, evo::Tick{9})); + CHECK(!archive.organism(800)->alive); + // The copy is a separate archive. Nothing can write it back over the + // original, so the terminal record stands. + CHECK(taken_while_living.organism(800)->alive); + CHECK(!archive.organism(800)->alive); + // A move decays to a copy, so the source still holds every record rather + // than being emptied the way a moved-from container would be. + // NOLINTNEXTLINE(performance-move-const-arg) + const auto moved = std::move(archive); + // NOLINTNEXTLINE(bugprone-use-after-move): the point of the check. + CHECK(archive.archived() == moved.archived() && archive.recorded() == 1); + // NOLINTNEXTLINE(bugprone-use-after-move) + CHECK(archive.find(1) && !archive.organism(800)->alive); +} void the_archive_offers_no_way_to_forget() { static_assert(!erases); @@ -221,6 +258,7 @@ int main() try { admission_refuses_duplicates_and_dangling_parents(); death_is_terminal_and_births_are_unique(); absence_is_never_reported_as_extinction(); + the_archive_cannot_be_replaced_or_rewound(); the_archive_offers_no_way_to_forget(); capacity_refuses_loudly_rather_than_dropping(); std::cout << "PASS lineage retention, branching ancestry and provisional absence\n";