regexp: fix latent stale flag bug after NFA prefix fast-forward#80266
regexp: fix latent stale flag bug after NFA prefix fast-forward#80266le0pard wants to merge 1 commit into
Conversation
|
This PR (HEAD: 3cdf6af) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/797020. Important tips:
|
3cdf6af to
77808ec
Compare
77808ec to
37a2398
Compare
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/797020. |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/797020. |
|
This PR (HEAD: 37a2398) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/797020. Important tips:
|
|
Message from Jake Bailey: Patch Set 2: Commit-Queue+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/797020. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 2: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2026-07-05T16:21:30Z","revision":"651d35645ed4abc256e55f1437164bbfddc43b45"} Please don’t reply on this GitHub thread. Visit golang.org/cl/797020. |
|
Message from Jake Bailey: Patch Set 2: -Commit-Queue (Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_3946988>) Please don’t reply on this GitHub thread. Visit golang.org/cl/797020. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 2: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/797020. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 2: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/797020. |
In
exec.go, when the NFA machine utilizesm.re.prefixto fast-forward theposcursor, it updates the runes (r,r1) but fails to recalculate theflagcontext for the new position. This oversight causes the subsequentm.add()call to evaluateInstEmptyWidthusing the stale boundary context from the pre-jump position.Interestingly, this was implemented correctly in the
OnePassengine (doOnePassexplicitly callsflag = i.context(pos)after fast-forwarding), but was missed in the NFAmatch()loop.Currently, this NFA bug is dormant because
syntax.(*Prog).Prefix()halts atInstEmptyWidth, meaning any regex starting with a boundary assertion will have an empty prefix and bypass the fast-forward loop entirely. However, if the prefix extractor is ever optimized to identify literal prefixes after empty-width assertions, this stale flag will immediately cause false positives and negatives.This commit adds the missing
flag = i.context(pos)assignment to the NFA match loop. A test is also included which artificially injects a prefix into a boundary-prefixedRegexpto simulate a smarter compiler and prove the stale flag evaluation.Found it while was busy with re2js replacing thread pool with a sparse array (because js env have no threads) - le0pard/re2js#48