Skip to content

Commit 4ae81ee

Browse files
committed
Rename new types.
1 parent e6ee19f commit 4ae81ee

1 file changed

Lines changed: 35 additions & 33 deletions

File tree

tests/ParallelTypeCheckingTests/Code/ParallelTypeChecking.fs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ type PartialResult = TcEnv * TopAttribs * CheckedImplFile option * ModuleOrNames
3535
let folder (state: State) (result: SingleResult) : FinalFileResult * State = result state
3636

3737
[<RequireQualifiedAccess>]
38-
type Dependency =
38+
type NodeToTypeCheck =
39+
/// A real physical file in the current project.
40+
/// This can be either an implementation or a signature file.
3941
| PhysicalFile of fileIndex: int
40-
| Pair of signatureFileIndex: int
42+
/// An artificial node that will add the earlier processed signature information to the TcEnvFromImpls.
43+
/// Dependants on this type of node will perceive that a file is known in both TcEnvFromSignatures and TcEnvFromImpls.
44+
/// Even though the actual implementation file was not type-checked.
45+
| ArtificialImplFile of signatureFileIndex: int
4146

4247
/// Use parallel checking of implementation files that have signature files
4348
let CheckMultipleInputsInParallel
@@ -63,28 +68,25 @@ let CheckMultipleInputsInParallel
6368
// When type checking a file, depending on the type (implementation or signature), it will use one of these typing environments (TcEnv).
6469
// Checking a file will populate the respective TcEnv.
6570
//
66-
// When a file has a dependencies, the information of the signature file in case a pair (1) will suffice to type-check the file.
67-
// Example: if `B.fs` has a dependency on `A`, the information of `A.fsi` is enough for `B.fs` to type-check,
68-
// on condition that it is available in the TcEnvFromImpls.
69-
// We introduce a special Pair dependency node in the graph to satisfy this. `B.fs -> [ A.fsi ]` becomes `B.fs -> [ Pair<A> ].
70-
// The `Pair<A>` node will duplicate the signature information which A.fsi provided.
71-
// Processing a Pair will add the information from the TcEnvFromSignatures to the TcEnvFromImpls.
71+
// When a file has a dependencies, the information of the signature file in case a pair (implementation file backed by a signature) will suffice to type-check that file.
72+
// Example: if `B.fs` has a dependency on `A`, the information of `A.fsi` is enough for `B.fs` to type-check, on condition that information is available in the TcEnvFromImpls.
73+
// We introduce a special ArtificialImplFile node in the graph to satisfy this. `B.fs -> [ A.fsi ]` becomes `B.fs -> [ ArtificialImplFile A ].
74+
// The `ArtificialImplFile A` node will duplicate the signature information which A.fsi provided earlier.
75+
// Processing a `ArtificialImplFile` node will add the information from the TcEnvFromSignatures to the TcEnvFromImpls.
7276
// This means `A` will be known in both TcEnvs and therefor `B.fs` can be type-checked.
7377
// By doing this, we can speed up the graph processing as type checking a signature file is less expensive than its implementation counterpart.
7478
//
75-
// When we need to actually type-check the implementation file of a Pair, we cannot have the duplicate information of the signature file present in TcEnvFromImpls.
76-
// Example `A.fs -> [ A.fsi ]`, because an implementation file always depends on its signature.
77-
// Type-checking `A.fs` will add the actual information to TcEnvFromImpls and we do not depend on the Pair<A> for `A.fs` itself.
79+
// When we need to actually type-check an implementation file backed by a signature, we cannot have the duplicate information of the signature file present in TcEnvFromImpls.
80+
// Example `A.fs -> [ A.fsi ]`. An implementation file always depends on its signature.
81+
// Type-checking `A.fs` will add the actual information to TcEnvFromImpls and we do not depend on the `ArtificialImplFile A` for `A.fs`.
7882
//
79-
// In order to deal correctly with the Pair logic, we need to transform the resolved graph to contain the additional pair nodes.
80-
// After we have type-checked the graph, we exclude the Pair nodes as they are not actual physical files in our project.
81-
//
82-
// (1) : A pair is consider the combination of a implementation and signature file. (For example `A.fsi` and matching `A.fs` is Pair<A>)
83-
let dependencyGraph =
84-
let mkPair n = Dependency.Pair n
85-
let mkPhysicalFile n = Dependency.PhysicalFile n
83+
// In order to deal correctly with the `ArtificialImplFile` logic, we need to transform the resolved graph to contain the additional pair nodes.
84+
// After we have type-checked the graph, we exclude the ArtificialImplFile nodes as they are not actual physical files in our project.
85+
let nodeGraph =
86+
let mkArtificialImplFile n = NodeToTypeCheck.ArtificialImplFile n
87+
let mkPhysicalFile n = NodeToTypeCheck.PhysicalFile n
8688

