Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions src/fsharp/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module internal FSharp.Compiler.CompilerConfig

open System
open System.Collections.Generic
open System.Collections.Concurrent
open System.Diagnostics
open System.IO
open System.Text
Expand Down Expand Up @@ -177,8 +178,8 @@ type IRawFSharpAssemblyData =

/// Cache of time stamps as we traverse a project description
type TimeStampCache(defaultTimeStamp: DateTime) =
let files = Dictionary<string, DateTime>()
let projects = Dictionary<IProjectReference, DateTime>(HashIdentity.Reference)
let files = ConcurrentDictionary<string, DateTime>()
let projects = ConcurrentDictionary<IProjectReference, DateTime>(HashIdentity.Reference)
member cache.GetFileTimeStamp fileName =
let ok, v = files.TryGetValue fileName
if ok then v else
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/ExtensionTyping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ module internal ExtensionTyping =
/// appears that the laziness likely serves no purpose and could be safely removed.
and ProvidedTypeContext =
| NoEntries
// The dictionaries are safe because the ProvidedType with the ProvidedTypeContext are only accessed one thread at a time during type-checking.
| Entries of Dictionary<ProvidedType, ILTypeRef> * Lazy<Dictionary<ProvidedType, obj>>

static member Empty = NoEntries
Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ and TypeDefsBuilder() =
tdefs.Add (tdef.Name, (idx, (new TypeDefBuilder(tdef, tdefDiscards), eliminateIfEmpty)))

type AnonTypeGenerationTable() =
// Dictionary is safe here as it will only be used during the codegen stage - will happen on a single thread.
let dict = Dictionary<Stamp, (ILMethodRef * ILMethodRef[] * ILType)>(HashIdentity.Structural)
member __.Table = dict

Expand All @@ -1456,6 +1457,7 @@ type AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbu
let gtdefs= new TypeDefsBuilder()

// The definitions of top level values, as quotations.
// Dictionary is safe here as it will only be used during the codegen stage - will happen on a single thread.
let mutable reflectedDefinitions: Dictionary<Val, (string * int * Expr)> = Dictionary(HashIdentity.Reference)
let mutable extraBindingsToGenerate = []

Expand Down Expand Up @@ -8170,6 +8172,7 @@ type IlxAssemblyGenerator(amap: ImportMap, tcGlobals: TcGlobals, tcVal: Constrai
// The incremental state held by the ILX code generator
let mutable ilxGenEnv = GetEmptyIlxGenEnv tcGlobals ccu
let anonTypeTable = AnonTypeGenerationTable()
// Dictionaries are safe here as they will only be used during the codegen stage - will happen on a single thread.
let intraAssemblyInfo = { StaticFieldInfo = new Dictionary<_, _>(HashIdentity.Structural) }
let casApplied = new Dictionary<Stamp, bool>()

Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/InfoReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module internal FSharp.Compiler.InfoReader

open System
open System.Collections.Generic
open System.Collections.Concurrent

open FSharp.Compiler
open FSharp.Compiler.AbstractIL.IL
Expand Down Expand Up @@ -107,7 +108,7 @@ type PropertyCollector(g, amap, m, ty, optFilter, ad) =
PropInfosEquivByNameAndPartialSig EraseNone g amap m pinfo1 pinfo2 &&
pinfo1.IsDefiniteFSharpOverride = pinfo2.IsDefiniteFSharpOverride )

let props = new Dictionary<PropInfo, PropInfo>(hashIdentity)
let props = new ConcurrentDictionary<PropInfo, PropInfo>(hashIdentity)

let add pinfo =
match props.TryGetValue pinfo, pinfo with
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ open FSharp.Compiler.TcGlobals
open FSharp.Compiler.TypeRelations

open System.Collections.Generic
open System.Collections.ObjectModel

#if DEBUG
let verboseOptimizationInfo =
Expand Down Expand Up @@ -162,7 +163,7 @@ type ValInfos(entries) =
if dict.ContainsKey vkey then
failwithf "dictionary already contains key %A" vkey
dict.Add(vkey, p) |> ignore
dict), id)
ReadOnlyDictionary dict), id)

member x.Entries = valInfoTable.Force().Values

