@@ -179,34 +179,28 @@ let collectGhostDependencies (fileIndex: int) (trie: TrieNode) (queryTrie: Query
179179 Array.empty)
180180
181181let 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
0 commit comments