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

Parallel type-checking in compilation (behind a feature flag) #14494

Merged
merged 88 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
0c5c1ff
Squashed commit of the following:
safesparrow Dec 19, 2022
7f69062
Code clean up after initial draft PR.
nojaf Dec 20, 2022
30a0081
Revert fscmain.fs
nojaf Dec 20, 2022
95d8024
Revert more unwanted changes.
nojaf Dec 20, 2022
c496359
Surface area for now.
nojaf Dec 20, 2022
c57acf2
Mark GraphChecking as internal.
nojaf Jan 3, 2023
9c6b5f1
Mark helper functions in unit tests as private.
nojaf Jan 3, 2023
5666202
Mark Scenarios as internal.
nojaf Jan 3, 2023
a4dfa8f
Make Scenario public and use TestFileWithAST.
nojaf Jan 3, 2023
16e5614
Use Graph when FSHARP_EXPERIMENTAL_FEATURES is set.
nojaf Jan 3, 2023
f223333
Merge branch 'main' into graph-tc-new
vzarytovskii Jan 3, 2023
244bbaa
Always depend on prim-types-prelude.fsi for F# Core.
nojaf Jan 3, 2023
81fb7d1
Add CI leg for GraphBasedCheckingOn.
nojaf Jan 3, 2023
cb1a22f
Merge branch 'graph-tc-new' of https://github.com/safesparrow/fsharp …
nojaf Jan 3, 2023
cc0aaba
Remove unused members of TcState.
nojaf Jan 4, 2023
0fabdd3
Trigger CI
nojaf Jan 4, 2023
992b9c0
Scope additional links in F# core to files between prim-types-prelude…
nojaf Jan 5, 2023
8bd8cd4
Merge branch 'main' into graph-tc-new
nojaf Jan 12, 2023
08e5e7e
Workaround for Set.empty.
nojaf Jan 12, 2023
af21780
Merge branch 'main' into graph-tc-new
nojaf Jan 12, 2023
2378cf9
Remove --test:ParallelCheckingWithSignatureFilesOn
nojaf Jan 12, 2023
5510383
Wrap lambda's in types.
nojaf Jan 12, 2023
60fe3d1
Update type name and add some more comments.
nojaf Jan 12, 2023
79f487c
Move comment to type definition.
nojaf Jan 12, 2023
649727b
Always depend on prim-types-prelude.fsi in FSharp.Core.
nojaf Jan 12, 2023
53265d0
Remove ParaChecking
nojaf Jan 12, 2023
c065a12
Merge branch 'main' into graph-tc-new
nojaf Jan 13, 2023
c09a49b
Update surface area
nojaf Jan 13, 2023
a74651f
Removed unused setting in VS
nojaf Jan 13, 2023
c39c5ac
Merge branch 'main' into graph-tc-new
nojaf Jan 16, 2023
b708e4e
Exclude graph mode for interactive compilation.
nojaf Jan 16, 2023
fcf8c70
Pipe collections into module functions.
nojaf Jan 16, 2023
fd46607
Update SurfaceArea in Release mode 🙃
nojaf Jan 16, 2023
72cdcfd
Add signature files for GraphChecking modules.
nojaf Jan 16, 2023
01a7887
Add warning when AutoOpenAttribute is being aliased.
nojaf Jan 16, 2023
8ad542a
Initial comparison benchmark.
nojaf Jan 17, 2023
d23922c
Check if CompiledRepresentation is Named.
nojaf Jan 18, 2023
3efaf23
Remove trailing space.
nojaf Jan 18, 2023
1a78368
Excluded erased types.
nojaf Jan 18, 2023
6900373
Dump graph as mermaid diagram.
nojaf Jan 18, 2023
95a0e9b
Missing files.
nojaf Jan 18, 2023
0692914
Make alias types internal.
nojaf Jan 18, 2023
3cf87c8
SurfaceArea!
nojaf Jan 18, 2023
a942941
Merge branch 'main' into graph-tc-new
nojaf Jan 19, 2023
1ddcbc1
Merge branch 'main' into graph-tc-new
vzarytovskii Jan 19, 2023
9f5195b
Merge upstream/main
safesparrow Jan 20, 2023
b960811
Fix build - remove unused symbols.
safesparrow Jan 20, 2023
b80df24
Auto-disable graph mode in deterministic build
safesparrow Jan 20, 2023
aa56edc
Merge branch 'main' into graph-tc-new
nojaf Jan 24, 2023
d6ded54
Merge branch 'main' into graph-tc-new
nojaf Jan 24, 2023
6f0aa50
Merge branch 'main' into graph-tc-new
nojaf Jan 24, 2023
479b66a
A few local refactorings + update comments
safesparrow Jan 25, 2023
ea16fd7
Use TcGlobals for AutoOpenAttribute reference. Assert exitCode of 0 i…
safesparrow Jan 25, 2023
362b25c
Merge branch 'graph-tc-new' of https://github.com/safesparrow/fsharp …
safesparrow Jan 25, 2023
9b0ed15
Do not match on `TType` directly
safesparrow Jan 26, 2023
72279dd
Merge branch 'main' into graph-tc-new
nojaf Jan 31, 2023
e520e2e
Add comment on why we warn when user aliases the AutoOpenAttribute.
nojaf Jan 31, 2023
88e5ee6
Capitalize type parameter names.
nojaf Jan 31, 2023
9abdd77
Prefer array comprehension expression.
nojaf Feb 1, 2023
d2e4354
Refactor cryptic abbreviations.
nojaf Feb 1, 2023
b103d2b
Refactor List.collect id to List.concat.
nojaf Feb 1, 2023
d8c0ee9
Show scrape.fsx in IDE.
nojaf Feb 1, 2023
8a6bb9f
Prefer array comprehension expression.
nojaf Feb 1, 2023
29ae5f2
Prefer list comprehension expression.
nojaf Feb 1, 2023
e94d0d0
Refactor cryptic function into a helper module.
nojaf Feb 1, 2023
52eee66
Refactor List.collect with lambda to list comprehension expression.
nojaf Feb 1, 2023
e4d69eb
Refactor List.collect id to List.concat.
nojaf Feb 1, 2023
8545b92
Remove with in type.
nojaf Feb 1, 2023
c66ea08
Remove unnecessary open.
nojaf Feb 1, 2023
aa8adc7
Use `||>`
nojaf Feb 1, 2023
a23588f
Don't use pipe-to-fun.
nojaf Feb 1, 2023
be2bc12
Remove unused CheckArgs.
nojaf Feb 1, 2023
006f562
Merge branch 'main' into graph-tc-new
nojaf Feb 2, 2023
154614c
Merge branch 'main' into graph-tc-new
nojaf Feb 2, 2023
a1a8eb1
Add some basic regression tests for the Graph module.
nojaf Feb 2, 2023
3c9fa6b
Use FileSystemUtils helper instead of direct Path.GetFileName access.
nojaf Feb 2, 2023
6272b5f
Merge branch 'main' into graph-tc-new
nojaf Feb 4, 2023
be5a612
Merge branch 'main' into graph-tc-new
nojaf Feb 6, 2023
742c7b0
Merge branch 'main' into graph-tc-new
nojaf Feb 6, 2023
6221c2a
Merge branch 'main' into graph-tc-new
nojaf Feb 6, 2023
20a4f9d
Merge branch 'main' into graph-tc-new
nojaf Feb 7, 2023
1e070b6
Merge branch 'main' into graph-tc-new
nojaf Feb 8, 2023
07c8cb6
Clean up after code review.
nojaf Feb 8, 2023
586b01a
Update algorithm info in Docs.md
nojaf Feb 8, 2023
5256c78
Update Docs.md
safesparrow Feb 8, 2023
e69f85b
Add concatenate to Continuation module.
nojaf Feb 9, 2023
27e6916
Use F# set instead of HashSet.
nojaf Feb 9, 2023
a03a66a
Merge branch 'graph-tc-new' of https://github.com/safesparrow/fsharp …
nojaf Feb 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion FSharpBuild.Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<WarningsAsErrors>1182;0025;$(WarningsAsErrors)</WarningsAsErrors>
<OtherFlags>$(OtherFlags) --nowarn:3384</OtherFlags>
<OtherFlags>$(OtherFlags) --times --nowarn:75</OtherFlags>
<OtherFlags Condition="$(ParallelCheckingWithSignatureFilesOn) == 'true'">$(OtherFlags) --test:ParallelCheckingWithSignatureFilesOn</OtherFlags>
<OtherFlags Condition="$(AdditionalFscCmdFlags) != ''">$(OtherFlags) $(AdditionalFscCmdFlags)</OtherFlags>
</PropertyGroup>

