Skip to content

Commit 4ebc64c

Browse files
committed
* Cleanup
* Start creating proper config
1 parent 0805660 commit 4ebc64c

File tree

15 files changed

+316
-164
lines changed

15 files changed

+316
-164
lines changed

src/Compiler/Driver/CompilerConfig.fs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,18 @@ type ParallelReferenceResolution =
393393
| On
394394
| Off
395395

396+
[<RequireQualifiedAccess>]
397+
type TypeCheckingMode =
398+
| Sequential
399+
| ParallelCheckingOfBackedImplFiles
400+
| Graph
401+
402+
[<RequireQualifiedAccess>]
403+
type TypeCheckingConfig =
404+
{
405+
Mode : TypeCheckingMode
406+
}
407+
396408
[<NoEquality; NoComparison>]
397409
type TcConfigBuilder =
398410
{
@@ -507,7 +519,6 @@ type TcConfigBuilder =
507519
mutable emitTailcalls: bool
508520
mutable deterministic: bool
509521
mutable concurrentBuild: bool
510-
mutable parallelCheckingWithSignatureFiles: bool
511522
mutable emitMetadataAssembly: MetadataAssemblyGeneration
512523
mutable preferredUiLang: string option
513524
mutable lcid: int option
@@ -587,6 +598,8 @@ type TcConfigBuilder =
587598
mutable exiter: Exiter
588599

589600
mutable parallelReferenceResolution: ParallelReferenceResolution
601+
602+
mutable typeCheckingConfig : TypeCheckingConfig
590603
}
591604

592605
// Directories to start probing in
@@ -733,7 +746,6 @@ type TcConfigBuilder =
733746
emitTailcalls = true
734747
deterministic = false
735748
concurrentBuild = true
736-
parallelCheckingWithSignatureFiles = false
737749
emitMetadataAssembly = MetadataAssemblyGeneration.None
738750
preferredUiLang = None
739751
lcid = None
@@ -775,6 +787,10 @@ type TcConfigBuilder =
775787
xmlDocInfoLoader = None
776788
exiter = QuitProcessExiter
777789
parallelReferenceResolution = ParallelReferenceResolution.Off
790+
typeCheckingConfig =
791+
{
792+
TypeCheckingConfig.Mode = TypeCheckingMode.Sequential
793+
}
778794
}
779795

780796
member tcConfigB.FxResolver =
@@ -1286,7 +1302,6 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
12861302
member _.emitTailcalls = data.emitTailcalls
12871303
member _.deterministic = data.deterministic
12881304
member _.concurrentBuild = data.concurrentBuild
1289-
member _.parallelCheckingWithSignatureFiles = data.parallelCheckingWithSignatureFiles
12901305
member _.emitMetadataAssembly = data.emitMetadataAssembly
12911306
member _.pathMap = data.pathMap
12921307
member _.langVersion = data.langVersion
@@ -1319,6 +1334,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
13191334
member _.xmlDocInfoLoader = data.xmlDocInfoLoader
13201335
member _.exiter = data.exiter
13211336
member _.parallelReferenceResolution = data.parallelReferenceResolution
1337+
member _.typeCheckingConfig = data.typeCheckingConfig
13221338

13231339
static member Create(builder, validate) =
13241340
use _ = UseBuildPhase BuildPhase.Parameter

src/Compiler/Driver/CompilerConfig.fsi

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ type ParallelReferenceResolution =
203203
| On
204204
| Off
205205

206+
[<RequireQualifiedAccess>]
207+
type TypeCheckingMode =
208+
| Sequential
209+
| ParallelCheckingOfBackedImplFiles
210+
| Graph
211+
212+
[<RequireQualifiedAccess>]
213+
type TypeCheckingConfig =
214+
{
215+
Mode : TypeCheckingMode
216+
}
217+
206218
[<NoEquality; NoComparison>]
207219
type TcConfigBuilder =
208220
{
@@ -412,8 +424,6 @@ type TcConfigBuilder =
412424

413425
mutable concurrentBuild: bool
414426

415-
mutable parallelCheckingWithSignatureFiles: bool
416-
417427
mutable emitMetadataAssembly: MetadataAssemblyGeneration
418428

419429
mutable preferredUiLang: string option
@@ -489,6 +499,8 @@ type TcConfigBuilder =
489499
mutable exiter: Exiter
490500

491501
mutable parallelReferenceResolution: ParallelReferenceResolution
502+
503+
mutable typeCheckingConfig : TypeCheckingConfig
492504
}
493505

494506
static member CreateNew:
@@ -732,8 +744,6 @@ type TcConfig =
732744

733745
member concurrentBuild: bool
734746

735-
member parallelCheckingWithSignatureFiles: bool
736-
737747
member emitMetadataAssembly: MetadataAssemblyGeneration
738748

