Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Parallel type checking for impl files with backing sig files - fsc.exe #11152

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d238d25
Enabling parallel parsing for compiling
TIHan Feb 23, 2021
9724f27
Using a delayed error logger per parsing file
TIHan Feb 23, 2021
53f234a
Added -parallel option
TIHan Feb 24, 2021
bf07e86
Fixing error logger
TIHan Feb 24, 2021
4b7c652
Moved parallel compiler option to be a test option
TIHan Feb 25, 2021
d2198df
Trying to get tests to pass
TIHan Feb 25, 2021
d4ad54c
Remove switch
TIHan Feb 25, 2021
23d81e3
Minor refactor
TIHan Feb 25, 2021
3f32f7d
More refactoring
TIHan Feb 25, 2021
03c8b8a
Add comment
TIHan Feb 25, 2021
51c897b
Initial work for parallel type checking
TIHan Feb 25, 2021
d3c674d
Minor refactor
TIHan Feb 26, 2021
20f285e
Add max
TIHan Feb 26, 2021
f40de5b
Merge branch 'parallel-parsing-2' into parallel-type-checking
TIHan Feb 26, 2021
6b06c3a
Some cleanup
TIHan Feb 26, 2021
c6c54b9
do not use SkipImpl
TIHan Feb 26, 2021
0f39ad4
minor refactor
TIHan Feb 26, 2021
fa5d394
Merged main
TIHan Feb 26, 2021
1236cbf
Merge branch 'parallel-parsing-2' into parallel-type-checking
TIHan Feb 26, 2021
5c5a466
Handling aggregate exceptions from ArrayParallel. Using try/finally t…
TIHan Mar 2, 2021
20e5263
Merge branch 'parallel-parsing-2' into parallel-type-checking
TIHan Mar 2, 2021
e5fa18b
Merged main
TIHan Mar 3, 2021
8b419b3
Merging main
TIHan Mar 4, 2021
311d436
Fix build
TIHan Mar 5, 2021
18cb076
merging
TIHan May 10, 2021
fee99c6
Merging main
TIHan Nov 4, 2021
4fe0f71
Fixing build
TIHan Nov 4, 2021
a3d39b2
Merge remote-tracking branch 'upstream/main' into parallel-type-checking
vzarytovskii Nov 25, 2021
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
51 changes: 46 additions & 5 deletions src/fsharp/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,10 @@ type TcState =
{ x with tcsTcSigEnv = tcEnvAtEndOfLastInput
tcsTcImplEnv = tcEnvAtEndOfLastInput }

member x.RemoveImpl qualifiedNameOfFile =
{ x with tcsRootImpls = x.tcsRootImpls.Remove(qualifiedNameOfFile) }


/// Create the initial type checking state for compiling an assembly
let GetInitialTcState(m, ccuName, tcConfig: TcConfig, tcGlobals, tcImports: TcImports, niceNameGen, tcEnv0, openDecls0) =
ignore tcImports
Expand Down Expand Up @@ -946,15 +949,23 @@ let TypeCheckOneInput(checkForErrors,
}

