Skip to content
Closed
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
25 changes: 16 additions & 9 deletions src/fsharp/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ open System.IO
open System.Reflection
open System.Text
open System.Threading
open System.Threading.Tasks

open Internal.Utilities
open Internal.Utilities.Collections
Expand Down Expand Up @@ -1841,14 +1842,21 @@ let main0(ctok, argv, legacyReferenceResolver, bannerAlreadyPrinted,
let inputs =
try
let isLastCompiland, isExe = sourceFiles |> tcConfig.ComputeCanContainEntryPoint
isLastCompiland |> List.zip sourceFiles
// PERF: consider making this parallel, once uses of global state relevant to parsing are cleaned up
|> List.choose (fun (filename: string, isLastCompiland) ->
let pathOfMetaCommandSource = Path.GetDirectoryName filename
match ParseOneInputFile(tcConfig, lexResourceManager, ["COMPILED"], filename, (isLastCompiland, isExe), errorLogger, (*retryLocked*)false) with
| Some input -> Some (input, pathOfMetaCommandSource)
| None -> None
)
let sourceFiles = isLastCompiland |> List.zip sourceFiles |> Array.ofSeq

let parallelOptions = ParallelOptions(MaxDegreeOfParallelism=min Environment.ProcessorCount sourceFiles.Length)

let results = Array.zeroCreate sourceFiles.Length
Parallel.For(0, sourceFiles.Length, parallelOptions, fun i ->
results.[i] <-
let (filename: string, isLastCompiland) = sourceFiles.[i]
let pathOfMetaCommandSource = Path.GetDirectoryName filename
match ParseOneInputFile(tcConfig, lexResourceManager, ["COMPILED"], filename, (isLastCompiland, isExe), errorLogger, (*retryLocked*)false) with
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The errorLogger is probably not concurrent safe; will need to solve that.

| Some input -> Some (input, pathOfMetaCommandSource)
| None -> None) |> ignore
results
|> Array.choose id
|> List.ofArray
with e ->
errorRecoveryNoRange e
exiter.Exit 1
Expand Down Expand Up @@ -2250,4 +2258,3 @@ let mainCompile
typecheckAndCompile
(ctok, argv, legacyReferenceResolver, bannerAlreadyPrinted, reduceMemoryUsage,
defaultCopyFSharpCore, exiter, errorLoggerProvider, tcImportsCapture, dynamicAssemblyCreator)

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