Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
0101 committed Sep 4, 2023
1 parent 81421fe commit 7612843
Show file tree
Hide file tree
Showing 14 changed files with 470 additions and 431 deletions.
42 changes: 0 additions & 42 deletions src/Compiler/Driver/GraphChecking/Graph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,48 +75,6 @@ module internal Graph =
|> readOnlyDict
|> addIfMissing originalGraph.Keys

/// Returns leaves of the graph and the remaining graph without the leaves.
let cutLeaves (graph: Graph<'Node>) =
let notLeaves =
set
[
for (KeyValue (node, deps)) in graph do
if deps.Length > 0 then
node
]

let leaves =
set
[
for (KeyValue (node, deps)) in graph do
if deps.Length = 0 then
node

yield! deps |> Array.filter (notLeaves.Contains >> not)
]

leaves,
seq {
for (KeyValue (node, deps)) in graph do
if deps.Length > 0 then
node, deps |> Array.filter (leaves.Contains >> not)
}
|> make

/// Returns layers of leaves repeatedly removed from the graph until there's nothing left
let leafSequence (graph: Graph<'Node>) =
let rec loop (graph: Graph<'Node>) acc =
match graph |> cutLeaves with
| leaves, _ when leaves.IsEmpty -> acc
| leaves, graph ->
seq {
yield! acc
leaves
}
|> loop graph

loop graph Seq.empty

let printCustom (graph: Graph<'Node>) (nodePrinter: 'Node -> string) : unit =
printfn "Graph:"
let join (xs: string[]) = System.String.Join(", ", xs)
Expand Down
2 changes: 0 additions & 2 deletions src/Compiler/Driver/GraphChecking/Graph.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ module internal Graph =
val subGraphFor: node: 'Node -> graph: Graph<'Node> -> Graph<'Node> when 'Node: equality
/// Create a reverse of the graph.
val reverse<'Node when 'Node: equality> : originalGraph: Graph<'Node> -> Graph<'Node>
/// Returns layers of leaves repeatedly removed from the graph until there's nothing left
val leafSequence: graph: Graph<'Node> -> Set<'Node> seq
/// Print the contents of the graph to the standard output.
val print: graph: Graph<'Node> -> unit
/// Create a simple Mermaid graph
Expand Down
16 changes: 9 additions & 7 deletions src/Compiler/Driver/GraphChecking/GraphProcessing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,13 @@ let processGraphAsync<'Item, 'Result when 'Item: equality and 'Item: comparison>

let raiseExn (item, ex: exn) =
localCts.Cancel()
match ex with
| :? OperationCanceledException ->
completionSignal.TrySetCanceled()
| _ ->
completionSignal.TrySetException(GraphProcessingException($"[*] Encountered exception when processing item '{item}': {ex.Message}", ex))

match ex with
| :? OperationCanceledException -> completionSignal.TrySetCanceled()
| _ ->
completionSignal.TrySetException(
GraphProcessingException($"[*] Encountered exception when processing item '{item}': {ex.Message}", ex)
)
|> ignore

let incrementProcessedNodesCount () =
Expand Down Expand Up @@ -280,8 +282,8 @@ let processGraphAsync<'Item, 'Result when 'Item: equality and 'Item: comparison>
leaves |> Array.iter queueNode

// Wait for end of processing, an exception, or an external cancellation request.
do! completionSignal.Task |> Async.AwaitTask
do! completionSignal.Task |> Async.AwaitTask

// All calculations succeeded - extract the results and sort in input order.
return
nodes.Values
Expand Down
Loading

0 comments on commit 7612843

Please sign in to comment.