Expand Down
11 changes: 10 additions & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,15 @@ module EstablishTypeDefinitionCores =
let kind = if hasMeasureAttr then TyparKind.Measure else TyparKind.Type
let ty, _ = TcTypeOrMeasureAndRecover (Some kind) cenv NoNewTypars checkConstraints ItemOccurence.UseInType WarnOnIWSAM.No envinner tpenv rhsType

match ty with
safesparrow marked this conversation as resolved.
Show resolved Hide resolved
safesparrow marked this conversation as resolved.
Show resolved Hide resolved
| AppTy g (tcref, _) when not tcref.IsErased ->
match tcref.CompiledRepresentation with
| CompiledTypeRepr.ILAsmOpen _ -> ()
| CompiledTypeRepr.ILAsmNamed _ ->
if tcref.CompiledRepresentationForNamedType.FullName = "Microsoft.FSharp.Core.AutoOpenAttribute" then
warning(Error(FSComp.SR.chkAutoOpenAttributeInTypeAbbrev(), tycon.Id.idRange))
| _ -> ()

if not firstPass then
let ftyvs = freeInTypeLeftToRight g false ty
let typars = tycon.Typars m
Expand Down Expand Up @@ -4278,7 +4287,7 @@ module TcDeclarations =

if not (isNil members) && tcref.IsTypeAbbrev then
errorR(Error(FSComp.SR.tcTypeAbbreviationsCannotHaveAugmentations(), tyDeclRange))