739749
member pathMap: PathMap
@@ -853,6 +863,8 @@ type TcConfig =
853863
member exiter: Exiter
854864

855865
member parallelReferenceResolution: ParallelReferenceResolution
866+
867+
member typeCheckingConfig : TypeCheckingConfig
856868

857869
/// Represents a computation to return a TcConfig. Normally this is just a constant immutable TcConfig,
858870
/// but for F# Interactive it may be based on an underlying mutable TcConfigBuilder.

src/Compiler/Driver/CompilerOptions.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,8 @@ let testFlag tcConfigB =
13871387
| "ShowLoadedAssemblies" -> tcConfigB.showLoadedAssemblies <- true
13881388
| "ContinueAfterParseFailure" -> tcConfigB.continueAfterParseFailure <- true
13891389
| "ParallelOff" -> tcConfigB.concurrentBuild <- false
1390-
| "ParallelCheckingWithSignatureFilesOn" -> tcConfigB.parallelCheckingWithSignatureFiles <- true
1390+
| "ParallelCheckingWithSignatureFilesOn" ->
1391+
tcConfigB.typeCheckingConfig <- { tcConfigB.typeCheckingConfig with Mode = TypeCheckingMode.ParallelCheckingOfBackedImplFiles }
13911392
#if DEBUG
13921393
| "ShowParserStackOnParseError" -> showParserStackOnParseError <- true
13931394
#endif

src/Compiler/Driver/ParseAndCheckInputs.fs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,18 +1728,21 @@ let CheckMultipleInputsInParallel
17281728

17291729
results, tcState)
17301730

1731-
/// Use parallel checking of implementation files that have signature files
1732-
let mutable CheckMultipleInputsInParallel2 : CheckArgs -> (PartialResult list * TcState)
1731+
/// A mutable to allow injection the implementation from another project
1732+
let mutable CheckMultipleInputsUsingGraphMode : CheckArgs -> (PartialResult list * TcState)
17331733
=
1734-
CheckMultipleInputsInParallel
1734+
fun _ -> failwith $"Graph-based type-checking function not set - set CheckMultipleInputsUsingGraphMode before using this mode"
17351735

17361736
let CheckClosedInputSet (ctok, checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, eagerFormat, inputs) =
17371737
// tcEnvAtEndOfLastFile is the environment required by fsi.exe when incrementally adding definitions
17381738
let results, tcState =
1739-
if tcConfig.parallelCheckingWithSignatureFiles then
1740-
CheckMultipleInputsInParallel2(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, eagerFormat, inputs)
1741-
else
1739+
match tcConfig.typeCheckingConfig.Mode with
1740+
| TypeCheckingMode.Sequential ->
17421741
CheckMultipleInputsSequential(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs)
1742+
| TypeCheckingMode.ParallelCheckingOfBackedImplFiles ->
1743+
CheckMultipleInputsInParallel(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, eagerFormat, inputs)
1744+
| TypeCheckingMode.Graph ->
1745+
CheckMultipleInputsUsingGraphMode(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, eagerFormat, inputs)
17431746

17441747
let (tcEnvAtEndOfLastFile, topAttrs, implFiles, _), tcState =
17451748
CheckMultipleInputsFinish(results, tcState)

src/Compiler/Driver/ParseAndCheckInputs.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ val mutable fsiBackedInfos : System.Collections.Concurrent.ConcurrentDictionary<
156156
type CheckArgs = CompilationThreadToken * (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * (PhasedDiagnostic -> PhasedDiagnostic) * ParsedInput list
157157

158158
/// Use parallel checking of implementation files that have signature files
159-
val mutable CheckMultipleInputsInParallel2 : (CheckArgs -> PartialResult list * TcState)
159+
val mutable CheckMultipleInputsUsingGraphMode : (CheckArgs -> PartialResult list * TcState)
160160

161161
/// Get the initial type checking state for a set of inputs
162162
val GetInitialTcState: range * string * TcConfig * TcGlobals * TcImports * TcEnv * OpenDeclaration list -> TcState

src/Compiler/Service/IncrementalBuild.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,8 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc
15191519
}
15201520
|> Some
15211521

1522-
tcConfigB.parallelCheckingWithSignatureFiles <- enableParallelCheckingWithSignatureFiles
1522+
let mode = if enableParallelCheckingWithSignatureFiles then TypeCheckingMode.ParallelCheckingOfBackedImplFiles else TypeCheckingMode.Sequential
1523+
tcConfigB.typeCheckingConfig <- { tcConfigB.typeCheckingConfig with Mode = mode }
15231524
tcConfigB.parallelReferenceResolution <- parallelReferenceResolution
15241525

15251526
tcConfigB, sourceFilesNew

src/fsc/fscmain.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Timer(name : string) =
3030
member this.Dispose() = this.Dispose()
3131

