Tag delay optimization#179
Draft
hhugo wants to merge 3 commits into
Draft
Conversation
3 tasks
When a Set_position tag fires on every transition entering a cycle
state, remove it from those transitions and emit Set_position with
offset 1 (pos - 1) on exit transitions. This turns O(n) tag writes
per loop into O(1) on exit.
Handles multi-state cycles via SCC analysis (Tarjan's algorithm) and
multi-exit cycles: exits from other cycle states are safe when they
only reach rules that don't read the tag.
Set_position { cell; offset } with offset 0 for current position and
offset 1 for previous code point (subtracted from pos).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
@toots, this PR is ready for review |
Tags are allocated during regexp_of_pattern in the PPX, not during compile_re. The tag_starts approach incorrectly mapped all tags to rule 0. Use an NFA walk (tag_owners) to correctly discover which rule each tag belongs to. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
With the tag binding on rule 1 (not rule 0), incorrect tag ownership would allow an unsafe delay: the check would see rule 0 as unreachable from the non-s exit (correct) but miss that rule 1 IS reachable there. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Set_positiontag fires on every transition entering a cycle state, remove it from those transitions and emitSet_positionwith offset 1 (pos - 1) on exit transitions. Turns O(n) tag writes per loop into O(1) on exit.Set_position { cell; offset }with offset 0 for current position and offset 1 for previous code point (subtracted from pos).Test plan
test_realistic.mlmulti-rule lexer baseline🤖 Generated with Claude Code