Skip to content

Correct algorithm to find dependent files. #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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