Skip to content

Commit

Permalink
Remove implementation index for signature files in trie.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 28, 2022
1 parent e96d98f commit 46505f3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
28 changes: 11 additions & 17 deletions tests/ParallelTypeCheckingTests/Code/DependencyResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -179,34 +179,28 @@ let collectGhostDependencies (fileIndex: int) (trie: TrieNode) (queryTrie: Query
Array.empty)

let mkGraph (files: FileWithAST array) : Graph<int> =
// File pairs to easily retrieve the signature file from a
let implToSig, sigToImpl =
// Map to easily retrieve the signature file index
let implToSig =
Array.choose
(fun f ->
match f.AST with
| ParsedInput.SigFile _ ->
let implIdx =
files
|> Array.skip (f.Idx + 1)
|> Array.tryFind (fun (implFile: FileWithAST) -> $"{implFile.File}i" = f.File)

Option.map (fun (implFile: FileWithAST) -> (implFile.Idx, f.Idx), (f.Idx, implFile.Idx)) implIdx
files
|> Array.skip (f.Idx + 1)
|> Array.tryFind (fun (implFile: FileWithAST) -> $"{implFile.File}i" = f.File)
|> Option.map (fun (implFile: FileWithAST) -> (implFile.Idx, f.Idx))
| ParsedInput.ImplFile _ -> None)
files
|> Array.unzip
|> fun (implToSig, sigToImpl) -> Map.ofArray implToSig, Map.ofArray sigToImpl
|> Map.ofArray

// Implementation files backed by signatures should be excluded to construct the trie.
// Signature files should link to the implementation index instead.
let trieInput =
Array.choose
(fun f ->
match f.AST with
| ParsedInput.SigFile _ -> Map.tryFind f.Idx sigToImpl |> Option.map (fun implIdx -> (f, implIdx))
| ParsedInput.ImplFile _ ->
match Map.tryFind f.Idx implToSig with
| Some _ -> None
| None -> Some(f, f.Idx))
| ParsedInput.SigFile _ -> Some f
| ParsedInput.ImplFile _ -> if Map.containsKey f.Idx implToSig then None else Some f)
files

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

let filesWithAutoOpen =
Array.choose
(fun (f, idx) ->
(fun f ->
if AlwaysLinkDetection.doesFileHasAutoOpenBehavior f.AST then
Some idx
Some f.Idx
else
None)
trieInput
Expand Down
8 changes: 5 additions & 3 deletions tests/ParallelTypeCheckingTests/Code/TrieMapping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ let mergeTrieNodes (defaultChildSize: int) (tries: TrieNode array) =
let hs f = HashSet(Seq.singleton f)
let emptyHS () = HashSet(0)

let rec mkTrieNodeFor (file: FileWithAST, idx: int) : TrieNode =
let rec mkTrieNodeFor (file: FileWithAST) : TrieNode =
let idx = file.Idx

match file.AST with
| ParsedInput.SigFile (ParsedSigFileInput (contents = contents)) ->
contents
Expand Down Expand Up @@ -228,7 +230,7 @@ and mkTrieForNestedSigModule (fileIndex: int) (decl: SynModuleSigDecl) : KeyValu

| _ -> None

let mkTrie (files: (FileWithAST * int) array) : TrieNode =
let mkTrie (files: FileWithAST array) : TrieNode =
mergeTrieNodes 0 (Array.Parallel.map mkTrieNodeFor files)

// ==================================================================================================================================================
Expand Down Expand Up @@ -266,7 +268,7 @@ let ``Fantomas Core trie`` () =
|]
|> Array.mapi (fun idx file ->
let ast = parseSourceCode (file, System.IO.File.ReadAllText(file))
{ Idx = idx; File = file; AST = ast }, idx)
{ Idx = idx; File = file; AST = ast })

let trie = mkTrie files
ignore trie
3 changes: 1 addition & 2 deletions tests/ParallelTypeCheckingTests/Tests/TrieMappingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ let ``Basic trie`` () =
Idx = idx
File = fileName
AST = parseSourceCode (fileName, code)
},
idx)
})

let trie = TrieMapping.mkTrie files

Expand Down

0 comments on commit 46505f3

Please sign in to comment.