From 6f9a19158b61668a497d96a2620f8c7f8b4c1f7d Mon Sep 17 00:00:00 2001 From: Tuomas Hietanen Date: Tue, 28 Nov 2023 14:33:13 +0000 Subject: [PATCH 1/4] Less RegEx construction on recursive method --- src/Compiler/Utilities/sformat.fs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Utilities/sformat.fs b/src/Compiler/Utilities/sformat.fs index 73497ce6bcb..07b7be6bb5a 100644 --- a/src/Compiler/Utilities/sformat.fs +++ b/src/Compiler/Utilities/sformat.fs @@ -1056,6 +1056,8 @@ module Display = else let messageRegexPattern = @"^(?
.*?)(?.*?)(?.*)$"
                 let illFormedBracketPattern = @"(?
                                     // make sure we don't have any stray brackets
                                     let strayClosingMatch =
-                                        System.Text.RegularExpressions.Regex.IsMatch(remaingPropertyText, illFormedBracketPattern)
+                                        illFormedBracketPatternLookup.IsMatch remaingPropertyText
 
                                     if strayClosingMatch then
                                         None

From b05b9adffbe1a8bfd5ed82fe64d3a2906afd434e Mon Sep 17 00:00:00 2001
From: Tuomas Hietanen 
Date: Tue, 28 Nov 2023 14:44:19 +0000
Subject: [PATCH 2/4] mandatory Fantomas commit

---
 src/Compiler/Utilities/sformat.fs | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/Compiler/Utilities/sformat.fs b/src/Compiler/Utilities/sformat.fs
index 07b7be6bb5a..f2b4c411ca8 100644
--- a/src/Compiler/Utilities/sformat.fs
+++ b/src/Compiler/Utilities/sformat.fs
@@ -1057,7 +1057,9 @@ module Display =
                 let messageRegexPattern = @"^(?
.*?)(?.*?)(?.*)$"
                 let illFormedBracketPattern = @"(?
                                     // make sure we don't have any stray brackets
-                                    let strayClosingMatch =
-                                        illFormedBracketPatternLookup.IsMatch remaingPropertyText
+                                    let strayClosingMatch = illFormedBracketPatternLookup.IsMatch remaingPropertyText
 
                                     if strayClosingMatch then
                                         None

From 56d3f2a3d6034b6e4e88b2f9eeabab109cc95c8c Mon Sep 17 00:00:00 2001
From: Tuomas Hietanen 
Date: Thu, 30 Nov 2023 16:37:22 +0000
Subject: [PATCH 3/4] moved regexes to a static value

---
 src/Compiler/Utilities/sformat.fs | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/Compiler/Utilities/sformat.fs b/src/Compiler/Utilities/sformat.fs
index f2b4c411ca8..b4f638e819f 100644
--- a/src/Compiler/Utilities/sformat.fs
+++ b/src/Compiler/Utilities/sformat.fs
@@ -969,6 +969,13 @@ module Display =
         && (ty.GetGenericTypeDefinition() = typedefof>
             || ty.GetGenericTypeDefinition() = typedefof>)
 
+    let messageRegexLookup =
+        @"^(?
.*?)(?.*?)(?.*)$"
+        |> System.Text.RegularExpressions.Regex
+
+    let illFormedBracketPatternLookup =
+        @"(? System.Text.RegularExpressions.Regex
+
     // showMode = ShowTopLevelBinding on the outermost expression when called from fsi.exe,
     // This allows certain outputs, e.g. objects that would print as  to be suppressed, etc. See 4343.
     // Calls to layout proper sub-objects should pass showMode = ShowAll.
@@ -1054,12 +1061,6 @@ module Display =
             if isNull txt || txt.Length <= 1 then
                 None
             else
-                let messageRegexPattern = @"^(?
.*?)(?.*?)(?.*)$"
-                let illFormedBracketPattern = @"(?
Date: Thu, 30 Nov 2023 19:02:53 +0000
Subject: [PATCH 4/4] Expected growth in size exactly 2x 256

---
 tests/AheadOfTime/Trimming/check.ps1 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/AheadOfTime/Trimming/check.ps1 b/tests/AheadOfTime/Trimming/check.ps1
index 8528710b76f..4b9dcaebf16 100644
--- a/tests/AheadOfTime/Trimming/check.ps1
+++ b/tests/AheadOfTime/Trimming/check.ps1
@@ -42,4 +42,4 @@ function CheckTrim($root, $tfm, $outputfile, $expected_len) {
 CheckTrim -root "SelfContained_Trimming_Test" -tfm "net8.0" -outputfile "FSharp.Core.dll" -expected_len 287232
 
 # Check net7.0 trimmed assemblies
-CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net8.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 8820736
+CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net8.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 8821248