Skip to content

Enable parallel compilation features for users of LangVersion=preview #17948

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

Merged
merged 6 commits into from
Nov 6, 2024
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
4 changes: 2 additions & 2 deletions FSharp.Profiles.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<NullCheckingSupportInLibrary>false</NullCheckingSupportInLibrary>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' != 'Proto' and '$(BUILDING_USING_DOTNET)' != 'true'">
<OtherFlags>$(OtherFlags) /langversion:preview</OtherFlags>
<PropertyGroup Condition="'$(Configuration)' != 'Proto' and '$(BUILDING_USING_DOTNET)' != 'true' and '$(MSBuildProjectExtension)' == '.fsproj'"> <!-- VB.NET does not understand "preview". It only knows "old","older" and "boomer" :-)) (jk)-->
<LangVersion>preview</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(BUILDING_USING_DOTNET)' == 'true'">
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Deprecate places where `seq` can be omitted. ([Language suggestion #1033](https://github.com/fsharp/fslang-suggestions/issues/1033), [PR #17772](https://github.com/dotnet/fsharp/pull/17772))
* Support literal attribute on decimals ([PR #17769](https://github.com/dotnet/fsharp/pull/17769))
* Added type conversions cache, only enabled for compiler runs, guarded by language version preview ([PR#17668](https://github.com/dotnet/fsharp/pull/17668))
* Added project property ParallelCompilation which turns on graph based type checking, parallel ILXGen and parallel optimization. By default on for users of langversion=preview ([PR#17948](https://github.com/dotnet/fsharp/pull/17948))

### Changed

Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ type TcConfigBuilder =
mutable optSettings: Optimizer.OptimizationSettings
mutable emitTailcalls: bool
mutable deterministic: bool
mutable concurrentBuild: bool
mutable parallelParsing: bool
mutable parallelIlxGen: bool
mutable emitMetadataAssembly: MetadataAssemblyGeneration
mutable preferredUiLang: string option
Expand Down Expand Up @@ -817,7 +817,7 @@ type TcConfigBuilder =
}
emitTailcalls = true
deterministic = false
concurrentBuild = true
parallelParsing = true
parallelIlxGen = FSharpExperimentalFeaturesEnabledAutomatically
emitMetadataAssembly = MetadataAssemblyGeneration.None
preferredUiLang = None
Expand Down Expand Up @@ -1380,7 +1380,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.optSettings = data.optSettings
member _.emitTailcalls = data.emitTailcalls
member _.deterministic = data.deterministic
member _.concurrentBuild = data.concurrentBuild
member _.parallelParsing = data.parallelParsing
member _.parallelIlxGen = data.parallelIlxGen
member _.emitMetadataAssembly = data.emitMetadataAssembly
member _.pathMap = data.pathMap
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ type TcConfigBuilder =

mutable deterministic: bool

mutable concurrentBuild: bool
mutable parallelParsing: bool

mutable parallelIlxGen: bool

Expand Down Expand Up @@ -771,7 +771,7 @@ type TcConfig =

member deterministic: bool

member concurrentBuild: bool
member parallelParsing: bool

member parallelIlxGen: bool

Expand Down
36 changes: 32 additions & 4 deletions src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,26 @@ let splittingSwitch (tcConfigB: TcConfigBuilder) switch =
let callVirtSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.alwaysCallVirt <- switch = OptionSwitch.On

let callParallelCompilationSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.parallelIlxGen <- switch = OptionSwitch.On

let (graphCheckingMode, optMode) =
match switch with
| OptionSwitch.On -> TypeCheckingMode.Graph, OptimizationProcessingMode.Parallel
| OptionSwitch.Off -> TypeCheckingMode.Sequential, OptimizationProcessingMode.Sequential

if tcConfigB.typeCheckingConfig.Mode <> graphCheckingMode then
tcConfigB.typeCheckingConfig <-
{ tcConfigB.typeCheckingConfig with
Mode = graphCheckingMode
}

if tcConfigB.optSettings.processingMode <> optMode then
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
processingMode = optMode
}

let useHighEntropyVASwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.useHighEntropyVA <- switch = OptionSwitch.On

Expand Down Expand Up @@ -1365,9 +1385,9 @@ let testFlag tcConfigB =
| "DumpDebugInfo" -> tcConfigB.dumpDebugInfo <- true
| "ShowLoadedAssemblies" -> tcConfigB.showLoadedAssemblies <- true
| "ContinueAfterParseFailure" -> tcConfigB.continueAfterParseFailure <- true
| "ParallelOff" -> tcConfigB.concurrentBuild <- false
| "ParallelIlxGen" -> tcConfigB.parallelIlxGen <- true
| "GraphBasedChecking" ->
| "ParallelOff" -> tcConfigB.parallelParsing <- false
| "ParallelIlxGen" -> tcConfigB.parallelIlxGen <- true // Kept as --test:.. flag for temporary backwards compatibility during .NET10 period.
| "GraphBasedChecking" -> // Kept as --test:.. flag for temporary backwards compatibility during .NET10 period.
tcConfigB.typeCheckingConfig <-
{ tcConfigB.typeCheckingConfig with
Mode = TypeCheckingMode.Graph
Expand All @@ -1378,7 +1398,7 @@ let testFlag tcConfigB =
DumpGraph = true
}
| "DumpSignatureData" -> tcConfigB.dumpSignatureData <- true
| "ParallelOptimization" ->
| "ParallelOptimization" -> // Kept as --test:.. flag for temporary backwards compatibility during .NET10 period.
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
processingMode = OptimizationProcessingMode.Parallel
Expand Down Expand Up @@ -1692,6 +1712,14 @@ let internalFlags (tcConfigB: TcConfigBuilder) =
None
)

CompilerOption(
"parallelcompilation",
tagNone,
OptionSwitch(callParallelCompilationSwitch tcConfigB),
Some(InternalCommandLineOption("--parallelcompilation", rangeCmdArgs)),
None
)

testFlag tcConfigB
]
@
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ let ParseInputFilesSequential (tcConfig: TcConfig, lexResourceManager, sourceFil
/// Parse multiple input files from disk
let ParseInputFiles (tcConfig: TcConfig, lexResourceManager, sourceFiles, diagnosticsLogger: DiagnosticsLogger, retryLocked) =
try
if tcConfig.concurrentBuild then
if tcConfig.parallelParsing then
ParseInputFilesInParallel(tcConfig, lexResourceManager, sourceFiles, diagnosticsLogger, retryLocked)
else
ParseInputFilesSequential(tcConfig, lexResourceManager, sourceFiles, diagnosticsLogger, retryLocked)
Expand Down
8 changes: 8 additions & 0 deletions src/FSharp.Build/Fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type public Fsc() as this =
let mutable otherFlags: string MaybeNull = null
let mutable outputAssembly: string MaybeNull = null
let mutable outputRefAssembly: string MaybeNull = null
let mutable parallelCompilation: bool option = None
let mutable pathMap: string MaybeNull = null
let mutable pdbFile: string MaybeNull = null
let mutable platform: string MaybeNull = null
Expand Down Expand Up @@ -202,6 +203,7 @@ type public Fsc() as this =
if not tailcalls then
builder.AppendSwitch("--tailcalls-")

// Nullables
match nullable with
| Some true ->
builder.AppendSwitch("--checknulls+")
Expand Down Expand Up @@ -345,6 +347,8 @@ type public Fsc() as this =
if deterministic then
builder.AppendSwitch("--deterministic+")

builder.AppendOptionalSwitch("--parallelcompilation", parallelCompilation)

// OtherFlags - must be second-to-last
builder.AppendSwitchUnquotedIfNotNull("", otherFlags)
capturedArguments <- builder.CapturedArguments()
Expand Down Expand Up @@ -504,6 +508,10 @@ type public Fsc() as this =
with get () = outputRefAssembly
and set (s) = outputRefAssembly <- s

member _.ParallelCompilation
with get () = parallelCompilation |> Option.defaultValue false
and set (p) = parallelCompilation <- Some p

// --pathmap <string>: Paths to rewrite when producing deterministic builds
member _.PathMap
with get () = pathMap
Expand Down
1 change: 1 addition & 0 deletions src/FSharp.Build/Microsoft.FSharp.NetSdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
<UseStandardResourceNames Condition=" '$(UseStandardResourceNames)' == '' ">true</UseStandardResourceNames>
<FsiExec Condition=" '$(FsiExec)' == '' ">true</FsiExec>
<ReflectionFree Condition=" '$(ReflectionFree)' == '' ">false</ReflectionFree>
<ParallelCompilation Condition=" '$(ParallelCompilation)' == '' and '$(LangVersion)' == 'preview' "></ParallelCompilation> <!-- Default to parallel compilation for preview language users before it is rolled out to everyone -->
</PropertyGroup>

<!-- BinaryFormatter is disabled (warning is treated as error) by default in .NET8+, this mirroring the change in SDK (https://github.com/dotnet/sdk/pull/31591) -->
Expand Down
1 change: 1 addition & 0 deletions src/FSharp.Build/Microsoft.FSharp.Targets
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ this file.
OtherFlags="$(FscOtherFlags)"
OutputAssembly="@(IntermediateAssembly)"
OutputRefAssembly="@(IntermediateRefAssembly)"
ParallelCompilation="@(ParallelCompilation)"
PathMap="$(PathMap)"
PdbFile="$(PdbFile)"
Platform="$(PlatformTarget)"
Expand Down
Loading