Skip to content

fix(query): prevent cycles when analyzing hidden children#4659

Merged
WillLillis merged 1 commit intorelease-0.25from
backport-4614-to-release-0.25
Jul 30, 2025
Merged

fix(query): prevent cycles when analyzing hidden children#4659
WillLillis merged 1 commit intorelease-0.25from
backport-4614-to-release-0.25

Conversation

@tree-sitter-ci-bot
Copy link

Description

Backport of #4614 to release-0.25.

**Problem:** `query.c` compares the current analysis state with the
previous analysis state to see if they are equal, so that it can return
early if so. This prevents redundant work. However, the comparison
function here differs from the one used for sorted insertion/lookup in
that it does not check any state data other than the child index. This
is problematic because it leads to infinite analysis when hidden nodes
have cycles.

**Solution:** Remove the custom comparison function, and apply the
insertion/lookup comparison function in place of it.

**NOTE:** This commit also changes the comparison function slightly, so
that some comparisons are reordered. Namely, for performance, it returns
early if the lhs depth is less than the rhs depth. Is this acceptable?
Tests still pass and nothing hangs in my testing, but it still seems
sketchy. Returning early if the lhs depth is greater than the rhs depth
does seem to make query analysis hang, weirdly enough... Keeping the
depth checks at the end of the loop also works, but it introduces a
noticeable performance regression (for queries that otherwise wouldn't
have had analysis cycles, of course).

(cherry picked from commit 6850df9)
@WillLillis WillLillis merged commit e7f4dfc into release-0.25 Jul 30, 2025
12 checks passed
@WillLillis WillLillis deleted the backport-4614-to-release-0.25 branch July 30, 2025 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants