fix(runtime): isolate template context per render (#166)#627
Closed
fix(runtime): isolate template context per render (#166)#627
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.
Summary
Closes #166.
TemplateExecutor.render()/renderAndTrack()each create a childRuntimeContextviacreateTemplateContext(), but that helper eagerly snapshotted every parent variable into the child. That defeated the point of a child context: the snapshot went stale the moment the parent bound anything new, and becausebind()marks user variables immutable after the first write, the copied names could not be shadowed by template-local bindings. Concurrent renders off the same parent (two HTTP handlers rendering templates at once) could also observe each other's intermediate bindings through the snapshot surface.What changed
Sources/ARORuntime/Core/RuntimeContext.swift—createTemplateContext()no longer copies variables or services into the child. The child starts with empty storage; reads walk up to the parent via the existingresolve/resolveAny/servicefall-through; writes stay local and are discarded when the render completes.Tests/AROuntimeTests/TemplateEngineTests.swift— newTemplate Context Isolation Testssuite with 4 regression tests:Task.yieldinterleaving: no cross-child leakage, no leakage to parentTest plan
swift buildswift test— 1580/1580 passswift run aro run Examples/TemplateEngine— output unchanged