/// Typecheck a single file (or interactive entry into F# Interactive)
let TypeCheckOneInputEntry (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp =
let TypeCheckOneInputEntryAux (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp skipImplIfSigExists =
// 'use' ensures that the warning handler is restored at the end
use unwindEL = PushErrorLoggerPhaseUntilUnwind(fun oldLogger -> GetErrorLoggerFilteringByScopedPragmas(false, GetScopedPragmasForInput inp, oldLogger) )
use unwindBP = PushThreadBuildPhaseUntilUnwind BuildPhase.TypeCheck

RequireCompilationThread ctok
TypeCheckOneInput (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, TcResultsSink.NoSink, tcState, inp, false)
TypeCheckOneInput (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, TcResultsSink.NoSink, tcState, inp, skipImplIfSigExists)
|> Cancellable.runWithoutCancellation

/// Typecheck a single file (or interactive entry into F# Interactive)
let TypeCheckOneInputEntry (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp =
TypeCheckOneInputEntryAux(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp false

/// Typecheck a single file but skip it if the file is an impl and has a backing sig
let TypeCheckOneInputEntrySkipImpl (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp =
TypeCheckOneInputEntryAux(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp true

/// Finish checking multiple files (or one interactive entry into F# Interactive)
let TypeCheckMultipleInputsFinish(results, tcState: TcState) =
let tcEnvsAtEndFile, topAttrs, implFiles, ccuSigsForFiles = List.unzip4 results
Expand Down Expand Up @@ -983,10 +994,40 @@ let TypeCheckClosedInputSetFinish (declaredImpls: TypedImplFile list, tcState) =
errorR(Error(FSComp.SR.buildSignatureWithoutImplementation(qualNameOfFile.Text), qualNameOfFile.Range)))

tcState, declaredImpls, ccuContents

let TypeCheckClosedInputSet (ctok, checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs) =
// tcEnvAtEndOfLastFile is the environment required by fsi.exe when incrementally adding definitions
let results, tcState =
if tcConfig.concurrentBuild then
let results, tcState = (tcState, inputs) ||> List.mapFold (TypeCheckOneInputEntrySkipImpl (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt))

let inputs = Array.ofList inputs
let newResults = Array.ofList results
let results = Array.ofList results

(inputs, results)
||> Array.zip
|> Array.mapi (fun i (input, (_, _, implOpt, _)) ->
match implOpt with
| None -> None
| Some impl ->
match impl with
| TypedImplFile.TImplFile(qualifiedNameOfFile=qualifiedNameOfFile;implementationExpressionWithSignature=ModuleOrNamespaceExprWithSig.ModuleOrNamespaceExprWithSig(contents=ModuleOrNamespaceExpr.TMDefs [])) ->
Some(i, input, qualifiedNameOfFile)
| _ ->
None
)
|> Array.choose id
|> ArrayParallel.iter (fun (i, input, qualifiedNameOfFile) ->
let tcState = tcState.RemoveImpl(qualifiedNameOfFile)
let result, _ = TypeCheckOneInputEntry (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt) tcState input
newResults.[i] <- result
)

newResults |> List.ofArray, tcState
else
(tcState, inputs) ||> List.mapFold (TypeCheckOneInputEntry (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt))

let TypeCheckClosedInputSet (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs) =
// tcEnvAtEndOfLastFile is the environment required by fsi.exe when incrementally adding definitions
let results, tcState = (tcState, inputs) ||> List.mapFold (TypeCheckOneInputEntry (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt))
let (tcEnvAtEndOfLastFile, topAttrs, implFiles, _), tcState = TypeCheckMultipleInputsFinish(results, tcState)
let tcState, declaredImpls, ccuContents = TypeCheckClosedInputSetFinish (implFiles, tcState)
tcState.Ccu.Deref.Contents <- ccuContents
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/ParseAndCheckInputs.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type TcState =

member CreatesGeneratedProvidedTypes: bool

member RemoveImpl: QualifiedNameOfFile -> TcState

/// Get the initial type checking state for a set of inputs
val GetInitialTcState:
range *
Expand Down
4 changes: 4 additions & 0 deletions src/fsharp/lib.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ type DisposablesTracker =
[<RequireQualifiedAccess>]
module ArrayParallel =

val inline iter : ('T -> unit) -> 'T [] -> unit

val inline iteri : (int -> 'T -> unit) -> 'T [] -> unit

val inline map : ('T -> 'U) -> 'T [] -> 'U []

val inline mapi : (int -> 'T -> 'U) -> 'T [] -> 'U []
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks Condition="'$(OS)' != 'Unix'">net472;net5.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Unix'">net5.0</TargetFrameworks>
<TargetFrameworks>net472;net5.0</TargetFrameworks>
<NoWarn>$(NoWarn);44;75;</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateProgramFile>false</GenerateProgramFile>
Expand All @@ -12,7 +11,6 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\fsharp\TestHelpers.fs" Link="TestHelpers.fs" />
<Compile Include="LibraryTestFx.fs" />
<Compile Include="SurfaceArea.netstandard.fs" />
<Compile Include="..\service\FsUnit.fs">
Expand Down Expand Up @@ -72,22 +70,14 @@
<Compile Include="..\service\ParserTests.fs">
<Link>ParserTests.fs</Link>
</Compile>
<Compile Include="..\service\XmlDocTests.fs">
<Link>XmlDocTests.fs</Link>
</Compile>
<Compile Include="..\service\PrettyNaming.fs">
<Link>PrettyNaming.fs</Link>
</Compile>
<Compile Include="..\service\Program.fs">
<Compile Include="..\service\Program.fs">
<Link>Program.fs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dotnet.ProjInfo" Version="0.37.0" />
<ProjectReference Include="..\..\src\fsharp\FSharp.Compiler.Service\FSharp.Compiler.Service.fsproj" />
<ProjectReference Include="..\..\tests\FSharp.Test.Utilities\FSharp.Test.Utilities.fsproj" />
<ProjectReference Include="..\service\data\CSharp_Analysis\CSharp_Analysis.csproj" />
</ItemGroup>

</Project>
</Project>
7 changes: 2 additions & 5 deletions tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition="'$(OS)' != 'Unix'">net472;net5.0</TargetFrameworks>
<TargetFrameworks>net472;net5.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Unix'">net5.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81</AssetTargetFallback>
Expand All @@ -28,14 +28,11 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Compiler.Service\FSharp.Compiler.Service.fsproj" />
</ItemGroup>

<ItemGroup Condition="'$(SolutionName)' != 'FSharp.Compiler.Service'">
<!-- CompilerAssert dependencies.
Make sure they are getting built with the Utilities. -->
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Core\FSharp.Core.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Build\FSharp.Build.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Compiler.Service\FSharp.Compiler.Service.fsproj" />
<ProjectReference Include="$(FSharpTestsRoot)\fsharpqa\testenv\src\PEVerify\PEVerify.csproj" />
</ItemGroup>

Expand Down