@@ -11,6 +11,7 @@ import Idris.Core.TT
11import Idris.Core.Evaluate
11import Idris.Core.Evaluate
13import Debug.Trace
13import Debug.Trace
14+import System.IO.Unsafe
15import Control.Arrow
16import Control.Arrow
16import Control.Applicative
17import Control.Applicative
@@ -72,8 +73,8 @@ forwardChain deps
73-- Build the dependency graph,
74-- Build the dependency graph,
74-- starting the depth-first search from a list of Names.
75-- starting the depth-first search from a list of Names.
75−buildDepMap :: Context -> [Name] -> Deps
76+buildDepMap :: Ctxt ClassInfo -> Context -> [Name] -> Deps
76−buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
77+buildDepMap ci ctx ns = addPostulates $ dfs S.empty M.empty ns
78 -- mark the result of Main.main as used with the empty assumption
79 -- mark the result of Main.main as used with the empty assumption
79 addPostulates :: Deps -> Deps
80 addPostulates :: Deps -> Deps
@@ -160,6 +161,13 @@ buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
160 etaExpand (n : ns) t = etaExpand ns (App t (P Ref n Erased))
161 etaExpand (n : ns) t = etaExpand ns (App t (P Ref n Erased))
162 getDepsSC :: Name -> [Name] -> Vars -> SC -> Deps
163 getDepsSC :: Name -> [Name] -> Vars -> SC -> Deps
164+ getDepsSC fn es vs (STerm t)
165+ | show fn == "SN.I-Char instance of NS.Prelude.Classes.UN:\"Ord\""
166+ , ("ORDINST", fn, t) `traceShow` True
167+ , "===" `traceShow` True
168+ , unsafePerformIO (mapM_ print . M.toList $ getDepsTerm vs [] (S.singleton (fn, Result)) (etaExpand es t)) `traceShow` True
169+ , "===" `traceShow` False
163 getDepsSC fn es vs ImpossibleCase = M.empty
171 getDepsSC fn es vs ImpossibleCase = M.empty
164 getDepsSC fn es vs (UnmatchedCase msg) = M.empty
172 getDepsSC fn es vs (UnmatchedCase msg) = M.empty
165 getDepsSC fn es vs (ProjCase t alt) = error "ProjCase not supported"
173 getDepsSC fn es vs (ProjCase t alt) = error "ProjCase not supported"
@@ -171,6 +179,8 @@ buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
171 = M.insertWith S.union (S.singleton (fn, Result)) casedVar -- add this dep to all deps
179 = M.insertWith S.union (S.singleton (fn, Result)) casedVar -- add this dep to all deps
172 $ unionMap (getDepsAlt fn es vs casedVar) alts -- coming from the whole subtree
180 $ unionMap (getDepsAlt fn es vs casedVar) alts -- coming from the whole subtree
182+ -- TODO: use effect instead of casedVar to mark the ctor tag
183+ -- effect = S.insert (typeName, Result) casedVar -- mark the tag of the type name as used
174 casedVar = fromMaybe (error $ "nonpatvar in case: " ++ show n) (M.lookup n vs)
184 casedVar = fromMaybe (error $ "nonpatvar in case: " ++ show n) (M.lookup n vs)
176 getDepsAlt :: Name -> [Name] -> Vars -> Var -> CaseAlt -> Deps
186 getDepsAlt :: Name -> [Name] -> Vars -> Var -> CaseAlt -> Deps
@@ -245,7 +255,13 @@ buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
246 -- TODO: figure out what to do with methods
256 -- TODO: figure out what to do with methods
247 -- the following code marks them as completely used
257 -- the following code marks them as completely used
258+ Proj (P Ref n@(SN (InstanceN className parms)) _) i
259+ | [CI ctorName ms ds dscs ps is] <- lookupCtxt className ci
260+ -> S.fromList [(ctorName, Arg i), (n, Result)]
248− Proj t i -> getDepsTerm vs bs cd t `M.union` unconditionalDeps args
261+ `ins` unconditionalDeps args
264+ -> error $ "cannot analyse projection !" ++ show i ++ " of " ++ show t
250 _ -> error $ "cannot analyse application of " ++ show fun ++ " to " ++ show args
266 _ -> error $ "cannot analyse application of " ++ show fun ++ " to " ++ show args
@@ -255,8 +271,7 @@ buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
255 unconditionalDeps args = unionMap (getDepsTerm vs bs cd) args
271 unconditionalDeps args = unionMap (getDepsTerm vs bs cd) args
257 -- projections (= methods)
273 -- projections (= methods)
258− getDepsTerm vs bs cd (Proj t i) | ("PROJ", t, S.toList cd) `traceShow` False = undefined
274+ getDepsTerm vs bs cd (Proj t i) = getDepsTerm vs bs cd t -- TODO?
259− getDepsTerm vs bs cd (Proj t i) = getDepsTerm vs bs cd t
261 -- the easy cases
276 -- the easy cases
262 getDepsTerm vs bs cd (Constant _) = M.empty
277 getDepsTerm vs bs cd (Constant _) = M.empty