From 6a93b9976d7f98673428ab5a4e2af96e02118d33 Mon Sep 17 00:00:00 2001 From: dotnet bot Date: Thu, 12 Dec 2024 07:32:19 -0800 Subject: [PATCH] Merge main to release/dev17.13 (#18131) * Backport :: Bugfix :: Support `ldelem.u8`, `ldelem.u` opcode aliases (#18081) (#18096) * Streamlining test deps a bit (#18022) * Streamlining test deps a bit * up * Format ILVerify output a bit (#18120) * fix for race condition in FileIndex.fileIndexOfFile (#18008) * fix for race condition in FileIndex.fileIndexOfFile * fantomas * fixed ilverify baselines (just a single line number changed) * add release notes entry * FileToIndex: Added unlocked read so that lock is entered for new files only * update ilverify baselines (changed line numbers only) * Fix ILVerify --------- Co-authored-by: Petr Co-authored-by: Vlad Zarytovskii * Update F# build version to 200 * Fix how much is trimmed from an interp string part (#18123) * Fix how much is trimmed from an interp string part Only trim last 2 characters if they are "%s" and the '%' is not escaped * Add release note --------- Co-authored-by: Adam Boniecki * Sink: report SynPat.ArrayOrList type (#18127) --------- Co-authored-by: Tomas Grosup Co-authored-by: Petr Co-authored-by: Martin <29605222+Martin521@users.noreply.github.com> Co-authored-by: Vlad Zarytovskii Co-authored-by: Adam Boniecki <20281641+abonie@users.noreply.github.com> Co-authored-by: Adam Boniecki Co-authored-by: Alex Berezhnykh Co-authored-by: Kevin Ransom (msft) --- .../.FSharp.Compiler.Service/9.0.200.md | 4 +- eng/Versions.props | 2 +- src/Compiler/Checking/CheckPatterns.fs | 1 + .../Checking/Expressions/CheckExpressions.fs | 2 +- src/Compiler/Utilities/range.fs | 69 ++++++++++--------- .../BasicProvider.Tests.fsproj | 1 - .../ComboProvider.Tests.fsproj | 1 - .../FSharp.Compiler.ComponentTests.fsproj | 1 + .../Language/InterpolatedStringsTests.fs | 11 +++ .../Miscellaneous/FileIndex.fs | 21 ++++++ tests/ILVerify/ilverify.ps1 | 4 +- ...y_FSharp.Compiler.Service_Debug_net9.0.bsl | 2 +- ....Compiler.Service_Debug_netstandard2.0.bsl | 2 +- ...FSharp.Compiler.Service_Release_net9.0.bsl | 2 +- ...ompiler.Service_Release_netstandard2.0.bsl | 2 +- 15 files changed, 82 insertions(+), 43 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Miscellaneous/FileIndex.fs diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index 7c7f9652b19..33125ff07ed 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -15,7 +15,8 @@ * Fix locals allocating for the special `copyOfStruct` defensive copy ([PR #18025](https://github.com/dotnet/fsharp/pull/18025)) * Fix lowering of computed array expressions when the expression consists of a simple mapping from a `uint64` or `unativeint` array. [PR #18081](https://github.com/dotnet/fsharp/pull/18081) * Add missing nullable-metadata for C# consumers of records,exceptions and DU subtypes generated from F# code. [PR #18079](https://github.com/dotnet/fsharp/pull/18079) - +* Fix a race condition in file book keeping in the compiler service ([#18008](https://github.com/dotnet/fsharp/pull/18008)) +* Fix trimming '%' characters when lowering interpolated string to a concat call [PR #18123](https://github.com/dotnet/fsharp/pull/18123) ### Added @@ -25,6 +26,7 @@ * Added type conversions cache, only enabled for compiler runs, guarded by language version preview ([PR #17668](https://github.com/dotnet/fsharp/pull/17668)) * Added project property ParallelCompilation which turns on graph based type checking, parallel ILXGen and parallel optimization. By default on for users of langversion=preview ([PR #17948](https://github.com/dotnet/fsharp/pull/17948)) * Adding warning when consuming generic method returning T|null for types not supporting nullness (structs,anons,tuples) ([PR #18057](https://github.com/dotnet/fsharp/pull/18057)) +* Sink: report SynPat.ArrayOrList type ([PR #18127](https://github.com/dotnet/fsharp/pull/18127)) ### Changed diff --git a/eng/Versions.props b/eng/Versions.props index 0245a0d620c..cd72f859965 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -184,7 +184,7 @@ 3.1.0 5.0.0-preview.7.20364.11 5.0.0-preview.7.20364.11 - 17.4.0 + 17.11.1 13.0.3 1.0.0-beta2-dev3 2.18.48 diff --git a/src/Compiler/Checking/CheckPatterns.fs b/src/Compiler/Checking/CheckPatterns.fs index 3f97cf81780..0c496517fd4 100644 --- a/src/Compiler/Checking/CheckPatterns.fs +++ b/src/Compiler/Checking/CheckPatterns.fs @@ -313,6 +313,7 @@ and TcPat warnOnUpper (cenv: cenv) env valReprInfo vFlags (patEnv: TcPatLinearEn TcPat warnOnUpper cenv env None vFlags patEnv ty p | SynPat.ArrayOrList (isArray, args, m) -> + CallExprHasTypeSink cenv.tcSink (m, env.NameEnv, ty, env.AccessRights) TcPatArrayOrList warnOnUpper cenv env vFlags patEnv ty isArray args m | SynPat.Record (flds, m) -> diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index b13e3d01d12..16dc49c1a61 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -174,7 +174,7 @@ let (|WithTrailingStringSpecifierRemoved|) (s: string) = let i = s.AsSpan(0, s.Length - 2).LastIndexOfAnyExcept '%' let diff = s.Length - 2 - i if diff &&& 1 <> 0 then - s[..i] + s[..s.Length - 3] else s else diff --git a/src/Compiler/Utilities/range.fs b/src/Compiler/Utilities/range.fs index 6d0002a97ba..09633136dbe 100755 --- a/src/Compiler/Utilities/range.fs +++ b/src/Compiler/Utilities/range.fs @@ -196,38 +196,43 @@ type FileIndexTable() = match fileToIndexTable.TryGetValue filePath with | true, idx -> idx | _ -> - - // Try again looking for a normalized entry. - let normalizedFilePath = - if normalize then - FileSystem.NormalizePathShim filePath - else - filePath - - match fileToIndexTable.TryGetValue normalizedFilePath with - | true, idx -> - // Record the non-normalized entry if necessary - if filePath <> normalizedFilePath then - lock fileToIndexTable (fun () -> fileToIndexTable[filePath] <- idx) - - // Return the index - idx - - | _ -> - lock fileToIndexTable (fun () -> - // Get the new index - let idx = indexToFileTable.Count - - // Record the normalized entry - indexToFileTable.Add normalizedFilePath - fileToIndexTable[normalizedFilePath] <- idx - - // Record the non-normalized entry if necessary - if filePath <> normalizedFilePath then - fileToIndexTable[filePath] <- idx - - // Return the index - idx) + // If a write operation can happen, we have to lock the whole read-check-write to avoid race conditions + lock fileToIndexTable + <| fun () -> + match fileToIndexTable.TryGetValue filePath with + | true, idx -> idx + | _ -> + + // Try again looking for a normalized entry. + let normalizedFilePath = + if normalize then + FileSystem.NormalizePathShim filePath + else + filePath + + match fileToIndexTable.TryGetValue normalizedFilePath with + | true, idx -> + // Record the non-normalized entry if necessary + if filePath <> normalizedFilePath then + fileToIndexTable[filePath] <- idx + + // Return the index + idx + + | _ -> + // Get the new index + let idx = indexToFileTable.Count + + // Record the normalized entry + indexToFileTable.Add normalizedFilePath + fileToIndexTable[normalizedFilePath] <- idx + + // Record the non-normalized entry if necessary + if filePath <> normalizedFilePath then + fileToIndexTable[filePath] <- idx + + // Return the index + idx member t.IndexToFile n = if n < 0 then diff --git a/tests/EndToEndBuildTests/BasicProvider/BasicProvider.Tests/BasicProvider.Tests.fsproj b/tests/EndToEndBuildTests/BasicProvider/BasicProvider.Tests/BasicProvider.Tests.fsproj index 4e4aef01856..4bc1b805799 100644 --- a/tests/EndToEndBuildTests/BasicProvider/BasicProvider.Tests/BasicProvider.Tests.fsproj +++ b/tests/EndToEndBuildTests/BasicProvider/BasicProvider.Tests/BasicProvider.Tests.fsproj @@ -21,7 +21,6 @@ content\myfiles\ - diff --git a/tests/EndToEndBuildTests/ComboProvider/ComboProvider.Tests/ComboProvider.Tests.fsproj b/tests/EndToEndBuildTests/ComboProvider/ComboProvider.Tests/ComboProvider.Tests.fsproj index d4d410bacd4..69a4cd8855d 100644 --- a/tests/EndToEndBuildTests/ComboProvider/ComboProvider.Tests/ComboProvider.Tests.fsproj +++ b/tests/EndToEndBuildTests/ComboProvider/ComboProvider.Tests/ComboProvider.Tests.fsproj @@ -18,7 +18,6 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 4338fbd807b..e8f044ed2f4 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -317,6 +317,7 @@ + diff --git a/tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs index b4e2cc8eab9..e7c18f0d679 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs @@ -130,6 +130,17 @@ type Foo () = |> compile |> shouldSucceed + [] + let ``Percent signs and format specifiers with string expression`` () = + Fsx """ +let x = "abc" +let s = $"%%%s{x}%%" +printfn "%s" s + """ + |> compileExeAndRun + |> shouldSucceed + |> withStdOutContains "%abc%" + [] // Test different number of interpolated string parts [] diff --git a/tests/FSharp.Compiler.ComponentTests/Miscellaneous/FileIndex.fs b/tests/FSharp.Compiler.ComponentTests/Miscellaneous/FileIndex.fs new file mode 100644 index 00000000000..0d5caabb982 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Miscellaneous/FileIndex.fs @@ -0,0 +1,21 @@ +module Miscellaneous.FileIndex + +open FSharp.Compiler.Text +open System.Threading.Tasks +open Xunit + +// This is a regression test for a bug that existed in FileIndex.fileIndexOfFile +[] +let NoRaceCondition() = + let parallelOptions = ParallelOptions() + let mutable count = 10000 + while count > 0 do + let file = $"test{count}.fs" + let files = Array.create 2 file + let indices = Array.create 2 -1 + let getFileIndex i = indices[i] <- FileIndex.fileIndexOfFile files[i] + Parallel.For(0, files.Length, parallelOptions, getFileIndex) |> ignore + if indices[0] <> indices[1] then + Assert.Fail $"Found different indices: {indices[0]} and {indices[1]}" + count <- count - 1 + \ No newline at end of file diff --git a/tests/ILVerify/ilverify.ps1 b/tests/ILVerify/ilverify.ps1 index 23618d1a1b1..ab1e2d316c2 100644 --- a/tests/ILVerify/ilverify.ps1 +++ b/tests/ILVerify/ilverify.ps1 @@ -162,7 +162,7 @@ foreach ($project in $projects.Keys) { } else { Write-Host "ILverify output does not match baseline, differences:" - $cmp | Format-Table | Out-String | Write-Host + $cmp | Format-Table -AutoSize -Wrap | Out-String | Write-Host # Update baselines if TEST_UPDATE_BSL is set to 1 if ($env:TEST_UPDATE_BSL -eq "1") { @@ -185,4 +185,4 @@ if ($failed) { exit 1 } -exit 0 \ No newline at end of file +exit 0 diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl index c527d99ccf5..03328728f4c 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl @@ -59,7 +59,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x0000000B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x00000021][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000CD][found Char] Unexpected type on the stack. -[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@543::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. +[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@548::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000037][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000043][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl index 7d4eff968ac..a863787a54e 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl @@ -84,7 +84,7 @@ [IL]: Error [StackUnexpected]: : Internal.Utilities.FSharpEnvironment+probePathForDotnetHost@321::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000028][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.SimulatedMSBuildReferenceResolver+Pipe #6 input at line 68@68::FSharp.Compiler.CodeAnalysis.ILegacyReferenceResolver.Resolve([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyResolutionEnvironment, [S.P.CoreLib]System.Tuple`2[], string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, string, string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, string, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>>)][offset 0x0000034D][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000CD][found Char] Unexpected type on the stack. -[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@543::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. +[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@548::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000037][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000043][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl index a930478a45e..d1f7525cef2 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl @@ -85,7 +85,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x0000000B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x00000021][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000B6][found Char] Unexpected type on the stack. -[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@543::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. +[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@548::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000035][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000041][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl index b97ede137b1..9de22b5cd79 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl @@ -111,7 +111,7 @@ [IL]: Error [StackUnexpected]: : Internal.Utilities.FSharpEnvironment::probePathForDotnetHost@320([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x0000002A][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.SimulatedMSBuildReferenceResolver+SimulatedMSBuildResolver@68::FSharp.Compiler.CodeAnalysis.ILegacyReferenceResolver.Resolve([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyResolutionEnvironment, [S.P.CoreLib]System.Tuple`2[], string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, string, string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, string, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>>)][offset 0x000002F5][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000B6][found Char] Unexpected type on the stack. -[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@543::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. +[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@548::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000035][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000041][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack.