diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 7c634ca81d6..c31f210022f 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -1797,6 +1797,9 @@ type internal FsiDynamicCompiler let multiAssemblyName = ilxMainModule.ManifestOfAssembly.Name + // The name of the assembly is "FSI-ASSEMBLY" for all submissions. This number is used for the Version + let dynamicAssemblyId = Interlocked.Increment &dynamicAssemblyId + // Adjust the assembly name of this fragment, and add InternalsVisibleTo attributes to // allow internals access by all future assemblies with the same name (and only differing in version) let manifest = @@ -1811,13 +1814,10 @@ type internal FsiDynamicCompiler { manifest with Name = multiAssemblyName // Because the coreclr loader will not load a higher assembly make versions go downwards - Version = Some(parseILVersion $"0.0.0.{maxVersion - dynamicAssemblyId}") + Version = Some(parseILVersion $"0.0.0.{maxVersion - dynamicAssemblyId % maxVersion}") CustomAttrsStored = storeILCustomAttrs (mkILCustomAttrs attrs) } - // The name of the assembly is "FSI-ASSEMBLY" for all submissions. This number is used for the Version - dynamicAssemblyId <- (dynamicAssemblyId + 1) % maxVersion - let ilxMainModule = { ilxMainModule with Manifest = Some manifest diff --git a/src/Compiler/Interactive/fsihelp.fs b/src/Compiler/Interactive/fsihelp.fs index eb1efd22ed7..f21da3ab441 100644 --- a/src/Compiler/Interactive/fsihelp.fs +++ b/src/Compiler/Interactive/fsihelp.fs @@ -14,6 +14,7 @@ open FSharp.Compiler.IO module Parser = open System.Xml + open System.Collections.Concurrent type Help = { @@ -79,22 +80,19 @@ module Parser = let s = if idx > 0 then s.Substring(0, idx) else s s - let xmlDocCache = Dictionary() + let xmlDocCache = ConcurrentDictionary>() let tryGetXmlDocument xmlPath = - try - match xmlDocCache.TryGetValue(xmlPath) with - | true, value -> - let xmlDocument = XmlDocument() - xmlDocument.LoadXml(value) - Some xmlDocument - | _ -> + let valueFactory xmlPath = + lazy use stream = FileSystem.OpenFileForReadShim(xmlPath) let rawXml = stream.ReadAllText() let xmlDocument = XmlDocument() xmlDocument.LoadXml(rawXml) - xmlDocCache.Add(xmlPath, rawXml) - Some xmlDocument + xmlDocument + + try + Some(xmlDocCache.GetOrAdd(xmlPath, valueFactory).Value) with _ -> None