Skip to content

Stop pattern matching when the state context is canceled - #566

Open
draarivpatel-ui wants to merge 1 commit into
yuin:masterfrom
draarivpatel-ui:add-pattern-matching-context-stop
Open

draarivpatel-ui wants to merge 1 commit into
yuin:masterfrom
draarivpatel-ui:add-pattern-matching-context-stop

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Summary

  • add pm.FindWithStop, keeping existing pm.Find behavior unchanged
  • check cancellation incrementally inside the recursive matcher, %b scans, and back-reference comparisons
  • pass the LState context from string.find, match, gmatch, and gsub so cancellation no longer waits for the pattern call to finish
  • add a regression test that cancels a pathological %b() scan

Contributes to #559. This intentionally does not include the separate gsub allocation optimization because that part is already being addressed in #558.

Validation

  • go test ./ -run '^TestContextCancelDuringPatternMatch$' -count=1
  • go test ./... -count=1

Pattern matching can spend unbounded time inside one Go call, so the
VM never reaches its instruction boundary context check. Thread a stop
channel through the matcher and pass the state context from string
library calls while keeping pm.Find behavior unchanged.

Contributes to yuin#559.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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