Repository navigation
Conversation
robobun
force-pushed
the
robobun/selector-compiler-iterative
branch
from
September 6, 2026 07:28
189d614 to
4340f76
Compare
Compiler::compile_nodes recursed once per combinator, so a selector such as "p p p ..." with tens of thousands of compounds overflowed the native stack in compile(). The derived drop glue for the AST recursed the same way. Both now walk the tree with an explicit work list.
robobun
force-pushed
the
robobun/selector-compiler-iterative
branch
from
September 22, 2026 15:57
4340f76 to
0344121
Compare
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.
Problem
"p p p ... p"with 30000 compounds, parses fine but overflows the native stack when the program is compiled. In bun this is a silent SIGSEGV inHTMLRewriter.transform().Compiler::compile_nodes(src/selectors_vm/compiler.rs) recurses throughcompile_descendantsonce per combinator. The derived drop glue for the AST recurses the same way when anAstis dropped without compilation.Fix
compile_nodeswalks the tree with an explicit work list. Each node reserves the address ranges for its children and descendants first, then queues them. Siblings still land in one contiguous range.Astgets aDropimpl that moves the tree into a work list before the nodes are freed.Astis the only owner of a node tree, so the compiler still destructures nodes by move.deep_combinator_chaincompiles a 100k deep chain for bothand>, walks the program link by link, and drops an uncompiled AST. Without the compiler change, or without theDropimpl, the test aborts with a stack overflow.cargo test --features _integration_test: 208 + 3 + 38 + 2 pass.cargo clippy --all-targets: no new warnings.cargo fmt --check: clean.Cost
Compile-only benchmark: 100 pre-parsed selectors, a fresh
HtmlRewriterper 9-byte document, release build, min of 6 interleaved runs, against e1a306d.div.cN)aN b c d > e f g h)The work list holds no entry until a node has children, so a flat selector list allocates nothing extra.
Branches
bunhead (e1a306d) plus one commit. It was rebased on 2026-09-22. It cherry-picks clean ontorobobun/31756292/not-de-morgan(selectors_vm: apply De Morgan's laws to :not() #9).robobun/selector-compiler-iterative-v2.7.2(5702629 = 725ce49 plus one commit). HTMLRewriter: compile long combinator chains without a native stack overflow bun#41475 pins that commit while Bun's main is on the v2.7.2 lineage, and moves to this branch after the v3.0.1 move lands in Bun.