@@ -4,7 +4,6 @@ module Idris.Erasure
44 ( findUnusedArgs
55 , buildDepMap
66 , minimalUsage
7− , usedToUnused
87 ) where
98
109import Idris.AbsSyntax
@@ -50,21 +49,6 @@ type Cond = Set Node
5049type Var = Set Node
5150type Vars = Map Name Var
5251
53−-- Change the map of used args to a map of unused args.
54−usedToUnused :: Context -> UseMap -> UseMap
55−usedToUnused ctx = M.mapWithKey invert
56− where
57− invert :: Name -> IntSet -> IntSet
58− invert n used = IS.fromList [0 .. arity n - 1] IS.\\ used
59−
60− arity :: Name -> Int
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
67−
6852-- Find the minimal consistent usage by forward chaining.
6953minimalUsage :: Deps -> UseMap
7054minimalUsage = gather . forwardChain
@@ -262,14 +246,14 @@ findUnusedArgs names = do
262246 process :: Ctxt CGInfo -> Name -> Idris ()
263247 process cg n = case lookupCtxt n cg of
264248 [x] -> do
265− let unused = traceUnused cg n x
266− logLvl 1 $ show n ++ " unused: " ++ show unused
267− addToCG n $ x{ unusedpos = unused }
249+ let used = traceUsed cg n x
250+ logLvl 1 $ show n ++ " used: " ++ show used
251+ addToCG n $ x{ usedpos = used }
268252 _ -> return ()
269253
270− traceUnused :: Ctxt CGInfo -> Name -> CGInfo -> [Int]
271− traceUnused cg n (CGInfo args calls _ usedns _)
272− = findIndices (not . (`elem` fused)) args
254+ traceUsed :: Ctxt CGInfo -> Name -> CGInfo -> [Int]
255+ traceUsed cg n (CGInfo args calls _ usedns _)
256+ = findIndices (`elem` fused) args
273257 where
274258 fargs = concatMap (getFargpos calls) (zip args [0..])
275259 recused = [n | (n, i, (g,j)) <- fargs, used cg [(n,i)] g j]