on master help sign in
Don't analyse programs without main.
commit3521b16b0a6954331f496a55fb36cbc9649a0e73 authorMatus Tejiscak <ziman@functor.sk> dateTue 11 Feb 2014, 15:55 (13 years ago) parentdfb2663
1 file changed+19−13
src/Idris/Erasure.hs+19−13
src/Idris/Erasure.hs+19−13
@@ -53,24 +53,30 @@ type Vars = Map Name Var
5353performUsageAnalysis :: Idris [Name]
5454performUsageAnalysis = do
5555 ctx <- tt_ctxt <$> getIState
56− ci <- idris_classes <$> getIState
5756
58− -- Build the dependency graph.
59− let depMap = buildDepMap ci ctx (sNS (sUN "main") ["Main"])
57+ case lookupCtxt mainName (definitions ctx) of
58+ [] -> return [] -- no main -> not compiling -> reachability irrelevant
59+ _ -> do
60+ ci <- idris_classes <$> getIState
6061
61− -- Search for reachable nodes in the graph.
62− let (residDeps, (reachableNames, minUse)) = minimalUsage depMap
62+ -- Build the dependency graph.
63+ let depMap = buildDepMap ci ctx mainName
6364
64− -- Print some debug info.
65− logLvl 3 $ "Reachable names:\n" ++ unlines (map show . S.toList $ reachableNames)
66− logLvl 4 $ "Minimal usage:\n" ++ fmtUseMap minUse
67− logLvl 5 $ "Residual deps:\n" ++ unlines (map fmtItem . M.toList $ residDeps)
65+ -- Search for reachable nodes in the graph.
66+ let (residDeps, (reachableNames, minUse)) = minimalUsage depMap
6867
69− -- Store the usage info in the internal state.
70− mapM_ storeUsage . M.toList $ minUse
68+ -- Print some debug info.
69+ logLvl 3 $ "Reachable names:\n" ++ unlines (map show . S.toList $ reachableNames)
70+ logLvl 4 $ "Minimal usage:\n" ++ fmtUseMap minUse
71+ logLvl 5 $ "Residual deps:\n" ++ unlines (map fmtItem . M.toList $ residDeps)
7172
72− return $ S.toList reachableNames
73+ -- Store the usage info in the internal state.
74+ mapM_ storeUsage . M.toList $ minUse
75+
76+ return $ S.toList reachableNames
7377 where
78+ mainName = sNS (sUN "main") ["Main"]
79+
7480 fmtItem :: (Cond, Set Node) -> String
7581 fmtItem (cond, deps) = show (S.toList cond) ++ " -> " ++ show (S.toList deps)
7682
@@ -109,7 +115,7 @@ forwardChain deps
109115-- Build the dependency graph,
110116-- starting the depth-first search from a list of Names.
111117buildDepMap :: Ctxt ClassInfo -> Context -> Name -> Deps
112−buildDepMap ci ctx rootName = addPostulates $ dfs S.empty M.empty [rootName]
118+buildDepMap ci ctx mainName = addPostulates $ dfs S.empty M.empty [mainName]
113119 where
114120 -- mark the result of Main.main as used with the empty assumption
115121 addPostulates :: Deps -> Deps