Use _quarto.modules registry instead of redundant module requires in filters#14702
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
editor-support crossref runs quarto-init.lua then crossref.lua as two separate pandoc --lua-filter args. quarto-init.lua's Meta handler (read_includes) runs before crossref.lua ever imports import_all.lua, so _quarto.modules was nil at that point. Revert to a local require.
|
This is a really great LLM task! Maybe it's worth taking a longer look at the Lua files and trying to move more of those files out. Although, make sure to remember that these Lua changes are not truly tested in the test suite, and that we should probably do a bit of manual testing with the actual software bundle. |
You mean testing the built quarto.exe right ? Not just the dev version ?
Yes it was definitely a good task, and I plan to follow up. We have a little room, but it seems LLM had ideas to improve it with more refactor. Though I wanted to split tasks to be more manageable in testing. It seems this specific PR refactor is safe. |
|
I triggered the build action to see if at least all bundles can be built: https://github.com/quarto-dev/quarto-cli/actions/runs/29572067222 And we can download artifacts to test |
|
All green - artifacts are building - I'll manually test. |
|
With help of 🤖 , I tested with the packaged Windows build from that run. All good! SO I am merging. detailsThe registry swap is a straight lookup replacement ( So I focused testing there:
Everything held up. Side note for anyone testing on Windows: extracting the build zip into a deeply nested path trips Windows' MAX_PATH and looks exactly like a Lua "module not found" error - nothing to do with this PR, just keep the extraction path short. |
When packaging the Lua filter bundle, Pandoc's Lua interpreter enforces a 200 top-level-local-variable limit (
MAXVARS) across all inlined filter files.mainis already at that ceiling with zero headroom, which surfaced while evaluating room to bump the bundled Pandoc to 3.10.modules/import_all.luaalready centralizes mostmodules/*requires into a single_quarto.modulesregistry table, at no additional local-slot cost no matter how many modules get registered. But ~24 inlined filter files still redundantly re-required the same modules (constants,patterns,lightbox,scope,typst) as fresh top-level locals instead of referencing the existing registry - each costing one slot in the shared budget.This replaces those redundant
local X = require("modules/Y")aliases with direct_quarto.modules.Yaccess at every call site. Pure access-path change to an already-loaded singleton table - no logic or API change.26 alias declarations removed across 24 files. Packaged bundle
main.luatop-level local count drops from ~200 to 173.Verified manually: packaged
quarto checkpasses with no "too many local variables" error, packaged renders of lightbox (HTML) and typst (PDF) fixtures succeed, and smoke-all chunks covering the edited filters (2022, 2023/01) pass locally.Follow up on #14664 where we hit the limit