Skip to content

Commit

Permalink
Correct algorithm to find dependent files. (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Nov 1, 2023
1 parent eb382c6 commit 3a553a7
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions fcs/service_slim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -432,24 +432,35 @@ type InteractiveChecker internal (compilerStateCache) =

let filePairs = FilePairMap(sourceFiles)
let graph, _trie = DependencyResolution.mkGraph filePairs sourceFiles
let findTransitiveDependencies (startNode : FileIndex) : FileIndex array =
let findTransitiveDependentFiles (startNode : FileIndex) : FileIndex array =
let rec dfs (node : FileIndex) (visited : Set<FileIndex>) (acc : FileIndex array) : FileIndex array =
if (Set.contains node visited) then
acc
else
let neighbors = graph.[node]
let visited' = Set.add node visited

let acc' =
Array.fold (fun innerAcc neighbor -> dfs neighbor visited' innerAcc) acc neighbors

[| yield! acc' ; yield node |]
let newVisited = Set.add node visited

let consumers =
// Last node in the project cannot have
if node = graph.Count - 1 then
acc
else
// Look if the next nodes depend on the current node
[| (node + 1) .. (graph.Count - 1) |]
|> Array.fold
(fun innerAcc nextIdx ->
if not (Array.contains node graph.[nextIdx]) then
innerAcc
else
dfs nextIdx newVisited innerAcc)
acc

[| yield node; yield! consumers |]

dfs startNode Set.empty Array.empty
|> Array.sort

let dependentFiles =
findTransitiveDependencies currentFileIdx
findTransitiveDependentFiles currentFileIdx
|> Array.sort
|> Array.map (fun idx -> Array.item idx fileNames)

Expand Down

0 comments on commit 3a553a7

Please sign in to comment.