Expand Down
5 changes: 3 additions & 2 deletions src/fsharp/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
module internal FSharp.Compiler.TcGlobals

open System.Collections.Generic
open System.Collections.Concurrent
open System.Diagnostics

open FSharp.Compiler.AbstractIL
Expand Down Expand Up @@ -360,7 +361,7 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
let mkForallTyIfNeeded d r = match d with [] -> r | tps -> TType_forall(tps, r)

// A table of all intrinsics that the compiler cares about
let v_knownIntrinsics = Dictionary<(string * string option * string * int), ValRef>(HashIdentity.Structural)
let v_knownIntrinsics = ConcurrentDictionary<(string * string option * string * int), ValRef>(HashIdentity.Structural)

let makeIntrinsicValRefGeneral isKnown (enclosingEntity, logicalName, memberParentName, compiledNameOpt, typars, (argtys, rty)) =
let ty = mkForallTyIfNeeded typars (mkIteratedFunTy (List.map mkSmallRefTupledTy argtys) rty)
Expand All @@ -374,7 +375,7 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
let key = (enclosingEntity.LastItemMangledName, memberParentName, compiledName, argCount)
assert not (v_knownIntrinsics.ContainsKey(key))
if isKnown && not (v_knownIntrinsics.ContainsKey(key)) then
v_knownIntrinsics.Add(key, ValRefForIntrinsic vref)
v_knownIntrinsics.[key] <- ValRefForIntrinsic vref
vref

let makeIntrinsicValRef info = makeIntrinsicValRefGeneral true info
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/absil/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open System.IO
open System.Collections
open System.Collections.Generic
open System.Collections.Concurrent
open System.Collections.ObjectModel
open System.Reflection
open System.Text
open System.Threading
Expand Down Expand Up @@ -2130,7 +2131,7 @@ and [<Sealed>] ILTypeDefs(f : unit -> ILPreTypeDef[]) =
for pre in arr do
let key = pre.Namespace, pre.Name
t.[key] <- pre
t)
ReadOnlyDictionary t)

member x.AsArray = [| for pre in array.Value -> pre.GetTypeDef() |]

Expand Down
17 changes: 10 additions & 7 deletions src/fsharp/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module public FSharp.Compiler.AbstractIL.Internal.Library

open System
open System.Collections.Generic
open System.Collections.Concurrent
open System.Diagnostics
open System.IO
open System.Reflection
Expand Down Expand Up @@ -959,16 +960,18 @@ let _ = eventually { use x = null in return 1 }

/// Generates unique stamps
type UniqueStampGenerator<'T when 'T : equality>() =
let encodeTab = new Dictionary<'T, int>(HashIdentity.Structural)
let gate = obj ()
let encodeTab = new ConcurrentDictionary<'T, int>(HashIdentity.Structural)
let mutable nItems = 0
let encode str =
match encodeTab.TryGetValue str with
| true, idx -> idx
| _ ->
let idx = nItems
encodeTab.[str] <- idx
nItems <- nItems + 1
idx
lock gate (fun () ->
let idx = nItems
encodeTab.[str] <- idx
nItems <- nItems + 1
idx)

member this.Encode str = encode str

