on master help sign in
addMain moved to buildDepMap.
8022aadMatus Tejiscak
src/Idris/Erasure.hs+11−7
@@ -51,7 +51,7 @@ type Vars = Map Name Var
51
51
52-- Find the minimal consistent usage by forward chaining.
52-- Find the minimal consistent usage by forward chaining.
53minimalUsage :: Deps -> UseMap
53minimalUsage :: Deps -> UseMap
54−minimalUsage = gather . forwardChain . triggerMain
54+minimalUsage = gather . forwardChain
55 where
55 where
56 gather :: Set (Name, Arg) -> UseMap
56 gather :: Set (Name, Arg) -> UseMap
57 gather = foldr ins M.empty . S.toList
57 gather = foldr ins M.empty . S.toList
@@ -60,13 +60,11 @@ minimalUsage = gather . forwardChain . triggerMain
60 ins (n, Result) = id
60 ins (n, Result) = id
61 ins (n, Arg i ) = M.insertWith IS.union n (IS.singleton i)
61 ins (n, Arg i ) = M.insertWith IS.union n (IS.singleton i)
62
62
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−
68forwardChain :: Deps -> Set Node
63forwardChain :: Deps -> Set Node
69forwardChain deps
64forwardChain deps
65+ | Just trivials <- M.lookup S.empty deps
66+ , ("==>", S.toList trivials) `traceShow` False = undefined
67+
70 | Just trivials <- M.lookup S.empty deps
68 | Just trivials <- M.lookup S.empty deps
71 = trivials `S.union` forwardChain (remove trivials . M.delete S.empty $ deps)
69 = trivials `S.union` forwardChain (remove trivials . M.delete S.empty $ deps)
72 | otherwise = S.empty
70 | otherwise = S.empty
@@ -79,8 +77,14 @@ forwardChain deps
79-- Build the dependency graph,
77-- Build the dependency graph,
80-- starting the depth-first search from a list of Names.
78-- starting the depth-first search from a list of Names.
81buildDepMap :: Context -> [Name] -> Deps
79buildDepMap :: Context -> [Name] -> Deps
82−buildDepMap ctx ns = dfs S.empty M.empty ns
80+buildDepMap ctx ns = addMain $ dfs S.empty M.empty ns
83 where
81 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+
84 -- perform depth-first search
88 -- perform depth-first search
85 -- to discover all the names used in the program
89 -- to discover all the names used in the program
86 -- and call getDeps for every name
90 -- and call getDeps for every name