let (SynComponentInfo (attributes, _, _, _, _, _, _, _)) = synTyconInfo
if not (List.isEmpty attributes) && (declKind = ExtrinsicExtensionBinding || declKind = IntrinsicExtensionBinding) then
let attributeRange = (List.head attributes).Range
Expand Down
27 changes: 24 additions & 3 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,18 @@ type ParallelReferenceResolution =
| On
| Off

[<RequireQualifiedAccess>]
type TypeCheckingMode =
safesparrow marked this conversation as resolved.
Show resolved Hide resolved
| Sequential
| Graph

[<RequireQualifiedAccess>]
type TypeCheckingConfig =
{
Mode: TypeCheckingMode
DumpGraph: bool
}

[<NoEquality; NoComparison>]
type TcConfigBuilder =
{
Expand Down Expand Up @@ -507,7 +519,6 @@ type TcConfigBuilder =
mutable emitTailcalls: bool
mutable deterministic: bool
mutable concurrentBuild: bool
mutable parallelCheckingWithSignatureFiles: bool
mutable parallelIlxGen: bool
mutable emitMetadataAssembly: MetadataAssemblyGeneration
mutable preferredUiLang: string option
Expand Down Expand Up @@ -591,6 +602,8 @@ type TcConfigBuilder =
mutable parallelReferenceResolution: ParallelReferenceResolution

mutable captureIdentifiersWhenParsing: bool

mutable typeCheckingConfig: TypeCheckingConfig
}

// Directories to start probing in
Expand Down Expand Up @@ -737,7 +750,6 @@ type TcConfigBuilder =
emitTailcalls = true
deterministic = false
concurrentBuild = true
parallelCheckingWithSignatureFiles = FSharpExperimentalFeaturesEnabledAutomatically
parallelIlxGen = FSharpExperimentalFeaturesEnabledAutomatically
emitMetadataAssembly = MetadataAssemblyGeneration.None
preferredUiLang = None
Expand Down Expand Up @@ -782,6 +794,15 @@ type TcConfigBuilder =
exiter = QuitProcessExiter
parallelReferenceResolution = ParallelReferenceResolution.Off
captureIdentifiersWhenParsing = false
typeCheckingConfig =
{
TypeCheckingConfig.Mode =
if FSharpExperimentalFeaturesEnabledAutomatically then
TypeCheckingMode.Graph
else
TypeCheckingMode.Sequential
DumpGraph = false
}
}

member tcConfigB.FxResolver =
Expand Down Expand Up @@ -1286,7 +1307,6 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.emitTailcalls = data.emitTailcalls
member _.deterministic = data.deterministic
member _.concurrentBuild = data.concurrentBuild
member _.parallelCheckingWithSignatureFiles = data.parallelCheckingWithSignatureFiles
member _.parallelIlxGen = data.parallelIlxGen
member _.emitMetadataAssembly = data.emitMetadataAssembly
member _.pathMap = data.pathMap
Expand Down Expand Up @@ -1322,6 +1342,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.exiter = data.exiter
member _.parallelReferenceResolution = data.parallelReferenceResolution
member _.captureIdentifiersWhenParsing = data.captureIdentifiersWhenParsing
member _.typeCheckingConfig = data.typeCheckingConfig

