refactor(util): make layer graphs opaque and composable - #46089
Open
kitlangton wants to merge 3 commits into
Open
refactor(util): make layer graphs opaque and composable#46089kitlangton wants to merge 3 commits into
kitlangton wants to merge 3 commits into
Conversation
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.
Why
LayerNode's normal collection-based override APIs erased the relationship between a source and its replacement, so a supposedly closed, infallible Layer could be missing services or introduce errors. Name-based substitution and publicly exposed hoisted halves added further contracts that the types could not express.
This replaces that surface with a small algebra of declarations, ordered graphs, and checked substitutions while retaining deep overrides and shared-global/fresh-Location ownership.
What Changes
Overrides are checked when constructed, before they enter a stored or concatenated collection:
Instance construction now ends with one closed compilation, rather than hoisting, compiling two incomplete graphs, and manually placing
Layer.fresh:Nodegroup([a, b])condition ? a : bnode.replace(target)node.mapLayer(transform)Groups are not replaceable nodes. Same-named sibling declarations remain independent. Explicit method receivers prevent rebinding a weaker replacement method to a stronger declaration. Erased Layer contracts cannot hide construction requirements.
Lifetime Ownership
The compiler resolves one effective graph, checks reachable cycles and incompatible wiring, then builds ordinary Effect Layers. Shared-tag subgraphs, including their dependencies, use the enclosing memo map; remaining wiring receives one fresh map per build. Compiled wiring is memoized so shared DAGs do not expand into trees during acquisition.
Effect continues to own resource acquisition, reference counting, and finalization. Lazy LayerMaps retain the enclosing memo-map ancestry, and internal build metadata does not replace declared service outputs. Selected shared roots remain visible in the result.
The application builder prepends a lazy Location-map default and appends caller overrides, eliminating its original-graph pre-scan. A dependency introduced by an override now receives the same default binding naturally.
Scope
This intentionally replaces the internal assembly API: raw replacement tuples,
hoist,hasUnbound, and representation-field access are removed. Core, CLI, Server, SDK, and simulation callers are migrated, with a migration guide inpackages/util/docs/layer-node.md; HTTP contracts and UI behavior are unchanged.The stricter checks also make previously ambient fixture/profile dependencies explicit.
PersistentPty.configurednow returns a wired node, and simulation driver installation failure is explicitly fatal at the infallible platform HTTP seam.Verification
git diff --checkpass; targeted lint has no errors.