Repository navigation
self: ended include blocks, scoped-block self, module self export (0207) - #551
Merged
Merged
Conversation
…(0207) A stack hands its blocks to the self made of them when it ends, so a self an include stored renders the include's blocks. A scoped block that sees more than its template's top level gets a self of what it sees, as Jinja2's TemplateReference of the block's derived context. Modules export a top-level self, and self is iterable. Leftovers filed as 0209. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TtbXoDehzWkexrJD9ZEBiK
…0207) A block rendered through an ended self resolves self to the ended blocks, and super() holds the stack's SelfBlocks instead of a raw pointer, so one stored past an include no longer reads a dead stack. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TtbXoDehzWkexrJD9ZEBiK
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TtbXoDehzWkexrJD9ZEBiK
rmorozov
marked this pull request as ready for review
October 17, 2026 17:41
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.
Requested by Ruslan · project thread
Before: a
selfstored by an include and called after the include ended rendered the caller's block of that name (OB), and a storedsuperread a dead stack (ASan stack-use-after-return, Debug segfault).self.c()from a scoped block in a loop renderedcwithout the loop variable.{% import 'm' as l %}{{ l.self }}was empty for a module that setsself, andself is iterablewas False.After: all of these match Jinja2 3.1.6. The stored
selfrenders the include's blocks (IB), includingselfandsuper()inside them. A scoped block passes the names it sees to the blocks itsselfrenders, scoped or not. Modules export a top-levelself, andself is iterableis True.How:
BlocksStackgets a sharedSelfBlocksholder, created with the firstselforsupermade of it. When the stack ends, its destructor moves its blocks into the holder. Theselfandsupercallables hold the holder (shared ownership, no raw stack pointer), so they compare frames against the live stack and render the ended blocks once it is gone; this also closes the address-reuse hazard of the old pointer compare.RenderContext::FindSelfbuilds aselfat the scoped block's depth when the block sees more than its template's top level. It is cached per block call in a newm_blockSelfof the block's context.ImportNamesno longer skipsself, which was a leftover from whenselflived in the scope.Corpus: three lines of task 0207 removed from
divergences/loader.txt, plus 19 new cases incases/loader.py. Two cases are pinned as deliberate under 0165, the same choice as for macros: aselfkept past its include does not keep the include's names, and one kept past its scoped block loses the loop variable. Two more are pinned under the new task 0211, a quirk where Jinja2's block reads the top-levelselfwhen the block storesselfonly in a nested scope. 0211 also lists the verifier's pre-existing findings: parent-only blocks are missing from a top-levelselfin an extending template, an extending module does not exportself, andcycler is iterable.Perf:
preflight.sh --perfstays within +0.4% on every benchmark. The scoped-in-loop pattern now builds oneselfper block call that uses it; before this change that pattern rendered the wrong output.Roles: main session implemented; verifier ran for 1 round, finding 1 blocking issue (
selfundefined inside a block rendered through an endedself) and the pre-existing stored-superUAF. Both are fixed in f330e4d and covered by corpus rows. Then ASan+UBSan (clang 18) on the full suite came back clean. Red pushes: none yet.Generated by Claude Code