87-
// Map any signature dependencies to the Pair counterparts.
89+
// Map any signature dependencies to the ArtificialImplFile counterparts.
8890
// Unless, the signature dependency is the backing file of the current (implementation) file.
8991
let mapDependencies idx deps =
9092
Array.map
@@ -97,21 +99,21 @@ let CheckMultipleInputsInParallel
9799
// Keep using the physical file
98100
mkPhysicalFile dep
99101
else
100-
mkPair dep
102+
mkArtificialImplFile dep
101103
else
102104
mkPhysicalFile dep)
103105
deps
104106

105-
// Transform the graph to include Pair nodes when necessary.
107+
// Transform the graph to include ArtificialImplFile nodes when necessary.
106108
graph
107109
|> Seq.collect (fun (KeyValue (fileIdx, deps)) ->
108110
if filePairs.IsSignature fileIdx then
109-
// Add an additional Pair node for the signature file.
111+
// Add an additional ArtificialImplFile node for the signature file.
110112
[|
111113
// Mark the current file as physical and map the dependencies.
112114
mkPhysicalFile fileIdx, mapDependencies fileIdx deps
113115
// Introduce a new node that depends on the signature.
114-
mkPair fileIdx, [| mkPhysicalFile fileIdx |]
116+
mkArtificialImplFile fileIdx, [| mkPhysicalFile fileIdx |]
115117
|]
116118
else
117119
[| mkPhysicalFile fileIdx, mapDependencies fileIdx deps |])
@@ -140,7 +142,7 @@ let CheckMultipleInputsInParallel
140142

141143
let mutable cnt = 1
142144

143-
let processPair (input: ParsedInput) ((currentTcState, _currentPriorErrors): State) : State -> PartialResult * State =
145+
let processArtificialImplFile (input: ParsedInput) ((currentTcState, _currentPriorErrors): State) : State -> PartialResult * State =
144146
fun (state: State) ->
145147
let tcState, currentPriorErrors = state
146148

@@ -195,25 +197,25 @@ let CheckMultipleInputsInParallel
195197
let logger = DiagnosticsLoggerForInput(tcConfig, input, oldLogger)
196198
input, logger)
197199

198-
let processFile (dependency: Dependency) (state: State) : State -> PartialResult * State =
199-
match dependency with
200-
| Dependency.Pair idx ->
200+
let processFile (node: NodeToTypeCheck) (state: State) : State -> PartialResult * State =
201+
match node with
202+
| NodeToTypeCheck.ArtificialImplFile idx ->
201203
let parsedInput, _ = inputsWithLoggers.[idx]
202-
processPair parsedInput state
203-
| Dependency.PhysicalFile idx ->
204+
processArtificialImplFile parsedInput state
205+
| NodeToTypeCheck.PhysicalFile idx ->
204206
let parsedInput, logger = inputsWithLoggers.[idx]
205207
processFile (parsedInput, logger) state
206208

207209
let state: State = tcState, priorErrors
208210

209211
let partialResults, (tcState, _) =
210-
TypeCheckingGraphProcessing.processFileGraph<Dependency, State, SingleResult, FinalFileResult>
211-
dependencyGraph
212+
TypeCheckingGraphProcessing.processFileGraph<NodeToTypeCheck, State, SingleResult, FinalFileResult>
213+
nodeGraph
212214
processFile
213215
folder
214216
(function
215-
| Dependency.Pair _ -> false
216-
| Dependency.PhysicalFile _ -> true)
217+
| NodeToTypeCheck.ArtificialImplFile _ -> false
218+
| NodeToTypeCheck.PhysicalFile _ -> true)
217219
state
218220
cts.Token
219221

0 commit comments

Comments
 (0)