@@ -51,7 +51,7 @@ type Vars = Map Name Var
5151
5252-- Find the minimal consistent usage by forward chaining.
5353minimalUsage :: Deps -> UseMap
54−minimalUsage = gather . forwardChain . triggerMain
54+minimalUsage = gather . forwardChain
5555 where
5656 gather :: Set (Name, Arg) -> UseMap
5757 gather = foldr ins M.empty . S.toList
@@ -60,13 +60,11 @@ minimalUsage = gather . forwardChain . triggerMain
6060 ins (n, Result) = id
6161 ins (n, Arg i ) = M.insertWith IS.union n (IS.singleton i)
6262
63− triggerMain :: Deps -> Deps
64− triggerMain = M.insertWith S.union S.empty $ S.singleton (main, Result)
65− where
66− main = NS (UN $ pack "main") [pack "Main"]
67−
6863forwardChain :: Deps -> Set Node
6964forwardChain deps
65+ | Just trivials <- M.lookup S.empty deps
66+ , ("==>", S.toList trivials) `traceShow` False = undefined
67+
7068 | Just trivials <- M.lookup S.empty deps
7169 = trivials `S.union` forwardChain (remove trivials . M.delete S.empty $ deps)
7270 | otherwise = S.empty
@@ -79,8 +77,14 @@ forwardChain deps
7977-- Build the dependency graph,
8078-- starting the depth-first search from a list of Names.
8179buildDepMap :: Context -> [Name] -> Deps
82−buildDepMap ctx ns = dfs S.empty M.empty ns
80+buildDepMap ctx ns = addMain $ dfs S.empty M.empty ns
8381 where
82+ -- mark the result of Main.main as used with the empty assumption
83+ addMain :: Deps -> Deps
84+ addMain = M.insertWith S.union S.empty $ S.singleton (main, Result)
85+ where
86+ main = NS (UN $ pack "main") [pack "Main"]
87+
8488 -- perform depth-first search
8589 -- to discover all the names used in the program
8690 -- and call getDeps for every name