Dependency-aware lifecycle management for interdependent runtime modules and resources.
LifeTree is a small C++ library for modeling dependency relationships between runtime-owned objects and enforcing safe deletion semantics. It is designed for systems code that needs explicit answers to questions like:
- Can this module be deleted right now?
- Which live objects block deletion?
- What is the minimal safe deletion order?
- Which invariants should always hold after graph mutation?
The current codebase is intentionally compact. The focus is correctness, determinism, and inspectability rather than framework-heavy abstraction.
Many runtimes, plugin systems, and embedders allow objects to be registered, linked, unregistered, and destroyed at different times. Once dependencies appear between those objects, deletion stops being a bookkeeping problem and becomes a lifetime-safety problem.
LifeTree explores that problem directly with:
- explicit dependency edges (
consumer -> provider) - safe-delete checks with blocker diagnostics
- deterministic cascade planning
- cycle rejection on mutation
- invariant validation for debugging and tests
- add and remove modules
- add and remove dependency edges
- reject self-dependencies
- reject cycle-creating insertions
- check whether a module can be deleted safely
- report direct blockers
- analyze transitive impact before deletion
- compute a deterministic dependents-first cascade order
- explicit
unregisterModule(name)thendestroyModule(id)flow
deleteModule(name)is non-mutating when blocked by active dependents- when allowed,
deleteModule(name)performs unregister + destroy atomically unregisterModule(name)makes a module name-invisible but keeps the node deferred by stableModuleIddestroyModule(id)requires an unregistered node with no active dependents
- resolve name to stable id with
lookupModuleId - inspect node state by id with
getModuleById - check lifecycle state with
isModuleRegistered - track current name-visible population with
registeredModuleCount
- direct dependency and dependent queries
- transitive dependency and dependent traversal
- topological ordering
- roots, leaves, isolated-node, and edge-count helpers
- Graphviz DOT export
- invariant validation for edge consistency
lifetree/
|-- CMakeLists.txt
|-- README.md
|-- TEST_RESULTS.md
|-- PHASE1.md
|-- include/
| |-- lifetree.h
|-- src/
| |-- lifetree.cpp
| |-- demo.cpp
|-- tests/
| |-- lifetree_tests.cpp
|-- .gitignore
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure
./build/lifetree_demomkdir -p build
g++ -std=c++17 -Wall -Wextra -Wpedantic -Iinclude src/lifetree.cpp src/demo.cpp -o build/lifetree_demo
g++ -std=c++17 -Wall -Wextra -Wpedantic -Iinclude src/lifetree.cpp tests/lifetree_tests.cpp -o build/lifetree_tests
./build/lifetree_tests
./build/lifetree_demoThe current test suite covers:
- module add, duplicate handling, and invalid input
- linear dependency deletion constraints
- diamond dependency behavior
- cycle insertion rejection
- topological ordering constraints
- missing-node error handling
- dependency edge removal semantics
- transitive query correctness
- delete-analysis output correctness
- cascade deletion behavior
- graph stats and helper APIs
- invariant validation checks
- unregister/destroy lifecycle semantics
- id-based lifecycle observability semantics
deleteModulenon-mutation contract when blocked
The latest local run result is recorded in TEST_RESULTS.md.
LifeTree is being developed as a standalone systems project rather than as a runtime-specific patch set. The current implementation keeps the model small on purpose. The next stage is described in PHASE1.md.
This repository currently demonstrates the core lifecycle-safety model in a compact form. It is not yet a full runtime integration layer.