static member Create(builder, validate) =
use _ = UseBuildPhase BuildPhase.Parameter
Expand Down
26 changes: 22 additions & 4 deletions src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@ type ParallelReferenceResolution =
| On
| Off

/// Determines the algorithm used for type-checking.
[<RequireQualifiedAccess>]
type TypeCheckingMode =
/// Default mode where all source files are processed sequentially in compilation order.
| Sequential
/// Parallel type-checking that uses automated file-to-file dependency detection to construct a file graph processed in parallel.
| Graph

/// Some of the information dedicated to type-checking.
[<RequireQualifiedAccess>]
type TypeCheckingConfig =
{
Mode: TypeCheckingMode
/// When using TypeCheckingMode.Graph, this flag determines whether the
/// resolved file graph should be serialised as a Mermaid diagram into a file next to the output dll.
DumpGraph: bool
}

[<NoEquality; NoComparison>]
type TcConfigBuilder =
{
Expand Down Expand Up @@ -412,8 +430,6 @@ type TcConfigBuilder =

mutable concurrentBuild: bool

mutable parallelCheckingWithSignatureFiles: bool

mutable parallelIlxGen: bool

mutable emitMetadataAssembly: MetadataAssemblyGeneration
Expand Down Expand Up @@ -495,6 +511,8 @@ type TcConfigBuilder =
mutable parallelReferenceResolution: ParallelReferenceResolution

mutable captureIdentifiersWhenParsing: bool

mutable typeCheckingConfig: TypeCheckingConfig
}

static member CreateNew:
Expand Down Expand Up @@ -738,8 +756,6 @@ type TcConfig =

member concurrentBuild: bool

member parallelCheckingWithSignatureFiles: bool

member parallelIlxGen: bool

member emitMetadataAssembly: MetadataAssemblyGeneration
Expand Down Expand Up @@ -866,6 +882,8 @@ type TcConfig =

member captureIdentifiersWhenParsing: bool

member typeCheckingConfig: TypeCheckingConfig

/// Represents a computation to return a TcConfig. Normally this is just a constant immutable TcConfig,
/// but for F# Interactive it may be based on an underlying mutable TcConfigBuilder.
[<Sealed>]
Expand Down
11 changes: 10 additions & 1 deletion src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,8 +1372,17 @@ let testFlag tcConfigB =
| "ShowLoadedAssemblies" -> tcConfigB.showLoadedAssemblies <- true
| "ContinueAfterParseFailure" -> tcConfigB.continueAfterParseFailure <- true
| "ParallelOff" -> tcConfigB.concurrentBuild <- false
| "ParallelCheckingWithSignatureFilesOn" -> tcConfigB.parallelCheckingWithSignatureFiles <- true
| "ParallelIlxGen" -> tcConfigB.parallelIlxGen <- true
| "GraphBasedChecking" ->
tcConfigB.typeCheckingConfig <-
{ tcConfigB.typeCheckingConfig with
Mode = TypeCheckingMode.Graph
}
| "DumpCheckingGraph" ->
tcConfigB.typeCheckingConfig <-
{ tcConfigB.typeCheckingConfig with
DumpGraph = true
}
#if DEBUG
| "ShowParserStackOnParseError" -> showParserStackOnParseError <- true
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/Compiler/Driver/GraphChecking/Continuation.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[<RequireQualifiedAccess>]
module internal Continuation

let rec sequence<'a, 'ret> (recursions: (('a -> 'ret) -> 'ret) list) (finalContinuation: 'a list -> 'ret) : 'ret =
safesparrow marked this conversation as resolved.
Show resolved Hide resolved
match recursions with
| [] -> [] |> finalContinuation
| recurse :: recurses -> recurse (fun ret -> sequence recurses (fun rets -> ret :: rets |> finalContinuation))
4 changes: 4 additions & 0 deletions src/Compiler/Driver/GraphChecking/Continuation.fsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[<RequireQualifiedAccess>]
module internal Continuation

val sequence<'a, 'ret> : recursions: (('a -> 'ret) -> 'ret) list -> finalContinuation: ('a list -> 'ret) -> 'ret