@@ -4,7 +4,6 @@ module Idris.Erasure
4 ( findUnusedArgs
4 ( findUnusedArgs
5 , buildDepMap
5 , buildDepMap
6 , minimalUsage
6 , minimalUsage
10import Idris.AbsSyntax
9import Idris.AbsSyntax
@@ -50,21 +49,6 @@ type Cond = Set Node
50type Var = Set Node
49type Var = Set Node
51type Vars = Map Name Var
50type Vars = Map Name Var
53−-- Change the map of used args to a map of unused args.
54−usedToUnused :: Context -> UseMap -> UseMap
55−usedToUnused ctx = M.mapWithKey invert
57− invert :: Name -> IntSet -> IntSet
58− invert n used = IS.fromList [0 .. arity n - 1] IS.\\ used
61− arity n = case lookupDef n ctx of
62− [TyDecl (DCon tag n) t] -> n
63− [CaseOp ci ty tys def tot cdefs] -> length tys
64− [def] -> error $ "unsupported definition of " ++ show n ++ ": " ++ show def
65− [] -> error $ "unknown name in conversion to unused: " ++ show n
66− _ -> error $ "ambiguous name in conversion to unused: " ++ show n
68-- Find the minimal consistent usage by forward chaining.
52-- Find the minimal consistent usage by forward chaining.
69minimalUsage :: Deps -> UseMap
53minimalUsage :: Deps -> UseMap
70minimalUsage = gather . forwardChain
54minimalUsage = gather . forwardChain
@@ -262,14 +246,14 @@ findUnusedArgs names = do
262 process :: Ctxt CGInfo -> Name -> Idris ()
246 process :: Ctxt CGInfo -> Name -> Idris ()
263 process cg n = case lookupCtxt n cg of
247 process cg n = case lookupCtxt n cg of
264 [x] -> do
248 [x] -> do
265− let unused = traceUnused cg n x
249+ let used = traceUsed cg n x
266− logLvl 1 $ show n ++ " unused: " ++ show unused
250+ logLvl 1 $ show n ++ " used: " ++ show used
267− addToCG n $ x{ unusedpos = unused }
251+ addToCG n $ x{ usedpos = used }
268 _ -> return ()
252 _ -> return ()
270− traceUnused :: Ctxt CGInfo -> Name -> CGInfo -> [Int]
254+ traceUsed :: Ctxt CGInfo -> Name -> CGInfo -> [Int]
271− traceUnused cg n (CGInfo args calls _ usedns _)
255+ traceUsed cg n (CGInfo args calls _ usedns _)
272− = findIndices (not . (`elem` fused)) args
256+ = findIndices (`elem` fused) args
274 fargs = concatMap (getFargpos calls) (zip args [0..])
258 fargs = concatMap (getFargpos calls) (zip args [0..])
275 recused = [n | (n, i, (g,j)) <- fargs, used cg [(n,i)] g j]
259 recused = [n | (n, i, (g,j)) <- fargs, used cg [(n,i)] g j]