Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
75c59fa
fix for race condition in FileIndex.fileIndexOfFile
Martin521 Nov 15, 2024
d838f1b
fantomas
Martin521 Nov 15, 2024
7326da9
fixed ilverify baselines (just a single line number changed)
Martin521 Nov 15, 2024
e552abd
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Nov 19, 2024
09363e0
add release notes entry
Martin521 Nov 19, 2024
4bce3d3
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Nov 26, 2024
9bda5aa
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Nov 27, 2024
d5f1ab0
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Nov 29, 2024
63ee595
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Dec 2, 2024
aeb0921
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Dec 3, 2024
e462cb7
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Dec 3, 2024
fe1533a
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Dec 4, 2024
9ad499f
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Dec 4, 2024
51eb10a
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Dec 6, 2024
1e554d6
FileToIndex: Added unlocked read so that lock is entered for new file…
Martin521 Dec 6, 2024
f1abc28
update ilverify baselines (changed line numbers only)
Martin521 Dec 6, 2024
d4a64bd
Merge branch 'main' into fileindex-race
psfinaki Dec 9, 2024
932ad12
Fix ILVerify
vzarytovskii Dec 9, 2024
1b2b8b2
Merge remote-tracking branch 'upstream/main' into fileindex-race
Martin521 Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* 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))


### Added
Expand Down
69 changes: 37 additions & 32 deletions src/Compiler/Utilities/range.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
<Compile Include="Miscellaneous\MigratedOverloadTests.fs" />
<Compile Include="Miscellaneous\MigratedTypeCheckTests.fs" />
<Compile Include="Miscellaneous\GraphTests.fs" />
<Compile Include="Miscellaneous\FileIndex.fs" />
<Compile Include="Signatures\TestHelpers.fs" />
<Compile Include="Signatures\ModuleOrNamespaceTests.fs" />
<Compile Include="Signatures\RecordTests.fs" />
Expand Down
21 changes: 21 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/Miscellaneous/FileIndex.fs
Original file line number Diff line number Diff line change
@@ -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
[<Fact>]
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

Original file line number Diff line number Diff line change
Expand Up @@ -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]: : <StartupCode$FSharp-Compiler-Service>.$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<FSharp.Compiler.Text.Range>.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<FSharp.Compiler.Text.Range>.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]: : <StartupCode$FSharp-Compiler-Service>.$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,string>[], string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, string, string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, string, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<string,Microsoft.FSharp.Core.Unit>, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<bool,Microsoft.FSharp.Core.FSharpFunc`2<string,Microsoft.FSharp.Core.FSharpFunc`2<string,Microsoft.FSharp.Core.Unit>>>)][offset 0x0000034D][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : <StartupCode$FSharp-Compiler-Service>.$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<FSharp.Compiler.Text.Range>.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<FSharp.Compiler.Text.Range>.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]: : <StartupCode$FSharp-Compiler-Service>.$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]: : <StartupCode$FSharp-Compiler-Service>.$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<FSharp.Compiler.Text.Range>.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<FSharp.Compiler.Text.Range>.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]: : <StartupCode$FSharp-Compiler-Service>.$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,string>[], string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, string, string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, string, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<string,Microsoft.FSharp.Core.Unit>, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<bool,Microsoft.FSharp.Core.FSharpFunc`2<string,Microsoft.FSharp.Core.FSharpFunc`2<string,Microsoft.FSharp.Core.Unit>>>)][offset 0x000002F5][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : <StartupCode$FSharp-Compiler-Service>.$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<FSharp.Compiler.Text.Range>.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<FSharp.Compiler.Text.Range>.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]: : <StartupCode$FSharp-Compiler-Service>.$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack.
Expand Down
Loading