Split TreeContext into TreeConfig and OperationState#424
Draft
Split TreeContext into TreeConfig and OperationState#424
Conversation
`TreeContext` currently holds four fields with fundamentally different lifecycles: - **Setup fields** (SchemaClient, PoolFactory): fixed at tree creation, immutable, shared across all entries and operations - **Operation fields** (ExplicitDeletes, NonRevertiveInfos): reset and accumulated during each operation (import pass, transaction, validation), copied when branching To callers, all four fields look identical. There is no semantic distinction between "this never changes" and "this accumulates per-operation." This creates three problems: 1. **Unclear semantics**: Code reading `e.GetTreeContext().NonRevertiveInfo()` cannot immediately tell whether this reads global config or operation-specific state. 2. **Silent mutations**: Processors and operations mutate `ExplicitDeletes` and `NonRevertiveInfos` as side effects of traversal (e.g., `ImportConfigProcessor.Run` calls `e.GetTreeContext().ExplicitDeletes().Add(...)`). A reader must trace deep into multiple call stacks to understand what state is being mutated. 3. **Accidental sharing**: If a future refactor accidentally fails to deep-copy mutable state during tree branching (DeepCopy), the bug is silent — two branches silently share mutations. ## Solution Split `TreeContext` into two separate concerns: 1. **TreeConfig interface**: immutable, created once per tree root, shared by all entries. Contains SchemaClient and PoolFactory. 2. **OperationState interface**: mutable, created once per tree root but deep-copied when the tree is branched. Contains ExplicitDeletes and NonRevertiveInfos. The `TreeContext` interface is simplified to a lifecycle marker (DeepCopy plus the two getters), and all flat data-access methods are removed. A big-bang migration updates all call sites at once. DeepCopy reuses the same TreeConfig instance and deep-copies OperationState. Benefits: - **Locality**: Reading `GetTreeConfig()` tells you "this is fixed;" reading `GetOperationState()` tells you "this accumulates." - **Testability**: OperationState can be tested in isolation from schema and pool setup. - **Safety**: The distinction is enforced at the interface level, reducing the risk of accidental mutation sharing. - **Future leverage**: Sets the stage for Phase 2, where OperationState can be threaded explicitly through processors and transaction flows.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TreeContextcurrently holds four fields with fundamentally different lifecycles:To callers, all four fields look identical. There is no semantic distinction between "this never changes" and "this accumulates per-operation." This creates three problems:
e.GetTreeContext().NonRevertiveInfo()cannot immediately tell whether this reads global config or operation-specific state.ExplicitDeletesandNonRevertiveInfosas side effects of traversal (e.g.,ImportConfigProcessor.Runcallse.GetTreeContext().ExplicitDeletes().Add(...)). A reader must trace deep into multiple call stacks to understand what state is being mutated.Solution
Split
TreeContextinto two separate concerns:The
TreeContextinterface is simplified to a lifecycle marker (DeepCopy plus the two getters), and all flat data-access methods are removed. A big-bang migration updates all call sites at once. DeepCopy reuses the same TreeConfig instance and deep-copies OperationState.Benefits:
GetTreeConfig()tells you "this is fixed;" readingGetOperationState()tells you "this accumulates."