3232

33-
let internal mainAux2 (argv : string[], onlyTypeCheck : bool, exiter : Exiter option) : int =
33+
let internal mainAux (argv : string[], onlyTypeCheck : bool, exiter : Exiter option) : int =
3434
use _ = FSharp.Compiler.Diagnostics.Activity.startNoTags "fscmain"
3535

3636
use _ = new Timer("main")
@@ -118,4 +118,4 @@ let internal mainAux2 (argv : string[], onlyTypeCheck : bool, exiter : Exiter op
118118

119119
[<EntryPoint>]
120120
let main (argv : string[]) : int =
121-
mainAux2 (argv, false, None)
121+
mainAux (argv, false, None)

tests/ParallelTypeCheckingTests/Code/ASTVisit.fs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
open FSharp.Compiler.Syntax
44
open FSharp.Compiler.SyntaxTrivia
55

6+
type SimpleId = string[]
7+
68
[<AutoOpen>]
79
module X =
810
let unsupported = "unsupported"
@@ -13,7 +15,7 @@ type ReferenceKind =
1315
/// Reference to a module or type, found in the AST
1416
type Reference =
1517
{
16-
Ident : LongIdent
18+
Ident : SimpleId
1719
Kind : ReferenceKind
1820
}
1921

@@ -28,13 +30,28 @@ type ReferenceOrAbbreviation =
2830

2931
type private References = ReferenceOrAbbreviation seq
3032

33+
type ReferenceSimple =
34+
{
35+
Ident : string[]
36+
Kind : ReferenceKind
37+
}
38+
39+
/// Reference to a module or type, found in the AST
40+
type ReferenceOrAbbreviationSimple =
41+
| Reference of ReferenceSimple
42+
| Abbreviation of Abbreviation
43+
3144
module Array =
3245
let split<'a, 'b, 'c> (splitter : 'a -> Choice<'b, 'c>) (items : 'a[]) =
3346
let items = items |> Array.map splitter
3447
items |> Array.choose (function Choice1Of2 x -> Some x | _ -> None),
3548
items |> Array.choose (function Choice2Of2 x -> Some x | _ -> None)
3649

3750
module ASTVisit =
51+
52+
let extractSimpleId (longIdent : LongIdent) : SimpleId =
53+
longIdent |> Seq.map (fun id -> id.idText) |> Seq.toArray
54+
3855
let rec visitSynModuleDecl (decl : SynModuleDecl) : References =
3956
// TODO
4057
match decl with
@@ -678,7 +695,7 @@ module ASTVisit =
678695
| SynOpenDeclTarget.Type(typeName, range) ->
679696
visitType typeName
680697
| SynOpenDeclTarget.ModuleOrNamespace(synLongIdent, range) ->
681-
[ReferenceOrAbbreviation.Reference {Ident = synLongIdent.LongIdent; Kind = ReferenceKind.ModuleOrNamespace}]
698+
[ReferenceOrAbbreviation.Reference {Ident = synLongIdent.LongIdent |> extractSimpleId; Kind = ReferenceKind.ModuleOrNamespace}]
682699

683700
and visitSynComponentInfo (info : SynComponentInfo) : References =
684701
match info with
@@ -693,10 +710,10 @@ module ASTVisit =
693710
}
694711

695712
and visitLongIdent (ident : LongIdent) : References =
696-
[ReferenceOrAbbreviation.Reference {Ident = ident; Kind = ReferenceKind.Type}]
713+
[ReferenceOrAbbreviation.Reference {Ident = ident |> extractSimpleId; Kind = ReferenceKind.Type}]
697714

698715
and visitSynLongIdent (ident : SynLongIdent) : References =
699-
[ReferenceOrAbbreviation.Reference {Ident = ident.LongIdent; Kind = ReferenceKind.Type}]
716+
[ReferenceOrAbbreviation.Reference {Ident = ident.LongIdent |> extractSimpleId; Kind = ReferenceKind.Type}]
700717

701718
and visitSynMatchClause (x : SynMatchClause) : References =
702719
match x with
@@ -1097,14 +1114,16 @@ module ASTVisit =
10971114
| ParsedInput.SigFile(ParsedSigFileInput(fileName, qualifiedNameOfFile, scopedPragmas, parsedHashDirectives, synModuleOrNamespaceSigs, parsedSigFileInputTrivia)) ->
10981115
synModuleOrNamespaceSigs
10991116
|> Seq.collect visitSynModuleOrNamespaceSig
1100-
|> Seq.toArray
11011117
| ParsedInput.ImplFile(ParsedImplFileInput(fileName, isScript, qualifiedNameOfFile, scopedPragmas, parsedHashDirectives, synModuleOrNamespaces, flags, parsedImplFileInputTrivia)) ->
11021118
synModuleOrNamespaces
11031119
|> Seq.collect visitSynModuleOrNamespace
1104-
|> Seq.toArray
1120+
|> Seq.distinct
1121+
|> Seq.toArray
1122+
1123+
11051124

