Repository navigation
Conversation
A macro or call block records the hashes of the names its parameters and body read at parse time; the capture shared by a frame's closures holds their union, passes it to the frame below, and the copy made when the frame ends keeps only those names. Includes and imports with context, blocks, applymacro and filters naming another filter or test by a non-constant read every name; self sites and an included template's top level keep the whole frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7pMTLZKmURPZ8DQAjj
The resolver's read list grew on every name use of every template, which cost the load benchmarks up to 8% more instructions. Reads are now kept only while a macro or call block is being parsed, and each one's are sorted and deduplicated in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7pMTLZKmURPZ8DQAjj
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7pMTLZKmURPZ8DQAjj
|
@codex review Generated by Claude Code |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 263db4b9d9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codex review on #758: a capture made for a closure that never escapes allocated its read list on the heap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7pMTLZKmURPZ8DQAjj
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DTQTriEsFrrBgcYNKDUUF4
Parity batch 3, group A, second PR: task 0375. Follows #751 (0373).
Problem
A macro kept past the frame it was defined in copied every name of that frame when the frame ended. Python closes over only the names the body reads. Copying everything made a kept closure in a frame of many macros slow to call, kept values alive that nothing reads, and closed reference cycles through containers the closure never touches (0373 item 4).
What changes
NameResolver::BeginReads/EndReads,AddUse,AddRead). Indirect reads are recorded too: the namespace of aset ns.attr, a filter or test that falls back to a value of its name, the gettext function of atrans, and the names given as constants tomap/select/reject/selectattr/rejectattr.AddReadOfAllstands for every name. It covers an include or import with context, a block,applymacro, and those filters when the name is not a constant.MacroStatement::m_bodyReads, checked byVisitRefs).ClosureCaptureholds the union of the reads of the closures sharing it and passes it on to the frame below.CollectNamesDownTocopies only those names.selfsites and an included template's top level still keep every name, as Jinja2's include context holds them all.Behaviour note: a host callable taking
*contextinside a kept closure now sees only the names the closure reads among its ended frames' locals. Python'spass_contextsees none of a macro's locals. This is recorded in the task file.Validation
generate.py --checkpasses. Python 3.12 / Jinja2 3.1.6.statements.macro_closure_sets_attr_of_frame_namespaceplus five more,loader.macro_closure_includes_with_frame_names,loader.macro_closure_imports_with_context;MacroTest.KeptClosureAppliesMacroByName.preflight --perfagainst 84be673 passes:Roles, rounds, CI
Roles: verifier (1 round). It found no rendering or lifetime finding in about 600 probe templates compared with Python and with 84be673, plus a clang-18 ASan+UBSan build and run. It blocked on Load instruction counts (+3 to +8%, because every template recorded every read). That is fixed in 3a5bf41 (reads recorded only inside macros, sorted in place) and 263db4b (hashes taken from the interned symbol; no merge when the reads are already held). The gate was then re-run green. CI red pushes: none (two pushes, both green). Codex: 1 finding, 1 fixed, 0 declined (P2: a heap read list per capture, now inline in 42cbb8a); the security review was requested but never started. Scratch merge with master 8e93fe8:
ctest -R 'parity|chat_templates'passes.Generated by Claude Code