on cbc8a13 help sign in
Idris-dev/src/Idris/Coverage.hs
610 lines 26 kB history raw
1{-# LANGUAGE PatternGuards #-}
3module Idris.Coverage where
5import Core.TT
6import Core.Evaluate
7import Core.CaseTree
9import Idris.AbsSyntax
10import Idris.Delaborate
11import Idris.Error
13import Data.List
14import Data.Either
15import Data.Maybe
16import Debug.Trace
18import Control.Monad.State
20-- Generate the LHSes which are missing from a case tree
21-- Eliminate the ones which cannot be well typed
23genMissing :: Name -> [Name] -> SC -> Idris [PTerm]
24genMissing fn args sc
25 = do sc' <- expandTree sc
26 logLvl 5 $ "Checking missing cases for " ++
27 show fn ++ "\n" ++ (show sc')
28 (got, missing) <- gm fn (map (\x -> P Bound x Erased) args) sc'
29 return $ filter (\x -> not (x `elem` got)) missing
31-- Make a term to feed to the pattern matcher from a LHS declared impossible
32-- (we can't type check it, but we need the case analysis to check for
33-- covering...)
35mkPatTm :: PTerm -> Idris Term
36mkPatTm t = do i <- get
37 let timp = addImpl' True [] [] i t
38 evalStateT (toTT timp) 0
39 where
40 toTT (PRef _ n) = do i <- lift $ get
41 case lookupDef Nothing n (tt_ctxt i) of
42 [TyDecl nt _] -> return $ P nt n Erased
43 _ -> return $ P Ref n Erased
44 toTT (PApp _ t args) = do t' <- toTT t
45 args' <- mapM (toTT . getTm) args
46 return $ mkApp t' args'
47 toTT _ = do v <- get
48 put (v + 1)
49 return (P Bound (MN v "imp") Erased)
51mkPTerm :: Name -> [TT Name] -> Idris PTerm
52mkPTerm f args = do i <- get
53 let fapp = mkApp (P Bound f Erased) (map eraseName args)
54 return $ delab i fapp
55 where eraseName (App f a) = App (eraseName f) (eraseName a)
56 eraseName (P _ (MN _ _) _) = Erased
57 eraseName t = t
59gm :: Name -> [TT Name] -> SC -> Idris ([PTerm], [PTerm])
60gm fn args (Case n alts) = do m <- mapM (gmAlt fn args n) alts
61 let (got, missing) = unzip m
62 return (concat got, concat missing)
63gm fn args (STerm tm) = do logLvl 3 ("Covered: " ++ show args)
64 t <- mkPTerm fn args
65 return ([t], [])
66gm fn args ImpossibleCase = do logLvl 3 ("Impossible: " ++ show args)
67 t <- mkPTerm fn args
68 return ([], [])
69gm fn args (UnmatchedCase _) = do logLvl 3 ("Missing: " ++ show args)
70 t <- mkPTerm fn args
71 return ([], [t])
73gmAlt fn args n (ConCase cn t cargs sc)
74 = do let args' = map (subst n (mkApp (P Bound cn Erased)
75 (map (\x -> P Bound x Erased) cargs)))
76 args
77 gm fn args' sc
78gmAlt fn args n (ConstCase c sc)
79 = do let args' = map (subst n (Constant c)) args
80 gm fn args' sc
81gmAlt fn args n (DefaultCase sc)
82 = do gm fn args sc
84getDefault (DefaultCase sc : _) = sc
85getDefault (_ : cs) = getDefault cs
86getDefault [] = UnmatchedCase ""
88dropDefault (DefaultCase sc : rest) = dropDefault rest
89dropDefault (c : cs) = c : dropDefault cs
90dropDefault [] = []
92expandTree :: SC -> Idris SC
93expandTree (Case n alts) = do i <- get
94 as <- expandAlts i (dropDefault alts)
95 (getDefault alts)
96 alts' <- mapM expandTreeA as
97 return (Case n alts')
98 where expandTreeA (ConCase n i ns sc) = do sc' <- expandTree sc
99 return (ConCase n i ns sc')
100 expandTreeA (ConstCase i sc) = do sc' <- expandTree sc
101 return (ConstCase i sc')
102 expandTreeA (DefaultCase sc) = do sc' <- expandTree sc
103 return (DefaultCase sc')
104expandTree t = return t
106expandAlts :: IState -> [CaseAlt] -> SC -> Idris [CaseAlt]
107expandAlts i all@(ConstCase c _ : alts) def
108 = return $ all ++ [DefaultCase def]
109expandAlts i all@(ConCase n _ _ _ : alts) def
110 | (TyDecl c@(DCon _ arity) ty : _) <- lookupDef Nothing n (tt_ctxt i)
111 = do let tyn = getTy n (tt_ctxt i)
112 case lookupCtxt Nothing tyn (idris_datatypes i) of
113 (TI ns _ : _) -> do let ps = map mkPat ns
114 return $ addAlts ps (altsFor all) all
115 _ -> return all
116 where
117 altsFor [] = []
118 altsFor (ConCase n _ _ _ : alts) = n : altsFor alts
119 altsFor (_ : alts) = altsFor alts
121 addAlts [] got alts = alts
122 addAlts ((n, arity) : ps) got alts
123 | n `elem` got = addAlts ps got alts
124 | otherwise = addAlts ps got (alts ++
125 [ConCase n (-1) (argList arity) def])
127 argList i = take i (map (\x -> (MN x "ign")) [0..])
129 getTy n ctxt
130 = case lookupTy Nothing n ctxt of
131 (t : _) -> case unApply (getRetTy t) of
132 (P _ tyn _, _) -> tyn
133 x -> error $ "Can't happen getTy 1 " ++ show (n, x)
134 _ -> error "Can't happen getTy 2"
136 mkPat x = case lookupCtxt Nothing x (idris_implicits i) of
137 (pargs : _)
138 -> (x, length pargs)
139 _ -> error "Can't happen - genAll"
140expandAlts i alts def = return alts
144-- OLD STUFF: probably broken...
146-- Given a list of LHSs, generate a extra clauses which cover the remaining
147-- cases. The ones which haven't been provided are marked 'absurd' so that the
148-- checker will make sure they can't happen.
150-- This will only work after the given clauses have been typechecked and the
151-- names are fully explicit!
153genClauses :: FC -> Name -> [Term] -> [PClause] -> Idris [PTerm]
154genClauses fc n xs given
155 = do i <- getIState
156 let lhss = map (getLHS i) xs
157 let argss = transpose lhss
158 let all_args = map (genAll i) argss
159 logLvl 7 $ "COVERAGE of " ++ show n
160 logLvl 10 $ show argss ++ "\n" ++ show all_args
161 logLvl 10 $ "Original: \n" ++
162 showSep "\n" (map (\t -> showImp True (delab' i t True)) xs)
163 let parg = case lookupCtxt Nothing n (idris_implicits i) of
164 (p : _) -> p
165 _ -> repeat (pexp Placeholder)
166 let tryclauses = mkClauses parg all_args
167 let new = mnub i $ filter (noMatch i) tryclauses
168 logLvl 7 $ "New clauses: \n" ++ showSep "\n" (map (showImp True) new)
169-- ++ " from:\n" ++ showSep "\n" (map (showImp True) tryclauses)
170 return new
171-- return (map (\t -> PClause n t [] PImpossible []) new)
172 where getLHS i term
173 | (f, args) <- unApply term = map (\t -> delab' i t True) args
174 | otherwise = []
176 lhsApp (PClause _ _ l _ _ _) = l
177 lhsApp (PWith _ _ l _ _ _) = l
179 mnub i [] = []
180 mnub i (x : xs) =
181 if (any (\t -> case matchClause i x t of
182 Right _ -> True
183 Left _ -> False) xs) then mnub i xs
184 else x : mnub i xs
186 noMatch i tm = all (\x -> case matchClause i (delab' i x True) tm of
187 Right _ -> False
188 Left miss -> True) xs
191 mkClauses :: [PArg] -> [[PTerm]] -> [PTerm]
192 mkClauses parg args
193 | all (== [Placeholder]) args = []
194 mkClauses parg args
195 = do args' <- mkArg args
196 let tm = PApp fc (PRef fc n) (zipWith upd args' parg)
197 return tm
198 where
199 mkArg :: [[PTerm]] -> [[PTerm]]
200 mkArg [] = return []
201 mkArg (a : as) = do a' <- a
202 as' <- mkArg as
203 return (a':as')
205-- FIXME: Just look for which one is the deepest, then generate all
206-- possibilities up to that depth.
208genAll :: IState -> [PTerm] -> [PTerm]
209genAll i args = case filter (/=Placeholder) $ concatMap otherPats (nub args) of
210 [] -> [Placeholder]
211 xs -> xs
212 where
213 conForm (PApp _ (PRef fc n) _) = isConName Nothing n (tt_ctxt i)
214 conForm (PRef fc n) = isConName Nothing n (tt_ctxt i)
215 conForm _ = False
217 otherPats :: PTerm -> [PTerm]
218 otherPats o@(PRef fc n) = ops fc n [] o
219 otherPats o@(PApp _ (PRef fc n) xs) = ops fc n xs o
220 otherPats arg = return Placeholder
222 ops fc n xs o
223 | (TyDecl c@(DCon _ arity) ty : _) <- lookupDef Nothing n (tt_ctxt i)
224 = do xs' <- mapM otherPats (map getTm xs)
225 let p = PApp fc (PRef fc n) (zipWith upd xs' xs)
226 let tyn = getTy n (tt_ctxt i)
227 case lookupCtxt Nothing tyn (idris_datatypes i) of
228 (TI ns _ : _) -> p : map (mkPat fc) (ns \\ [n])
229 _ -> [p]
230 ops fc n arg o = return Placeholder
232 getTy n ctxt = case lookupTy Nothing n ctxt of
233 (t : _) -> case unApply (getRetTy t) of
234 (P _ tyn _, _) -> tyn
235 x -> error $ "Can't happen getTy 1 " ++ show (n, x)
236 _ -> error "Can't happen getTy 2"
238 mkPat fc x = case lookupCtxt Nothing x (idris_implicits i) of
239 (pargs : _)
240 -> PApp fc (PRef fc x) (map (upd Placeholder) pargs)
241 _ -> error "Can't happen - genAll"
243upd p' p = p { getTm = p' }
245-- Check if, in a given type n, the constructor cn : ty is strictly positive,
246-- and update the context accordingly
248checkPositive :: Name -> (Name, Type) -> Idris ()
249checkPositive n (cn, ty)
250 = do let p = cp ty
251 i <- getIState
252 let tot = if p then Total (args ty) else Partial NotPositive
253 let ctxt' = setTotal cn tot (tt_ctxt i)
254 putIState (i { tt_ctxt = ctxt' })
255 logLvl 5 $ "Constructor " ++ show cn ++ " is " ++ show tot
256 addIBC (IBCTotal cn tot)
257 where
258 args t = [0..length (getArgTys t)-1]
260 cp (Bind n (Pi aty) sc) = posArg aty && cp sc
261 cp t = True
263 posArg (Bind _ (Pi nty) sc)
264 | (P _ n' _, args) <- unApply nty
265 = n /= n' && posArg sc
266 posArg t = True
268-- Totality checking - check for structural recursion
269-- (no mutual definitions yet)
271data LexOrder = LexXX | LexEQ | LexLT
272 deriving (Show, Eq, Ord)
274calcProd :: IState -> FC -> Name -> [([Name], Term, Term)] -> Idris Totality
275calcProd i fc n pats = do patsprod <- mapM prodRec pats
276 if (and patsprod)
277 then return Productive
278 else return (Partial NotProductive)
279 where
280 -- every application of n must be in an argument of a coinductive
281 -- constructor
283 prodRec :: ([Name], Term, Term) -> Idris Bool
284 prodRec (_, _, tm) = prod False tm
286 prod ok ap@(App _ _)
287 | (P _ (UN "lazy") _, [_, arg]) <- unApply ap = prod ok arg
288 | (P _ f ty, args) <- unApply ap
289 = let co = cotype ty in
290 if f == n
291 then do argsprod <- mapM (prod co) args
292 return (and (ok : argsprod) )
293 else do argsprod <- mapM (prod co) args
294 return (and argsprod)
295 prod ok (App f a) = liftM2 (&&) (prod False f) (prod False a)
296 prod ok (Bind _ (Let t v) sc) = liftM2 (&&) (prod False v) (prod False v)
297 prod ok (Bind _ b sc) = prod ok sc
298 prod ok t = return True
300 cotype ty
301 | (P _ t _, _) <- unApply (getRetTy ty)
302 = case lookupCtxt Nothing t (idris_datatypes i) of
303 [TI _ True] -> True
304 _ -> False
305 | otherwise = False
307calcTotality :: [Name] -> FC -> Name -> [([Name], Term, Term)]
308 -> Idris Totality
309calcTotality path fc n pats
310 = do i <- get
311 let opts = case lookupCtxt Nothing n (idris_flags i) of
312 [fs] -> fs
313 _ -> []
314 case mapMaybe (checkLHS i) (map (\ (_, l, r) -> l) pats) of
315 (failure : _) -> return failure
316 _ -> if (Coinductive `elem` opts)
317 then calcProd i fc n pats
318 else checkSizeChange n
319 where
320 checkLHS i (P _ fn _)
321 = case lookupTotal fn (tt_ctxt i) of
322 [Partial _] -> return (Partial (Other [fn]))
323 _ -> Nothing
324 checkLHS i (App f a) = mplus (checkLHS i f) (checkLHS i a)
325 checkLHS _ _ = Nothing
327checkTotality :: [Name] -> FC -> Name -> Idris Totality
328checkTotality path fc n
329 | n `elem` path = return (Partial (Mutual (n : path)))
330 | otherwise = do
331 t <- getTotality n
332 updateContext (simplifyCasedef n)
333 ctxt <- getContext
334 i <- getIState
335 let opts = case lookupCtxt Nothing n (idris_flags i) of
336 [fs] -> fs
337 _ -> []
338 t' <- case t of
339 Unchecked ->
340 case lookupDef Nothing n ctxt of
341 [CaseOp _ _ _ _ pats _ _ _ _] ->
342 do t' <- if AssertTotal `elem` opts
343 then return $ Total []
344 else calcTotality path fc n pats
345 setTotality n t'
346 addIBC (IBCTotal n t')
347 -- if it's not total, it can't reduce, to keep
348 -- typechecking decidable
349 case t' of
350-- FIXME: Put this back when we can handle mutually recursive things
351-- p@(Partial _) ->
352-- do setAccessibility n Frozen
353-- addIBC (IBCAccess n Frozen)
354-- logLvl 5 $ "HIDDEN: "
355-- ++ show n ++ show p
356 _ -> return ()
357 return t'
358 _ -> return $ Total []
359 x -> return x
360 case t' of
361 Total _ -> return t'
362 Productive -> return t'
363 e -> do w <- cmdOptType WarnPartial
364 if TotalFn `elem` opts
365 then totalityError t'
366 else do when (w && not (PartialFn `elem` opts)) $
367 warnPartial n t'
368 return t'
369 where
370 totalityError t = tclift $ tfail (At fc (Msg (show n ++ " is " ++ show t)))
372 warnPartial n t
373 = do i <- get
374 case lookupDef Nothing n (tt_ctxt i) of
375 [x] -> do
376 iputStrLn $ show fc ++ ":Warning - " ++ show n ++ " is " ++ show t
377-- ++ "\n" ++ show x
378-- let cg = lookupCtxtName Nothing n (idris_callgraph i)
379-- iputStrLn (show cg)
382checkDeclTotality :: (FC, Name) -> Idris Totality
383checkDeclTotality (fc, n)
384 = do logLvl 2 $ "Checking " ++ show n ++ " for totality"
385-- buildSCG (fc, n)
386-- logLvl 2 $ "Built SCG"
387 checkTotality [] fc n
389-- Calculate the size change graph for this definition
391-- SCG for a function f consists of a list of:
392-- (g, [(a1, sizechange1), (a2, sizechange2), ..., (an, sizechangen)])
394-- where g is a function called
395-- a1 ... an are the arguments of f in positions 1..n of g
396-- sizechange1 ... sizechange2 is how their size has changed wrt the input
397-- to f
398-- Nothing, if the argument is unrelated to the input
400buildSCG :: (FC, Name) -> Idris ()
401buildSCG (_, n) = do
402 ist <- get
403 case lookupCtxt Nothing n (idris_callgraph ist) of
404 [cg] -> case lookupDef Nothing n (tt_ctxt ist) of
405 [CaseOp _ _ _ _ _ args sc _ _] ->
406 do logLvl 5 $ "Building SCG for " ++ show n ++ " from\n"
407 ++ show sc
408 let newscg = buildSCG' ist sc args
409 logLvl 5 $ show newscg
410 addToCG n ( cg { scg = newscg } )
411 [] -> logLvl 5 $ "Could not build SCG for " ++ show n ++ "\n"
412 x -> error $ "buildSCG: " ++ show (n, x)
414buildSCG' :: IState -> SC -> [Name] -> [SCGEntry]
415buildSCG' ist sc args = -- trace ("Building SCG for " ++ show sc) $
416 nub $ scg sc (zip args args)
417 (zip args (zip args (repeat Same)))
418 where
419 scg :: SC -> [(Name, Name)] -> -- local var, originating top level var
420 [(Name, (Name, SizeChange))] -> -- orig to new, and relationship
421 [SCGEntry]
422 scg (Case x alts) vars szs
423 = let x' = findTL x vars in
424 concatMap (scgAlt x' vars szs) alts
425 where
426 findTL x vars
427 | Just x' <- lookup x vars
428 = if x' `elem` args then x'
429 else findTL x' vars
430 | otherwise = x
432 scg (STerm tm) vars szs = scgTerm tm vars szs
433 scg _ _ _ = []
435 -- how the arguments relate - either Smaller or Unknown
436 argRels :: Name -> [(Name, SizeChange)]
437 argRels n = let ctxt = tt_ctxt ist
438 [ty] = lookupTy Nothing n ctxt -- must exist!
439 P _ nty _ = fst (unApply (getRetTy ty))
440 args = map snd (getArgTys ty) in
441 map (getRel nty) (map (fst . unApply . getRetTy) args)
442 where
443 getRel ty (P _ n' _) | n' == ty = (n, Smaller)
444 getRel ty t = (n, Unknown)
446 scgAlt x vars szs (ConCase n _ args sc)
447 -- all args smaller than top variable of x in sc
448 -- (as long as they are in the same type family)
449 | Just tvar <- lookup x vars
450 = let arel = argRels n
451 szs' = zipWith (\arg (_,t) -> (arg, (x, t))) args arel
452 ++ szs
453 vars' = nub (zip args (repeat tvar) ++ vars) in
454 scg sc vars' szs'
455 | otherwise = scg sc vars szs
456 scgAlt x vars szs (ConstCase _ sc) = scg sc vars szs
457 scgAlt x vars szs (DefaultCase sc) = scg sc vars szs
459 scgTerm f@(App _ _) vars szs
460 | (P _ (UN "lazy") _, [_, arg]) <- unApply f
461 = scgTerm arg vars szs
462 | (P _ fn _, args) <- unApply f
463 = let rest = concatMap (\x -> scgTerm x vars szs) args in
464 case lookup fn vars of
465 Just _ -> rest
466 Nothing -> nub $ (fn, map (mkChange szs) args) : rest
467 scgTerm (App f a) vars szs
468 = scgTerm f vars szs ++ scgTerm a vars szs
469 scgTerm (Bind n (Let t v) e) vars szs
470 = scgTerm v vars szs ++ scgTerm e vars szs
471 scgTerm (Bind n _ e) vars szs
472 = scgTerm e (nub ((n, n) : vars)) szs
473 scgTerm (P _ fn _) vars szs
474 = case lookup fn vars of
475 Just _ -> []
476 Nothing -> [(fn, [])]
477 scgTerm _ _ _ = []
479 mkChange :: [(Name, (Name, SizeChange))] -> Term
480 -> Maybe (Int, SizeChange)
481 mkChange szs tm
482 | (P _ (UN "lazy") _, [_, arg]) <- unApply tm = mkChange szs arg
483 | (P _ n ty, _) <- unApply tm -- get higher order args too
484 = do sc <- lookup n szs
485 case sc of
486 (_, Unknown) -> Nothing
487 (o, sc) -> do i <- getArgPos 0 o args
488 return (i, sc)
489 mkChange _ _ = Nothing
491 getArgPos :: Int -> Name -> [Name] -> Maybe Int
492 getArgPos i n [] = Nothing
493 getArgPos i n (x : xs) | n == x = Just i
494 | otherwise = getArgPos (i + 1) n xs
496checkSizeChange :: Name -> Idris Totality
497checkSizeChange n = do
498 ist <- get
499 case lookupCtxt Nothing n (idris_callgraph ist) of
500 [cg] -> do let ms = mkMultiPaths ist [] (scg cg)
501 logLvl 6 ("Multipath for " ++ show n ++ ":\n" ++
502 "from " ++ show (scg cg) ++ "\n" ++
503 showSep "\n" (map show ms))
504 logLvl 6 (show cg)
505 -- every multipath must have an infinitely descending
506 -- thread, then the function terminates
507 -- also need to checks functions called are all total
508 -- (Unchecked is okay as we'll spot problems here)
509 let tot = map (checkMP ist (length (argsdef cg))) ms
510 logLvl 3 $ "Paths for " ++ show n ++ " yield " ++ (show tot)
511 return (noPartial tot)
512 [] -> do logLvl 5 $ "No paths for " ++ show n
513 return Unchecked
515type MultiPath = [SCGEntry]
517mkMultiPaths :: IState -> MultiPath -> [SCGEntry] -> [MultiPath]
518mkMultiPaths ist path [] = [reverse path]
519mkMultiPaths ist path cg
520 = concat (map extend cg)
521 where extend (nextf, args)
522 | (nextf, args) `elem` path = [ reverse ((nextf, args) : path) ]
523 | otherwise
524 = case lookupCtxt Nothing nextf (idris_callgraph ist) of
525 [ncg] -> mkMultiPaths ist ((nextf, args) : path) (scg ncg)
526 _ -> [ reverse ((nextf, args) : path) ]
528-- do (nextf, args) <- cg
529-- if ((nextf, args) `elem` path)
530-- then return (reverse ((nextf, args) : path))
531-- else case lookupCtxt Nothing nextf (idris_callgraph ist) of
532-- [ncg] -> mkMultiPaths ist ((nextf, args) : path) (scg ncg)
533-- _ -> return (reverse ((nextf, args) : path))
535-- If any route along the multipath leads to infinite descent, we're fine.
536-- Try a route beginning with every argument.
537-- If we reach a point we've been to before, but with a smaller value,
538-- that means there is an infinitely descending path from that argument.
540checkMP :: IState -> Int -> MultiPath -> Totality
541checkMP ist i mp = if i > 0
542 then collapse (map (tryPath 0 [] mp) [0..i-1])
543 else tryPath 0 [] mp 0
544 where
545 tryPath' d path mp arg
546 = let res = tryPath d path mp arg in
547 trace (show mp ++ "\n" ++ show arg ++ " " ++ show res) res
549 tryPath :: Int -> [(SCGEntry, Int)] -> MultiPath -> Int -> Totality
550 tryPath desc path [] _ = Total []
551-- tryPath desc path ((UN "believe_me", _) : _) arg
552-- = Partial BelieveMe
553 -- if we get to a constructor, it's fine as long as it's strictly positive
554 tryPath desc path ((f, _) :es) arg
555 | [TyDecl (DCon _ _) _] <- lookupDef Nothing f (tt_ctxt ist)
556 = case lookupTotal f (tt_ctxt ist) of
557 [Total _] -> Unchecked -- okay so far
558 [Partial _] -> Partial (Other [f])
559 x -> error (show x)
560 | [TyDecl (TCon _ _) _] <- lookupDef Nothing f (tt_ctxt ist)
561 = Total []
562 tryPath desc path (e@(f, []) : es) arg
563 | e `elem` es = Partial (Mutual [f])
564 tryPath desc path (e@(f, nextargs) : es) arg
565 | Just d <- lookup e path
566 = if desc > 0
567 then -- trace ("Descent " ++ show (desc - d) ++ " "
568 -- ++ show (path, e)) $
569 Total []
570 else Partial (Mutual (map (fst . fst) path ++ [f]))
571 | [Unchecked] <- lookupTotal f (tt_ctxt ist) =
572 let argspos = zip nextargs [0..] in
573 collapse' Unchecked $
574 do (a, pos) <- argspos
575 case a of
576 Nothing -> -- don't know, but if the
577 -- rest definitely terminates without
578 -- any cycles with route so far,
579 -- then we might yet be total
580 case collapse (map (tryPath (-10000) ((e, desc):path) es)
581 [0..length nextargs - 1]) of
582 Total _ -> return Unchecked
583 x -> return x
584 Just (nextarg, sc) ->
585 if nextarg == arg then
586 case sc of
587 Same -> return $ tryPath desc ((e, desc) : path)
588 es pos
589 Smaller -> return $ tryPath (desc+1)
590 ((e, desc):path)
591 es
592 pos
593 _ -> trace ("Shouldn't happen " ++ show e) $
594 return (Partial Itself)
595 else return Unchecked
596 | [Total _] <- lookupTotal f (tt_ctxt ist) = Unchecked
597 | [Partial _] <- lookupTotal f (tt_ctxt ist) = Partial (Other [f])
598 | otherwise = Unchecked
600noPartial (Partial p : xs) = Partial p
601noPartial (_ : xs) = noPartial xs
602noPartial [] = Total []
604collapse xs = collapse' Unchecked xs
605collapse' def (Total r : xs) = Total r
606collapse' def (Unchecked : xs) = collapse' def xs
607collapse' def (d : xs) = collapse' d xs
608-- collapse' Unchecked [] = Total []
609collapse' def [] = def