11061125
/// Extract partial module references from partial module or type references
1107-
let extractModuleSegments (stuff : ReferenceOrAbbreviation seq): LongIdent[] * Abbreviation[] =
1126+
let extractModuleSegments (stuff : ReferenceOrAbbreviation seq): SimpleId[] * Abbreviation[] =
11081127
let refs, abbreviations =
11091128
stuff
11101129
|> Seq.toArray
@@ -1120,7 +1139,7 @@ module ASTVisit =
11201139
match x.Ident.Length with
11211140
| 0
11221141
| 1 -> None
1123-
| n -> x.Ident.GetSlice(Some 0, n - 2 |> Some) |> Some
1142+
| n -> x.Ident[0..n-2] |> Some
11241143
)
11251144
|> Seq.toArray
11261145

@@ -1276,3 +1295,5 @@ module TopModulesExtraction =
12761295
items
12771296
|> List.toArray
12781297
|> Array.collect topStuffForSynModuleOrNamespaceSig
1298+
|> Array.map ASTVisit.extractSimpleId
1299+
|> Array.distinct

tests/ParallelTypeCheckingTests/Code/DepResolving.fs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ open ParallelTypeCheckingTests
88
open ParallelTypeCheckingTests.FileInfoGathering
99
open ParallelTypeCheckingTests.Graph
1010
open ParallelTypeCheckingTests.Types
11-
open ParallelTypeCheckingTests.ASTVisit
1211
open FSharp.Compiler.Syntax
1312

1413
let log (msg : string) =
@@ -88,19 +87,19 @@ module internal AutomatedDependencyResolving =
8887
let buildTrie (files : FileData[]) : TrieNode =
8988
let root = emptyTrie()
9089

91-
let addFileIdent (file : FileData) (ident : LongIdent) =
90+
let addFileIdent (file : FileData) (ident : SimpleId) =
9291
// Go down from root using segments of the identifier, possibly extending the Trie with new nodes.
9392
let mutable node = root
9493
for segment in ident do
9594
let child =
96-
match node.Children.TryGetValue segment.idText with
95+
match node.Children.TryGetValue segment with
9796
// Child exists
9897
| true, child ->
9998
child
10099
// Child doesn't exist
101100
| false, _ ->
102101
let child = emptyTrie()
103-
node.Children[segment.idText] <- child
102+
node.Children[segment] <- child
104103
child
105104
node <- child
106105
// Add the file to the found leaf's list
@@ -195,24 +194,24 @@ module internal AutomatedDependencyResolving =
195194
/// When the path leads outside the Trie, the Trie is not extended and no node is marked as a potential prefix.
196195
/// This is just a performance optimisation - all the files are linked to already existing nodes, so there is no need to create and visit deeper nodes.
197196
/// </remarks>
198-
let rec walkDownAndMark (id : LongIdent) (node : TrieNode) =
197+
let rec walkDownAndMark (id : SimpleId) (node : TrieNode) =
199198
match id with
200199
// Reached end of the identifier - new reachable node
201-
| [] ->
200+
| [||] ->
202201
markPotentialPrefix node
203202
// More segments exist
204-
| segment :: rest ->
203+
| id ->
205204
// Visit (not 'reach') the TrieNode
206205
markReachable node
207-
match node.Children.TryGetValue(segment.idText) with
206+
match node.Children.TryGetValue id[0] with
208207
// A child for the segment exists - continue there
209208
| true, child ->
210-
walkDownAndMark rest child
209+
walkDownAndMark id[1..] child
211210
// A child for the segment doesn't exist - stop, since we don't care about the non-existent part of the Trie
212211
| false, _ ->
213212
()
214213

215-
let processRef (id : LongIdent) =
214+
let processRef (id : SimpleId) =
216215
// Start at every potential prefix,
217216
List<_>(potentialPrefixes) // Copy the list for iteration as the original is going to be extended.
218217
// Extend potential prefixes with this 'id'

tests/ParallelTypeCheckingTests/Code/FileInfoGathering.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ let internal gatherBackingInfo (files : SourceFiles) : Files =
3232
type ExtractedData =
3333
{
3434
/// Order of the file in the project. Files with lower number cannot depend on files with higher number
35-
Tops : LongIdent[]
35+
Tops : SimpleId[]
3636
Abbreviations : Abbreviation[]
3737
/// All partial module references found in this file's AST
38-
ModuleRefs : LongIdent[]
38+
ModuleRefs : SimpleId[]
3939
}
4040

4141
/// All the data about a single file needed for the dependency resolution algorithm

0 commit comments

Comments
 (0)