1{-# LANGUAGE PatternGuards #-}
3module Idris.Coverage where
13-- Given a list of LHSs, generate a extra clauses which cover the remaining
14-- cases. The ones which haven't been provided are marked 'absurd' so that the
15-- checker will make sure they can't happen.
17-- This will only work after the given clauses have been typechecked and the
18-- names are fully explicit!
20genClauses :: FC -> Name -> [Term] -> [PClause] -> Idris [PClause]
21genClauses fc n xs given
23 let lhss = map (getLHS i) xs
24 let argss = transpose lhss
25 let all_args = map (genAll i) argss
26 logLvl 7 $ "COVERAGE of " ++ show n
27 logLvl 10 $ show argss ++ "\n" ++ show all_args
28 logLvl 10 $ "Original: \n" ++
29 showSep "\n" (map (\t -> showImp True (delab' i t True)) xs)
30 let parg = case lookupCtxt Nothing n (idris_implicits i) of
32 _ -> repeat (pexp Placeholder)
33 let new = mnub i $ filter (noMatch i) $ mkClauses parg all_args
34 logLvl 7 $ "New clauses: \n" ++ showSep "\n" (map (showImp True) new)
35 return (map (\t -> PClause n t [] PImpossible []) new)
37 | (f, args) <- unApply term = map (\t -> delab' i t True) args
40 lhsApp (PClause _ l _ _ _) = l
41 lhsApp (PWith _ l _ _ _) = l
45 if (any (\t -> case matchClause x t of
47 Left _ -> False) xs) then mnub i xs
50 noMatch i tm = all (\x -> case matchClause (delab' i x True) tm of
55 mkClauses :: [PArg] -> [[PTerm]] -> [PTerm]
57 = do args' <- mkArg args
58 let tm = PApp fc (PRef fc n) (zipWith upd args' parg)
61 mkArg :: [[PTerm]] -> [[PTerm]]
63 mkArg (a : as) = do a' <- a
67genAll :: IState -> [PTerm] -> [PTerm]
68genAll i args = concatMap otherPats (nub args)
70 otherPats :: PTerm -> [PTerm]
71 otherPats o@(PRef fc n) = ops fc n [] o
72 otherPats o@(PApp _ (PRef fc n) xs) = ops fc n xs o
73 otherPats arg = return arg
76 | (TyDecl c@(DCon _ arity) ty : _) <- lookupDef Nothing n (tt_ctxt i)
77 = do xs' <- mapM otherPats (map getTm xs)
78 let p = PApp fc (PRef fc n) (zipWith upd xs' xs)
79 let tyn = getTy n (tt_ctxt i)
80 case lookupCtxt Nothing tyn (idris_datatypes i) of
81 (TI ns : _) -> p : map (mkPat fc) (ns \\ [n])
83 ops fc n arg o = return o
85 getTy n ctxt = case lookupTy Nothing n ctxt of
86 (t : _) -> case unApply (getRetTy t) of
88 x -> error $ "Can't happen getTy 1 " ++ show (n, x)
89 _ -> error "Can't happen getTy 2"
91 mkPat fc x = case lookupCtxt Nothing x (idris_implicits i) of
93 -> PApp fc (PRef fc x) (map (upd Placeholder) pargs)
94 _ -> error "Can't happen - genAll"
96upd p' p = p { getTm = p' }
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