Skip to content

Commit 46505f3

Browse files
committed
Remove implementation index for signature files in trie.
1 parent e96d98f commit 46505f3

3 files changed

Lines changed: 17 additions & 22 deletions

File tree

tests/ParallelTypeCheckingTests/Code/DependencyResolution.fs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,34 +179,28 @@ let collectGhostDependencies (fileIndex: int) (trie: TrieNode) (queryTrie: Query
179179
Array.empty)
180180

181181
let mkGraph (files: FileWithAST array) : Graph<int> =
182-
// File pairs to easily retrieve the signature file from a
183-
let implToSig, sigToImpl =
182+
// Map to easily retrieve the signature file index
183+
let implToSig =
184184
Array.choose
185185
(fun f ->
186186
match f.AST with
187187
| ParsedInput.SigFile _ ->
188-
let implIdx =
189-
files
190-
|> Array.skip (f.Idx + 1)
191-
|> Array.tryFind (fun (implFile: FileWithAST) -> $"{implFile.File}i" = f.File)
192-
193-
Option.map (fun (implFile: FileWithAST) -> (implFile.Idx, f.Idx), (f.Idx, implFile.Idx)) implIdx
188+
files
189+
|> Array.skip (f.Idx + 1)
190+
|> Array.tryFind (fun (implFile: FileWithAST) -> $"{implFile.File}i" = f.File)
191+
|> Option.map (fun (implFile: FileWithAST) -> (implFile.Idx, f.Idx))
194192
| ParsedInput.ImplFile _ -> None)
195193
files
196-
|> Array.unzip
197-
|> fun (implToSig, sigToImpl) -> Map.ofArray implToSig, Map.ofArray sigToImpl
194+
|> Map.ofArray
198195

199196
// Implementation files backed by signatures should be excluded to construct the trie.
200197
// Signature files should link to the implementation index instead.
201198
let trieInput =
202199
Array.choose
203200
(fun f ->
204201
match f.AST with
205-
| ParsedInput.SigFile _ -> Map.tryFind f.Idx sigToImpl |> Option.map (fun implIdx -> (f, implIdx))
206-
| ParsedInput.ImplFile _ ->
207-
match Map.tryFind f.Idx implToSig with
208-
| Some _ -> None
209-
| None -> Some(f, f.Idx))
202+
| ParsedInput.SigFile _ -> Some f
203+
| ParsedInput.ImplFile _ -> if Map.containsKey f.Idx implToSig then None else Some f)
210204
files
211205

212206
let trie = TrieMapping.mkTrie trieInput
@@ -216,9 +210,9 @@ let mkGraph (files: FileWithAST array) : Graph<int> =
216210

217211
let filesWithAutoOpen =
218212
Array.choose
219-
(fun (f, idx) ->
213+
(fun f ->
220214
if AlwaysLinkDetection.doesFileHasAutoOpenBehavior f.AST then
221-
Some idx
215+
Some f.Idx
222216
else
223217
None)
224218
trieInput

tests/ParallelTypeCheckingTests/Code/TrieMapping.fs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ let mergeTrieNodes (defaultChildSize: int) (tries: TrieNode array) =
4646
let hs f = HashSet(Seq.singleton f)
4747
let emptyHS () = HashSet(0)
4848

49-
let rec mkTrieNodeFor (file: FileWithAST, idx: int) : TrieNode =
49+
let rec mkTrieNodeFor (file: FileWithAST) : TrieNode =
50+
let idx = file.Idx
51+
5052
match file.AST with
5153
| ParsedInput.SigFile (ParsedSigFileInput (contents = contents)) ->
5254
contents
@@ -228,7 +230,7 @@ and mkTrieForNestedSigModule (fileIndex: int) (decl: SynModuleSigDecl) : KeyValu
228230

229231
| _ -> None
230232

231-
let mkTrie (files: (FileWithAST * int) array) : TrieNode =
233+
let mkTrie (files: FileWithAST array) : TrieNode =
232234
mergeTrieNodes 0 (Array.Parallel.map mkTrieNodeFor files)
233235

234236
// ==================================================================================================================================================
@@ -266,7 +268,7 @@ let ``Fantomas Core trie`` () =
266268
|]
267269
|> Array.mapi (fun idx file ->
268270
let ast = parseSourceCode (file, System.IO.File.ReadAllText(file))
269-
{ Idx = idx; File = file; AST = ast }, idx)
271+
{ Idx = idx; File = file; AST = ast })
270272

271273
let trie = mkTrie files
272274
ignore trie

tests/ParallelTypeCheckingTests/Tests/TrieMappingTests.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ let ``Basic trie`` () =
3535
Idx = idx
3636
File = fileName
3737
AST = parseSourceCode (fileName, code)
38-
},
39-
idx)
38+
})
4039

4140
let trie = TrieMapping.mkTrie files
4241

0 commit comments

Comments
 (0)