setStages :: [Node] -> [Node]
setStages nodes0 = snd (mapAccumL go Map.empty nodes0)
  where
  nodeMap = Map.fromList [ (fun n, n) | n <- nodes0 ]

  go done nd =
    case Map.lookup (fun nd) done of
      Just s  -> (done, s)
      Nothing -> let (done1, nodes) = mapAccumL go' done (calls nd)
                     newStage       = maximum (0 : map ((+ 1) . stage) nodes)
                     node           = nd { stage = newStage }
                 in (Map.insert (fun nd) node done1, node)

  go' done nodeId      = case Map.lookup nodeId nodeMap of
                           Just node -> go done node
                           Nothing ->
                             error ("getStages: Missing node " ++ show nodeId)



-- | What functions are called by this function.
-- This does not use the `depends` infracstrucutre, it is extracted
-- directly from the `holes.hs` file.
setStages :: [Node] -> [Node]
setStages nodes0 = snd (mapAccumL go Map.empty nodes0)
  where
  nodeMap = Map.fromList [ (fun n, n) | n <- nodes0 ]

  go done nd =
    case Map.lookup (fun nd) done of
      Just s  -> (done, s)
      Nothing -> let (done1, nodes) = mapAccumL go' done (calls nd)
                     newStage       = maximum (0 : map ((+ 1) . stage) nodes)
                     node           = nd { stage = newStage }
                 in (Map.insert (fun nd) node done1, node)

  go' done nodeId      = case Map.lookup nodeId nodeMap of
                           Just node -> go done node
                           Nothing ->
                             error ("getStages: Missing node " ++ show nodeId)



-- | What functions are called by this function.
-- This does not use the `depends` infracstrucutre, it is extracted
-- directly from the `holes.hs` file.
setStages nodes0 = snd (mapAccumL go Map.empty nodes0)
  where
  nodeMap = Map.fromList [ (fun n, n) | n <- nodes0 ]

  go done nd =
    case Map.lookup (fun nd) done of
      Just s  -> (done, s)
      Nothing -> let (done1, nodes) = mapAccumL go' done (calls nd)
                     newStage       = maximum (0 : map ((+ 1) . stage) nodes)
                     node           = nd { stage = newStage }
                 in (Map.insert (fun nd) node done1, node)

  go' done nodeId      = case Map.lookup nodeId nodeMap of
                           Just node -> go done node
                           Nothing ->
                             error ("getStages: Missing node " ++ show nodeId)



-- | What functions are called by this function.
-- This does not use the `depends` infracstrucutre, it is extracted
-- directly from the `holes.hs` file.