on master help sign in
Cached deps added.
commit06e0bb927ec9f3782cc9fdeb2060b7fa55a64498 authorMatus Tejiscak <ziman@functor.sk> dateThu 23 Jan 2014, 16:22 (13 years ago) parent0a71ea2
2 files changed+27−4
src/IRTS/Compiler.hs+3−1 src/Idris/Erasure.hs+24−3
src/IRTS/Compiler.hs+3−1
@@ -47,12 +47,14 @@ compile codegen f tm
4747 defsIn <- mkDecls tm used
4848 findUnusedArgs used
4949
50+ -- TODO: traverse all names correctly
51+
5052 -- TODO: DEBUG-ONLY, remove
5153 ist <- getIState
5254 let usedF = findUsed (tt_ctxt ist) (idris_callgraph ist) used
5355 let printCond (ctors, cond) = "if " ++ show (S.toList cond) ++ " -ctors- " ++ show (S.toList ctors)
5456 let printDep (i, conds) = unlines . map (" "++) $ (show i : map printCond (S.toList conds))
55− let printItem (fn, deps) = unlines (show fn : map printDep (IM.toList deps))
57+ let printItem (fn, (deps, depns)) = unlines ((show fn ++ " <- " ++ show (S.toList depns)) : map printDep (IM.toList deps))
5658 iLOG $ "USAGE ANALYSIS:\n" ++ unlines (map printItem . M.toList $ usedF)
5759 -- END TODO
5860
src/Idris/Erasure.hs+24−3
@@ -28,8 +28,13 @@ import Data.IntMap (IntMap)
2828-- UseMap maps names to the set of used (reachable) argument positions.
2929type UseMap = Map Name IntSet
3030
31−-- DepMap maps functions (only functions) to their Deps.
32−type DepMap = Map Name Deps
31+-- Deps augmented with cached info.
32+-- fst = deps
33+-- snd = all names that the function depends on
34+type Deps' = (Deps, Set Name)
35+
36+-- DepMap maps functions (only functions) to their Deps'.
37+type DepMap = Map Name Deps'
3338
3439-- Deps of a function is a map from argument index
3540-- to all usages of the argument, including conditions
@@ -54,8 +59,24 @@ type PatVar = Ctors -> Var
5459type PatVars = Map Name PatVar
5560
5661findUsed :: Context -> Ctxt CGInfo -> [Name] -> DepMap
57−findUsed ctx cg ns = M.fromList [(n, getDeps n) | n <- ns]
62+findUsed ctx cg ns = dfs M.empty ns
5863 where
64+ dfs :: DepMap -> [Name] -> DepMap
65+ dfs dmap [] = dmap
66+ dfs dmap (n : ns)
67+ | n `M.member` dmap = dfs dmap ns
68+ | otherwise = dfs (M.insert n (deps, depn) dmap) ns
69+ where
70+ next = [n | n <- S.toList depn, n `M.notMember` dmap]
71+ depn = depNames deps
72+ deps = getDeps n
73+
74+ depNames :: Deps -> Set Name
75+ depNames = S.unions . map (S.unions . map f . S.toList) . IM.elems
76+ where
77+ f :: (Ctors, Cond) -> Set Name
78+ f (ctors, cond) = S.map fst cond -- let's ignore ctors for now
79+
5980 getDeps :: Name -> Deps
6081 getDeps n = case lookupDef n ctx of
6182 [def] -> getDepsDef def