Keep every lineage, and never call absence extinction
M3.5 retains the genomes M3.4 produces and the organisms that carried them. The named risk is deleting extinct genomes, so the answer is structural: LineageArchive has no removal operation at all, not a guarded one and not a private one. Retention is a property of the interface rather than a rule someone has to remember, which is the only form of "keep extinct genomes indefinitely" that a later change cannot quietly undo. Four concepts assert that, with a positive control so the check is known to be live rather than vacuous. Admission requires the parent to be present, so ancestry never dangles and the parent graph is acyclic by construction: a cycle would need one of its members admitted before itself. A duplicate identity is refused rather than overwritten, because overwriting is deletion renamed. Organism identity and genome identity stay separate. A death is terminal for the organism and touches nothing about the genome it carried; ancestry, descendants and divergence all resolve afterwards. The quieter risk is calling something extinct that is merely unobserved. The archive reports living or absent and has no third answer: terminal extinction is a policy judgement over a reconciled watermark covering suspended members, eggs, spores and in-flight transfers, none of which this type can see, so the word does not appear in the API. Absence is also reversible, and a test shows a lineage regaining a carrier. Capacity is bounded and admission fails loudly at the limit, since refusing to record is not deleting but a silent drop would be. The roadmap lists an NPC-mutation decision as a dependency, and OPEN_QUESTIONS leaves it open until M12. It stays open: the archive records an origin event and never an actor, so whether an NPC may diverge changes nothing here. Two clang-tidy findings were fixed rather than suppressed. std::map members made the archive's move potentially throwing, because MSVC's map move constructor allocates; sorted vectors replaced them. A wrapper struct holding a Genome by value had the same problem, since ADR-0030 made Genome copy-only, so genomes are stored directly under their own id(). The redundant carrier tally went with it: carriers are counted from the organism records, so no second tally can drift. Native Release, clang-tidy analysis, ASan and format checks pass 21/21. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/biology/genome.hpp"
|
||||
#include "evo/core/types.hpp"
|
||||
|
||||
namespace evo::biology {
|
||||
// What the archive can establish about itself. There is deliberately no third
|
||||
// value: terminal extinction is a policy judgement over a reconciled world
|
||||
// watermark covering suspended members, eggs, spores and in-flight transfers,
|
||||
// none of which this type can see. Absence is not extinction.
|
||||
enum class LineageStatus : std::uint8_t { living, absent };
|
||||
struct OrganismRecord {
|
||||
std::uint64_t genome;
|
||||
Tick born;
|
||||
Tick died; // meaningful only once alive is false
|
||||
bool alive; // death is terminal; this never returns to true
|
||||
auto operator<=>(const OrganismRecord&) const = default;
|
||||
};
|
||||
enum class HistoryError : std::uint8_t {
|
||||
duplicate_genome,
|
||||
unknown_genome,
|
||||
unknown_parent,
|
||||
archive_full,
|
||||
duplicate_organism,
|
||||
unknown_organism,
|
||||
already_dead,
|
||||
invalid_identity,
|
||||
invalid_tick
|
||||
};
|
||||
inline constexpr std::size_t max_archived_genomes = 4'096;
|
||||
inline constexpr std::size_t max_archived_organisms = 65'536;
|
||||
|
||||
// Retains genomes and the organisms that carried them. There is no removal
|
||||
// operation: not a guarded one, not a private one. Retention is a property of
|
||||
// this interface rather than a rule a caller has to remember.
|
||||
class LineageArchive {
|
||||
public:
|
||||
// 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<void, HistoryError> admit(const Genome& genome);
|
||||
[[nodiscard]] std::expected<void, HistoryError> record_birth(std::uint64_t organism,
|
||||
std::uint64_t genome, Tick when);
|
||||
// Terminal for the organism, and nothing to do with the genome it carried.
|
||||
[[nodiscard]] std::expected<void, HistoryError> record_death(std::uint64_t organism, Tick when);
|
||||
|
||||
[[nodiscard]] std::expected<Genome, HistoryError> find(std::uint64_t genome) const;
|
||||
[[nodiscard]] std::expected<OrganismRecord, HistoryError>
|
||||
organism(std::uint64_t identity) const;
|
||||
// Oldest first, ending at the founder. Still resolves after every carrier dies.
|
||||
[[nodiscard]] std::expected<std::vector<std::uint64_t>, HistoryError>
|
||||
ancestry(std::uint64_t genome) const;
|
||||
[[nodiscard]] std::expected<std::vector<std::uint64_t>, HistoryError>
|
||||
children(std::uint64_t genome) const;
|
||||
// Zero when the two descend from different founders.
|
||||
[[nodiscard]] std::expected<std::uint64_t, HistoryError>
|
||||
common_ancestor(std::uint64_t left, std::uint64_t right) const;
|
||||
// Counted from the organism records themselves rather than kept alongside
|
||||
// them, so there is no second tally that could drift out of agreement.
|
||||
[[nodiscard]] std::expected<std::uint64_t, HistoryError>
|
||||
living_carriers(std::uint64_t genome) const;
|
||||
[[nodiscard]] std::expected<LineageStatus, HistoryError> status(std::uint64_t genome) const;
|
||||
[[nodiscard]] std::size_t archived() const noexcept {
|
||||
return genomes_.size();
|
||||
}
|
||||
[[nodiscard]] std::size_t recorded() const noexcept {
|
||||
return organisms_.size();
|
||||
}
|
||||
|
||||
private:
|
||||
struct ArchivedOrganism {
|
||||
std::uint64_t id;
|
||||
OrganismRecord record;
|
||||
};
|
||||
// Held sorted by identity, so a lookup is a binary search and the archive
|
||||
// keeps one record of each thing and no index that could disagree. Genomes
|
||||
// are stored directly rather than in a wrapper: a genome is copy-only by
|
||||
// ADR-0030, so an aggregate holding one would have a throwing move.
|
||||
std::vector<Genome> genomes_;
|
||||
std::vector<ArchivedOrganism> organisms_;
|
||||
};
|
||||
} // namespace evo::biology
|
||||
Reference in New Issue
Block a user