1{-# LANGUAGE PatternGuards #-}
3module Idris.Coverage where
6import Idris.Core.Evaluate
7import Idris.Core.CaseTree
10import Idris.Delaborate
18import Control.Monad.State
20mkPatTm :: PTerm -> Idris Term
21mkPatTm t = do i <- getIState
22 let timp = addImpl' True [] [] i t
23 evalStateT (toTT timp) 0
25 toTT (PRef _ n) = do i <- lift getIState
26 case lookupDef n (tt_ctxt i) of
27 [TyDecl nt _] -> return $ P nt n Erased
28 _ -> return $ P Ref n Erased
29 toTT (PApp _ t args) = do t' <- toTT t
30 args' <- mapM (toTT . getTm) args
31 return $ mkApp t' args'
34 return (P Bound (MN v "imp") Erased)
36-- Given a list of LHSs, generate a extra clauses which cover the remaining
37-- cases. The ones which haven't been provided are marked 'absurd' so that the
38-- checker will make sure they can't happen.
40-- This will only work after the given clauses have been typechecked and the
41-- names are fully explicit!
43genClauses :: FC -> Name -> [Term] -> [PClause] -> Idris [PTerm]
44genClauses fc n xs given
46 let lhss = map (getLHS i) xs
47 let argss = transpose lhss
48 let all_args = map (genAll i) argss
49 logLvl 5 $ "COVERAGE of " ++ show n
50 logLvl 5 $ show (map length argss) ++ "\n" ++ show (map length all_args)
51 logLvl 10 $ show argss ++ "\n" ++ show all_args
52 logLvl 10 $ "Original: \n" ++
53 showSep "\n" (map (\t -> showImp Nothing True False (delab' i t True True)) xs)
54 -- add an infinite supply of explicit arguments to update the possible
55 -- cases for (the return type may be variadic, or function type, sp
56 -- there may be more case splitting that the idris_implicits record
58 let parg = case lookupCtxt n (idris_implicits i) of
59 (p : _) -> p ++ repeat (PExp 0 False Placeholder "")
60 _ -> repeat (pexp Placeholder)
61 let tryclauses = mkClauses parg all_args
62 logLvl 2 $ show (length tryclauses) ++ " initially to check"
63 logLvl 5 $ showSep "\n" (map (showImp Nothing True False) tryclauses)
64 let new = filter (noMatch i) (nub tryclauses)
65 logLvl 1 $ show (length new) ++ " clauses to check for impossibility"
66 logLvl 5 $ "New clauses: \n" ++ showSep "\n" (map (showImp Nothing True False) new)
67-- ++ " from:\n" ++ showSep "\n" (map (showImp True) tryclauses)
69-- return (map (\t -> PClause n t [] PImpossible []) new)
71 | (f, args) <- unApply term = map (\t -> delab' i t True True) args
74 lhsApp (PClause _ _ l _ _ _) = l
75 lhsApp (PWith _ _ l _ _ _) = l
77 noMatch i tm = all (\x -> case matchClause i (delab' i x True True) tm of
82 mkClauses :: [PArg] -> [[PTerm]] -> [PTerm]
84 | all (== [Placeholder]) args = []
86 = do args' <- mkArg args
87 let tm = PApp fc (PRef fc n) (zipWith upd args' parg)
90 mkArg :: [[PTerm]] -> [[PTerm]]
92 mkArg (a : as) = do a' <- a
98fnub' acc (x : xs) | x `qelem` acc = fnub' acc (filter (not.(quickEq x)) xs)
99 | otherwise = fnub' (x : acc) xs
102-- quick check for constructor equality
103quickEq :: PTerm -> PTerm -> Bool
104quickEq (PRef _ n) (PRef _ n') = n == n'
105quickEq (PApp _ t as) (PApp _ t' as')
106 | length as == length as'
107 = quickEq t t' && and (zipWith quickEq (map getTm as) (map getTm as'))
108quickEq Placeholder Placeholder = True
112qelem x (y : ys) | x `quickEq` y = True
113 | otherwise = qelem x ys
115-- FIXME: Just look for which one is the deepest, then generate all
116-- possibilities up to that depth.
118genAll :: IState -> [PTerm] -> [PTerm]
120 = case filter (/=Placeholder) $ fnub (concatMap otherPats (fnub args)) of
122 xs -> inventConsts xs
124 -- if they're constants, invent a new one to make sure that
125 -- constants which are not explicitly handled are covered
126 inventConsts cs@(PConstant c : _) = map PConstant (ic' (mapMaybe getConst cs))
127 where getConst (PConstant c) = Just c
131 -- try constants until they're not in the list.
132 -- FIXME: It is, of course, possible that someone has enumerated all
133 -- the constants and matched on them (maybe in generated code) and this
134 -- will be really slow. This is sufficiently unlikely that we won't
137 ic' xs@(I _ : _) = firstMissing xs (lotsOfNums I)
138 ic' xs@(BI _ : _) = firstMissing xs (lotsOfNums BI)
139 ic' xs@(Fl _ : _) = firstMissing xs (lotsOfNums Fl)
140 ic' xs@(B8 _ : _) = firstMissing xs (lotsOfNums B8)
141 ic' xs@(B16 _ : _) = firstMissing xs (lotsOfNums B16)
142 ic' xs@(B32 _ : _) = firstMissing xs (lotsOfNums B32)
143 ic' xs@(B64 _ : _) = firstMissing xs (lotsOfNums B64)
144 ic' xs@(Ch _ : _) = firstMissing xs lotsOfChars
145 ic' xs@(Str _ : _) = firstMissing xs lotsOfStrings
147 -- The rest are types with only one case
150 firstMissing cs (x : xs) | x `elem` cs = firstMissing cs xs
153 lotsOfNums t = map t [0..]
154 lotsOfChars = map Ch ['a'..]
155 lotsOfStrings = map Str (map (("some string " ++).show) [1..])
157 conForm (PApp _ (PRef fc n) _) = isConName n (tt_ctxt i)
158 conForm (PRef fc n) = isConName n (tt_ctxt i)
161 nubMap f acc [] = acc
162 nubMap f acc (x : xs) = nubMap f (fnub' acc (f x)) xs
164 otherPats :: PTerm -> [PTerm]
165 otherPats o@(PRef fc n) = ops fc n [] o
166 otherPats o@(PApp _ (PRef fc n) xs) = ops fc n xs o
167 otherPats o@(PPair fc l r)
169 ([pimp (UN "A") Placeholder True,
170 pimp (UN "B") Placeholder True] ++
172 otherPats o@(PDPair fc t _ v)
173 = ops fc (UN "Ex_intro")
174 ([pimp (UN "a") Placeholder True,
175 pimp (UN "P") Placeholder True] ++
177 otherPats o@(PConstant c) = return o
178 otherPats arg = return Placeholder
181 | (TyDecl c@(DCon _ arity) ty : _) <- lookupDef n (tt_ctxt i)
182 = do xs' <- mapM otherPats (map getExpTm xs)
183 let p = resugar (PApp fc (PRef fc n) (zipWith upd xs' xs))
184 let tyn = getTy n (tt_ctxt i)
185 case lookupCtxt tyn (idris_datatypes i) of
186 (TI ns _ _ : _) -> p : map (mkPat fc) (ns \\ [n])
188 ops fc n arg o = return Placeholder
190 getExpTm (PImp _ True _ _ _ _) = Placeholder -- machine inferred, no point!
193 -- put it back to its original form
194 resugar (PApp _ (PRef fc (UN "Ex_intro")) [_,_,t,v])
195 = PDPair fc (getTm t) Placeholder (getTm v)
196 resugar (PApp _ (PRef fc n) [_,_,l,r])
198 = PPair fc (getTm l) (getTm r)
201 dropForce force (x : xs) i | i `elem` force
202 = upd Placeholder x : dropForce force xs (i + 1)
203 dropForce force (x : xs) i = x : dropForce force xs (i + 1)
204 dropForce _ [] _ = []
207 getTy n ctxt = case lookupTy n ctxt of
208 (t : _) -> case unApply (getRetTy t) of
209 (P _ tyn _, _) -> tyn
210 x -> error $ "Can't happen getTy 1 " ++ show (n, x)
211 _ -> error "Can't happen getTy 2"
213 mkPat fc x = case lookupCtxt x (idris_implicits i) of
215 -> PApp fc (PRef fc x) (map (upd Placeholder) pargs)
216 _ -> error "Can't happen - genAll"
218upd p' p = p { getTm = p' }
220-- Check if, in a given type n, the constructor cn : ty is strictly positive,
221-- and update the context accordingly
223checkPositive :: Name -> (Name, Type) -> Idris ()
224checkPositive n (cn, ty)
227 let tot = if p then Total (args ty) else Partial NotPositive
228 let ctxt' = setTotal cn tot (tt_ctxt i)
229 putIState (i { tt_ctxt = ctxt' })
230 logLvl 5 $ "Constructor " ++ show cn ++ " is " ++ show tot
231 addIBC (IBCTotal cn tot)
233 args t = [0..length (getArgTys t)-1]
235 cp (Bind n (Pi aty) sc) = posArg aty && cp sc
238 posArg (Bind _ (Pi nty) sc)
239 | (P _ n' _, args) <- unApply nty
240 = n /= n' && posArg sc
243calcProd :: IState -> FC -> Name -> [([Name], Term, Term)] -> Idris Totality
244calcProd i fc topn pats
247 -- every application of n must be in an argument of a coinductive
248 -- constructor, in every function reachable from here in the
250 cp n pats done = do patsprod <- mapM (prodRec n done) pats
252 then return Productive
253 else return (Partial NotProductive)
255 prodRec :: Name -> [Name] -> ([Name], Term, Term) -> Idris Bool
256 prodRec n done _ | n `elem` done = return True
257 prodRec n done (_, _, tm) = prod n done False tm
259 prod :: Name -> [Name] -> Bool -> Term -> Idris Bool
260 prod n done ok ap@(App _ _)
261 | (P _ (UN "lazy") _, [_, arg]) <- unApply ap = prod n done ok arg
262 | (P nt f _, args) <- unApply ap
263 = do recOK <- checkProdRec (n:done) f
265 let [ty] = lookupTy f ctxt -- must exist!
266 let co = cotype nt f ty in
267 if (not recOK) then return False else
269 then do argsprod <- mapM (prod n done co) args
270 return (and (ok : argsprod) )
271 else do argsprod <- mapM (prod n done co) args
272 return (and argsprod)
273 prod n done ok (App f a) = liftM2 (&&) (prod n done False f)
274 (prod n done False a)
275 prod n done ok (Bind _ (Let t v) sc)
276 = liftM2 (&&) (prod n done False v) (prod n done False v)
277 prod n done ok (Bind _ b sc) = prod n done ok sc
278 prod n done ok t = return True
280 checkProdRec :: [Name] -> Name -> Idris Bool
282 = case lookupCtxt f (idris_patdefs i) of
283 [(def, _)] -> do ok <- mapM (prodRec f done) def
285 _ -> return True -- defined elsewhere, can't call topn
287 cotype (DCon _ _) n ty
288 | (P _ t _, _) <- unApply (getRetTy ty)
289 = case lookupCtxt t (idris_datatypes i) of
290 [TI _ True _] -> True
292 cotype nt n ty = False
294calcTotality :: [Name] -> FC -> Name -> [([Name], Term, Term)]
296calcTotality path fc n pats
298 let opts = case lookupCtxt n (idris_flags i) of
301 case mapMaybe (checkLHS i) (map (\ (_, l, r) -> l) pats) of
302 (failure : _) -> return failure
303 _ -> if (Coinductive `elem` opts)
304 then calcProd i fc n pats
305 else checkSizeChange n
307 checkLHS i (P _ fn _)
308 = case lookupTotal fn (tt_ctxt i) of
309 [Partial _] -> return (Partial (Other [fn]))
311 checkLHS i (App f a) = mplus (checkLHS i f) (checkLHS i a)
312 checkLHS _ _ = Nothing
314checkTotality :: [Name] -> FC -> Name -> Idris Totality
315checkTotality path fc n
316 | n `elem` path = return (Partial (Mutual (n : path)))
319 updateContext (simplifyCasedef n)
322 let opts = case lookupCtxt n (idris_flags i) of
327 case lookupDef n ctxt of
328 [CaseOp _ _ _ _ pats _] ->
329 do t' <- if AssertTotal `elem` opts
330 then return $ Total []
331 else calcTotality path fc n pats
333 addIBC (IBCTotal n t')
334 -- if it's not total, it can't reduce, to keep
335 -- typechecking decidable
338 do setAccessibility n Frozen
339 addIBC (IBCAccess n Frozen)
340 logLvl 5 $ "HIDDEN: "
344 _ -> return $ Total []
348 Productive -> return t'
349 e -> do w <- cmdOptType WarnPartial
350 if TotalFn `elem` opts
351 then totalityError t'
352 else do when (w && not (PartialFn `elem` opts)) $
356 totalityError t = tclift $ tfail (At fc (Msg (show n ++ " is " ++ show t)))
360 case lookupDef n (tt_ctxt i) of
362 iputStrLn $ show fc ++ ":Warning - " ++ show n ++ " is " ++ show t
364-- let cg = lookupCtxtName Nothing n (idris_callgraph i)
365-- iputStrLn (show cg)
368checkDeclTotality :: (FC, Name) -> Idris Totality
369checkDeclTotality (fc, n)
370 = do logLvl 2 $ "Checking " ++ show n ++ " for totality"
372-- logLvl 2 $ "Built SCG"
374 checkTotality [] fc n
376-- Calculate the size change graph for this definition
378-- SCG for a function f consists of a list of:
379-- (g, [(a1, sizechange1), (a2, sizechange2), ..., (an, sizechangen)])
381-- where g is a function called
382-- a1 ... an are the arguments of f in positions 1..n of g
383-- sizechange1 ... sizechange2 is how their size has changed wrt the input
385-- Nothing, if the argument is unrelated to the input
387buildSCG :: (FC, Name) -> Idris ()
390 case lookupCtxt n (idris_callgraph ist) of
391 [cg] -> case lookupDef n (tt_ctxt ist) of
392 [CaseOp _ _ _ pats _ cd] ->
393 let (args, sc) = cases_totcheck cd in
394 do logLvl 2 $ "Building SCG for " ++ show n ++ " from\n"
395 ++ show pats ++ "\n" ++ show sc
396 let newscg = buildSCG' ist (rights pats) args
397 logLvl 5 $ show newscg
398 addToCG n ( cg { scg = newscg } )
399 [] -> logLvl 5 $ "Could not build SCG for " ++ show n ++ "\n"
400 x -> error $ "buildSCG: " ++ show (n, x)
402buildSCG' :: IState -> [(Term, Term)] -> [Name] -> [SCGEntry]
403buildSCG' ist pats args = nub $ concatMap scgPat pats where
404 scgPat (lhs, rhs) = let (f, pargs) = unApply (dePat lhs) in
405 findCalls (dePat rhs) (patvars lhs) pargs
407 findCalls ap@(App f a) pvs pargs
408 | (P _ (UN "lazy") _, [_, arg]) <- unApply ap
409 = findCalls arg pvs pargs
410 | (P _ n _, args) <- unApply ap
411 = mkChange n args pargs ++
412 concatMap (\x -> findCalls x pvs pargs) args
413 findCalls (App f a) pvs pargs
414 = findCalls f pvs pargs ++ findCalls a pvs pargs
415 findCalls (Bind n (Let t v) e) pvs pargs
416 = findCalls v pvs pargs ++ findCalls e (n : pvs) pargs
417 findCalls (Bind n _ e) pvs pargs
418 = findCalls e (n : pvs) pargs
419 findCalls (P _ f _ ) pvs pargs
420 | not (f `elem` pvs) = [(f, [])]
424 = case lookupTy n (tt_ctxt ist) of
425 [ty] -> expand 0 (normalise (tt_ctxt ist) [] ty) args
427 where expand i (Bind n (Pi _) sc) (x : xs) = x : expand (i + 1) sc xs
428 expand i (Bind n (Pi _) sc) [] = Just (i, Same) : expand (i + 1) sc []
431 mkChange n args pargs = [(n, expandToArity n (sizes args))]
434 sizes (a : as) = checkSize a pargs 0 : sizes as
436 -- find which argument in pargs <a> is smaller than, if any
437 checkSize a (p : ps) i
438 | a == p = Just (i, Same)
439 | smaller Nothing a (p, Nothing) = Just (i, Smaller)
440 | otherwise = checkSize a ps (i + 1)
441 checkSize a [] i = Nothing
443 -- the smaller thing we find must be the same type as <a>, and
444 -- not be coinductive - so carry the type of the constructor we've
447 smaller (Just tyn) a (t, Just tyt)
448 | a == t = isInductive (fst (unApply (getRetTy tyn)))
449 (fst (unApply (getRetTy tyt)))
450 smaller ty a (ap@(App f s), _)
451 | (P (DCon _ _) n _, args) <- unApply ap
452 = let tyn = getType n in
453 any (smaller (ty `mplus` Just tyn) a)
454 (zip args (map toJust (getArgTys tyn)))
455 -- check higher order recursive arguments
456 smaller ty (App f s) a = smaller ty f a
457 smaller _ _ _ = False
459 toJust (n, t) = Just t
461 getType n = case lookupTy n (tt_ctxt ist) of
462 [ty] -> ty -- must exist
464 isInductive (P _ nty _) (P _ nty' _) =
465 let co = case lookupCtxt nty (idris_datatypes ist) of
468 nty == nty' && not co
469 isInductive _ _ = False
471-- getTypeFam t | (P _ n _, _) <- unApply t
473 dePat (Bind x (PVar ty) sc) = dePat (instantiate (P Bound x ty) sc)
476 patvars (Bind x (PVar _) sc) = x : patvars sc
480buildSCG' :: IState -> SC -> [Name] -> [SCGEntry]
481buildSCG' ist sc args = -- trace ("Building SCG for " ++ show sc) $
482 nub $ scg sc (zip args args)
483 (zip args (zip args (repeat Same)))
485 scg :: SC -> [(Name, Name)] -> -- local var, originating top level var
486 [(Name, (Name, SizeChange))] -> -- orig to new, and relationship
488 scg (Case x alts) vars szs
489 = let x' = findTL x vars in
490 concatMap (scgAlt x' vars szs) alts
493 | Just x' <- lookup x vars
494 = if x' `elem` args then x'
498 scg (STerm tm) vars szs = scgTerm tm vars szs
501 -- how the arguments relate - either Smaller or Unknown
502 argRels :: Name -> [(Name, SizeChange)]
503 argRels n = let ctxt = tt_ctxt ist
504 [ty] = lookupTy n ctxt -- must exist!
505 P _ nty _ = fst (unApply (getRetTy ty))
506 co = case lookupCtxt nty (idris_datatypes ist) of
509 args = map snd (getArgTys ty) in
510 map (getRel co nty) (map (fst . unApply . getRetTy) args)
512 getRel True _ _ = (n, Unknown) -- coinductive
513 getRel _ ty (P _ n' _) | n' == ty = (n, Smaller)
514 getRel _ ty t = (n, Unknown)
516 scgAlt x vars szs (ConCase n _ args sc)
517 -- all args smaller than top variable of x in sc
518 -- (as long as they are in the same type family, and it's
520 | Just tvar <- lookup x vars
521 = let arel = argRels n
522 szs' = zipWith (\arg (_,t) -> (arg, (x, t))) args arel
524 vars' = nub (zip args (repeat tvar) ++ vars) in
526 | otherwise = scg sc vars szs
527 scgAlt x vars szs (ConstCase _ sc) = scg sc vars szs
528 scgAlt x vars szs (DefaultCase sc) = scg sc vars szs
530 scgTerm f@(App _ _) vars szs
531 | (P _ (UN "lazy") _, [_, arg]) <- unApply f
532 = scgTerm arg vars szs
533 | (P _ fn _, args) <- unApply f
534 = let rest = concatMap (\x -> scgTerm x vars szs) args in
535 case lookup fn vars of
537 Nothing -> nub $ (fn, map (mkChange szs) args) : rest
538 scgTerm (App f a) vars szs
539 = scgTerm f vars szs ++ scgTerm a vars szs
540 scgTerm (Bind n (Let t v) e) vars szs
541 = scgTerm v vars szs ++ scgTerm e vars szs
542 scgTerm (Bind n _ e) vars szs
543 = scgTerm e (nub ((n, n) : vars)) szs
544 scgTerm (P _ fn _) vars szs
545 = case lookup fn vars of
547 Nothing -> [(fn, [])]
550 mkChange :: [(Name, (Name, SizeChange))] -> Term
551 -> Maybe (Int, SizeChange)
553 | (P _ (UN "lazy") _, [_, arg]) <- unApply tm = mkChange szs arg
554 | (P _ n ty, _) <- unApply tm -- get higher order args too
555 = do sc <- lookup n szs
557 (_, Unknown) -> Nothing
558 (o, sc) -> do i <- getArgPos 0 o args
560 mkChange _ _ = Nothing
562 getArgPos :: Int -> Name -> [Name] -> Maybe Int
563 getArgPos i n [] = Nothing
564 getArgPos i n (x : xs) | n == x = Just i
565 | otherwise = getArgPos (i + 1) n xs
568checkSizeChange :: Name -> Idris Totality
569checkSizeChange n = do
571 case lookupCtxt n (idris_callgraph ist) of
572 [cg] -> do let ms = mkMultiPaths ist [] (scg cg)
573 logLvl 5 ("Multipath for " ++ show n ++ ":\n" ++
574 "from " ++ show (scg cg) ++ "\n" ++
575 show (length ms) ++ "\n" ++
576 showSep "\n" (map show ms))
578 -- every multipath must have an infinitely descending
579 -- thread, then the function terminates
580 -- also need to checks functions called are all total
581 -- (Unchecked is okay as we'll spot problems here)
582 let tot = map (checkMP ist (getArity ist n)) ms
583 logLvl 4 $ "Generated " ++ show (length tot) ++ " paths"
584 logLvl 6 $ "Paths for " ++ show n ++ " yield " ++ (show tot)
585 return (noPartial tot)
586 [] -> do logLvl 5 $ "No paths for " ++ show n
589 = case lookupTy n (tt_ctxt ist) of
590 [ty] -> arity (normalise (tt_ctxt ist) [] ty)
591 _ -> error "Can't happen: checkSizeChange.getArity"
593type MultiPath = [SCGEntry]
595mkMultiPaths :: IState -> MultiPath -> [SCGEntry] -> [MultiPath]
596mkMultiPaths ist path [] = [reverse path]
597mkMultiPaths ist path cg
598 = concat (map extend cg)
599 where extend (nextf, args)
600 | (nextf, args) `elem` path = [ reverse ((nextf, args) : path) ]
601 | [Unchecked] <- lookupTotal nextf (tt_ctxt ist)
602 = case lookupCtxt nextf (idris_callgraph ist) of
603 [ncg] -> mkMultiPaths ist ((nextf, args) : path) (scg ncg)
604 _ -> [ reverse ((nextf, args) : path) ]
605 | otherwise = [ reverse ((nextf, args) : path) ]
607-- do (nextf, args) <- cg
608-- if ((nextf, args) `elem` path)
609-- then return (reverse ((nextf, args) : path))
610-- else case lookupCtxt nextf (idris_callgraph ist) of
611-- [ncg] -> mkMultiPaths ist ((nextf, args) : path) (scg ncg)
612-- _ -> return (reverse ((nextf, args) : path))
614-- If any route along the multipath leads to infinite descent, we're fine.
615-- Try a route beginning with every argument.
616-- If we reach a point we've been to before, but with a smaller value,
617-- that means there is an infinitely descending path from that argument.
619checkMP :: IState -> Int -> MultiPath -> Totality
620checkMP ist i mp = if i > 0
621 then let paths = (map (tryPath 0 [] mp) [0..i-1]) in
622-- trace ("Paths " ++ show paths) $
624 else tryPath 0 [] mp 0
626 tryPath' d path mp arg
627 = let res = tryPath d path mp arg in
628 trace (show mp ++ "\n" ++ show arg ++ " " ++ show res) res
630 tryPath :: Int -> [((SCGEntry, Int), Int)] -> MultiPath -> Int -> Totality
631 tryPath desc path [] _ = Total []
632-- tryPath desc path ((UN "believe_me", _) : _) arg
633-- = Partial BelieveMe
634 -- if we get to a constructor, it's fine as long as it's strictly positive
635 tryPath desc path ((f, _) : es) arg
636 | [TyDecl (DCon _ _) _] <- lookupDef f (tt_ctxt ist)
637 = case lookupTotal f (tt_ctxt ist) of
638 [Total _] -> Unchecked -- okay so far
639 [Partial _] -> Partial (Other [f])
641 | [TyDecl (TCon _ _) _] <- lookupDef f (tt_ctxt ist)
643 tryPath desc path (e@(f, args) : es) arg
644 | e `elem` es && allNothing args = Partial (Mutual [f])
645 tryPath desc path (e@(f, nextargs) : es) arg
646 | Just d <- lookup (e, arg) path
648 then -- trace ("Descent " ++ show (desc - d) ++ " "
649 -- ++ show (path, e)) $
651 else Partial (Mutual (map (fst . fst . fst) path ++ [f]))
652 | e `elem` map (fst . fst) path
653 && not (f `elem` map fst es)
654 = Partial (Mutual (map (fst . fst . fst) path ++ [f]))
655 | [Unchecked] <- lookupTotal f (tt_ctxt ist) =
656 let argspos = case collapseNothing (zip nextargs [0..]) of
659-- trace (show (argspos, nextargs, path)) $
661 do (a, pos) <- argspos
663 Nothing -> -- don't know, but if the
664 -- rest definitely terminates without
665 -- any cycles with route so far,
666 -- then we might yet be total
667 case collapse (map (tryPath 0 (((e, arg), 0):path) es)
668 [0..length nextargs - 1]) of
669 Total _ -> return Unchecked
671 Just (nextarg, sc) ->
672 if nextarg == arg then
674 Same -> return $ tryPath desc (((e, arg), desc) : path)
676 Smaller -> return $ tryPath (desc+1)
677 (((e, arg), desc) : path)
680 _ -> trace ("Shouldn't happen " ++ show e) $
681 return (Partial Itself)
682 else return Unchecked in
683-- trace (show (desc, argspos, path, es, pathres)) $
684 collapse' Unchecked pathres
686 | [Total a] <- lookupTotal f (tt_ctxt ist) = Total a
687 | [Partial _] <- lookupTotal f (tt_ctxt ist) = Partial (Other [f])
688 | otherwise = Unchecked
690allNothing xs = null (collapseNothing (zip xs [0..]))
692collapseNothing ((Nothing, _) : xs)
693 = filter (\ (x, _) -> case x of
696collapseNothing (x : xs) = x : collapseNothing xs
697collapseNothing [] = []
699noPartial (Partial p : xs) = Partial p
700noPartial (_ : xs) = noPartial xs
701noPartial [] = Total []
703collapse xs = collapse' Unchecked xs
704collapse' def (Total r : xs) = Total r
705collapse' def (Unchecked : xs) = collapse' def xs
706collapse' def (d : xs) = collapse' d xs
707-- collapse' Unchecked [] = Total []
708collapse' def [] = def
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list