From dbe8f25883c52050cf21b8254896598c62add448 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 21:41:36 +0000 Subject: [PATCH 1/2] Initial plan From 96de71a8b44e55f6a7a5c9710598b24dbfba3818 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 22:13:40 +0000 Subject: [PATCH 2/2] Fix BOL anchor not setting base.runtextpos after position update When the beginning-of-line (BOL) anchor in TryFindNextPossibleStartingPosition finds a newline via IndexOf and advances pos, the updated position was never written back to base.runtextpos. This caused the match engine to retry from the original position, negating the vectorized IndexOf optimization for patterns like bare '^' with Multiline. Fix both the source generator (RegexGenerator.Emitter.cs) and the IL compiler (RegexCompiler.cs) to set base.runtextpos = pos after the BOL position update. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- .../gen/RegexGenerator.Emitter.cs | 1 + .../src/System/Text/RegularExpressions/RegexCompiler.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs index 1fb6aaf78f3fb6..69b3c1a6c9d47f 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs +++ b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs @@ -1106,6 +1106,7 @@ bool EmitAnchors() noMatchFoundLabelNeeded = true; Goto(NoMatchFound); } + writer.WriteLine("base.runtextpos = pos;"); } writer.WriteLine(); break; diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs index 529e9d37e43033..432c60689d8cf7 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs @@ -736,6 +736,11 @@ bool EmitAnchors() } Ldloc(pos); BltFar(returnFalse); + + // base.runtextpos = pos; + Ldthis(); + Ldloc(pos); + Stfld(RuntextposField); } MarkLabel(label);