Expand All @@ -977,7 +980,7 @@ type UniqueStampGenerator<'T when 'T : equality>() =
/// memoize tables (all entries cached, never collected)
type MemoizationTable<'T, 'U>(compute: 'T -> 'U, keyComparer: IEqualityComparer<'T>, ?canMemoize) =

let table = new Dictionary<'T, 'U>(keyComparer)
let table = new ConcurrentDictionary<'T, 'U>(keyComparer)

member t.Apply x =
if (match canMemoize with None -> true | Some f -> f x) then
Expand Down Expand Up @@ -1066,7 +1069,7 @@ type LazyWithContext<'T, 'ctxt> =
/// Intern tables to save space.
module Tables =
let memoize f =
let t = new Dictionary<_, _>(1000, HashIdentity.Structural)
let t = new ConcurrentDictionary<_, _>(Environment.ProcessorCount, 1000, HashIdentity.Structural)
fun x ->
match t.TryGetValue x with
| true, res -> res
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/absil/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ let mkCacheInt32 lowMem _inbase _nm _sz =
fun f (idx: int32) ->
let cache =
match !cache with
| null -> cache := new Dictionary<int32, _>(11)
| null -> cache := new ConcurrentDictionary<int32, _>(Environment.ProcessorCount, 11)
| _ -> ()
!cache
match cache.TryGetValue idx with
Expand All @@ -719,7 +719,7 @@ let mkCacheGeneric lowMem _inbase _nm _sz =
fun f (idx :'T) ->
let cache =
match !cache with
| null -> cache := new Dictionary<_, _>(11 (* sz: int *) )
| null -> cache := new ConcurrentDictionary<_, _>(Environment.ProcessorCount, 11 (* sz: int *) )
| _ -> ()
!cache
match cache.TryGetValue idx with
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/lexhelp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type LightSyntaxStatus(initial:bool,warn:bool) =
/// Manage lexer resources (string interning)
[<Sealed>]
type LexResourceManager(?capacity: int) =
let strings = new System.Collections.Generic.Dictionary<string, Parser.token>(defaultArg capacity 1024)
let strings = new System.Collections.Concurrent.ConcurrentDictionary<string, Parser.token>(Environment.ProcessorCount, defaultArg capacity 1024)
member x.InternIdentifierToken(s) =
match strings.TryGetValue s with
| true, res -> res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18369,8 +18369,8 @@ FSharp.Compiler.AbstractIL.Internal.Library+UndefinedException: Int32 GetHashCod
FSharp.Compiler.AbstractIL.Internal.Library+UndefinedException: Int32 GetHashCode(System.Collections.IEqualityComparer)
FSharp.Compiler.AbstractIL.Internal.Library+UndefinedException: Void .ctor()
FSharp.Compiler.AbstractIL.Internal.Library+UniqueStampGenerator`1[T]: Int32 Encode(T)
FSharp.Compiler.AbstractIL.Internal.Library+UniqueStampGenerator`1[T]: KeyCollection Table
FSharp.Compiler.AbstractIL.Internal.Library+UniqueStampGenerator`1[T]: KeyCollection get_Table()
FSharp.Compiler.AbstractIL.Internal.Library+UniqueStampGenerator`1[T]: System.Collections.Generic.ICollection`1[T] Table
FSharp.Compiler.AbstractIL.Internal.Library+UniqueStampGenerator`1[T]: System.Collections.Generic.ICollection`1[T] get_Table()
FSharp.Compiler.AbstractIL.Internal.Library+UniqueStampGenerator`1[T]: Void .ctor()
FSharp.Compiler.AbstractIL.Internal.Library+ValueOptionInternal: Microsoft.FSharp.Core.FSharpValueOption`1[a] ofOption[a](Microsoft.FSharp.Core.FSharpOption`1[a])
FSharp.Compiler.AbstractIL.Internal.Library+ValueOptionInternal: Microsoft.FSharp.Core.FSharpValueOption`1[b] bind[a,b](Microsoft.FSharp.Core.FSharpFunc`2[a,Microsoft.FSharp.Core.FSharpValueOption`1[b]], Microsoft.FSharp.Core.FSharpValueOption`1[a])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// #Regression #Conformance #ObjectOrientedTypes #Classes #MethodsAndProperties #MemberDefinitions
// Regression test for FSHARP1.0:5475
//<Expects status="error" span="(5,27-5,28)" id="FS0441">Duplicate property\. The property 'M' has the same name and signature as another property in type 'C'\.$</Expects>
//<Expects status="error" span="(6,31-6,32)" id="FS0441">Duplicate property\. The property 'M' has the same name and signature as another property in type 'C'\.$</Expects>
type C = class
member __.M = ()
static member M = ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Verify that one should not be able to have two properties called �X� with different arities (number of arguments).
// This is regression test for FSHARP1.0:4529

//<Expects id="FS0436" span="(11,17-11,18)" status="error">The property 'X' has the same name as another property in type 'TestType1'</Expects>
//<Expects id="FS0436" span="(13,17-13,18)" status="error">The property 'X' has the same name as another property in type 'TestType1'</Expects>


type TestType1( x : int ) =
Expand Down
Loading