@@ -11,6 +11,7 @@ import Idris.Core.TT
1111import Idris.Core.Evaluate
1212
1313import Debug.Trace
14+import System.IO.Unsafe
1415
1516import Control.Arrow
1617import Control.Applicative
@@ -72,8 +73,8 @@ forwardChain deps
7273
7374-- Build the dependency graph,
7475-- starting the depth-first search from a list of Names.
75−buildDepMap :: Context -> [Name] -> Deps
76−buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
76+buildDepMap :: Ctxt ClassInfo -> Context -> [Name] -> Deps
77+buildDepMap ci ctx ns = addPostulates $ dfs S.empty M.empty ns
7778 where
7879 -- mark the result of Main.main as used with the empty assumption
7980 addPostulates :: Deps -> Deps
@@ -160,6 +161,13 @@ buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
160161 etaExpand (n : ns) t = etaExpand ns (App t (P Ref n Erased))
161162
162163 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
170+ = undefined
163171 getDepsSC fn es vs ImpossibleCase = M.empty
164172 getDepsSC fn es vs (UnmatchedCase msg) = M.empty
165173 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
171179 = M.insertWith S.union (S.singleton (fn, Result)) casedVar -- add this dep to all deps
172180 $ unionMap (getDepsAlt fn es vs casedVar) alts -- coming from the whole subtree
173181 where
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
174184 casedVar = fromMaybe (error $ "nonpatvar in case: " ++ show n) (M.lookup n vs)
175185
176186 getDepsAlt :: Name -> [Name] -> Vars -> Var -> CaseAlt -> Deps
@@ -245,7 +255,13 @@ buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
245255
246256 -- TODO: figure out what to do with methods
247257 -- the following code marks them as completely used
248− Proj t i -> getDepsTerm vs bs cd t `M.union` unconditionalDeps args
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)]
261+ `ins` unconditionalDeps args
262+
263+ Proj t i
264+ -> error $ "cannot analyse projection !" ++ show i ++ " of " ++ show t
249265
250266 _ -> error $ "cannot analyse application of " ++ show fun ++ " to " ++ show args
251267 where
@@ -255,8 +271,7 @@ buildDepMap ctx ns = addPostulates $ dfs S.empty M.empty ns
255271 unconditionalDeps args = unionMap (getDepsTerm vs bs cd) args
256272
257273 -- projections (= methods)
258− getDepsTerm vs bs cd (Proj t i) | ("PROJ", t, S.toList cd) `traceShow` False = undefined
259− getDepsTerm vs bs cd (Proj t i) = getDepsTerm vs bs cd t
274+ getDepsTerm vs bs cd (Proj t i) = getDepsTerm vs bs cd t -- TODO?
260275
261276 -- the easy cases
262277 getDepsTerm vs bs cd (Constant _) = M.empty