summaryrefslogtreecommitdiff
path: root/compiler/GHC/Data/Graph/Directed.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/GHC/Data/Graph/Directed.hs')
-rw-r--r--compiler/GHC/Data/Graph/Directed.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/GHC/Data/Graph/Directed.hs b/compiler/GHC/Data/Graph/Directed.hs
index 2e1d13bec5..74e619ef90 100644
--- a/compiler/GHC/Data/Graph/Directed.hs
+++ b/compiler/GHC/Data/Graph/Directed.hs
@@ -7,6 +7,7 @@
module GHC.Data.Graph.Directed (
Graph, graphFromEdgedVerticesOrd, graphFromEdgedVerticesUniq,
+ graphFromVerticesAndAdjacency,
SCC(..), Node(..), flattenSCC, flattenSCCs,
stronglyConnCompG,
@@ -547,3 +548,21 @@ classifyEdges root getSucc edges =
ends'' = addToUFM ends' n time''
in
(time'' + 1, starts'', ends'')
+
+graphFromVerticesAndAdjacency
+ :: Ord key
+ => [Node key payload]
+ -> [(key, key)] -- First component is source vertex key,
+ -- second is target vertex key (thing depended on)
+ -- Unlike the other interface I insist they correspond to
+ -- actual vertices because the alternative hides bugs. I can't
+ -- do the same thing for the other one for backcompat reasons.
+ -> Graph (Node key payload)
+graphFromVerticesAndAdjacency [] _ = emptyGraph
+graphFromVerticesAndAdjacency vertices edges = Graph graph vertex_node (key_vertex . key_extractor)
+ where key_extractor = node_key
+ (bounds, vertex_node, key_vertex, _) = reduceNodesIntoVerticesOrd vertices key_extractor
+ key_vertex_pair (a, b) = (expectJust "graphFromVerticesAndAdjacency" $ key_vertex a,
+ expectJust "graphFromVerticesAndAdjacency" $ key_vertex b)
+ reduced_edges = map key_vertex_pair edges
+ graph = buildG bounds reduced_edges