未验证 提交 381b22a5 编写于 作者: D Don Syme 提交者: GitHub

Merge pull request #10308 from TIHan/concurrent-structures

Making several uses of Dictionary types be ConcurrentDictionary
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -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 = []
......@@ -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>()
......
......@@ -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
......@@ -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
......
......@@ -32,6 +32,7 @@ open FSharp.Compiler.TcGlobals
open FSharp.Compiler.TypeRelations
open System.Collections.Generic
open System.Collections.ObjectModel
#if DEBUG
let verboseOptimizationInfo =
......@@ -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
......
......@@ -9,6 +9,7 @@
module internal FSharp.Compiler.TcGlobals
open System.Collections.Generic
open System.Collections.Concurrent
open System.Diagnostics
open FSharp.Compiler.AbstractIL
......@@ -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)
......@@ -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
......
......@@ -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
......@@ -2135,7 +2136,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() |]
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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])
// #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 = ()
......
......@@ -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 ) =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册