on master help sign in
Coverage checker fix
fb6a0edEdwin Brady
libs/base/Data/HVect.idr+1
@@ -19,6 +19,7 @@ using (k : Nat, ts : Vect k Type)
19 deleteAt : {us : Vect (S l) Type} -> (i : Fin (S l)) -> HVect us -> HVect (deleteAt i us)
19 deleteAt : {us : Vect (S l) Type} -> (i : Fin (S l)) -> HVect us -> HVect (deleteAt i us)
20 deleteAt fZ (x::xs) = xs
20 deleteAt fZ (x::xs) = xs
21 deleteAt {l = S m} (fS j) (x::xs) = x :: deleteAt j xs
21 deleteAt {l = S m} (fS j) (x::xs) = x :: deleteAt j xs
22+ deleteAt {l = Z} (fS j) (x::xs) = absurd j
22 deleteAt _ [] impossible
23 deleteAt _ [] impossible
23
24
24 replaceAt : (i : Fin k) -> t -> HVect ts -> HVect (replaceAt i t ts)
25 replaceAt : (i : Fin k) -> t -> HVect ts -> HVect (replaceAt i t ts)
libs/prelude/Prelude/Vect.idr+2
@@ -7,6 +7,7 @@ import Prelude.List
7import Prelude.Classes
7import Prelude.Classes
8import Prelude.Nat
8import Prelude.Nat
9import Prelude.Bool
9import Prelude.Bool
10+import Prelude.Uninhabited
10
11
11%access public
12%access public
12%default total
13%default total
@@ -71,6 +72,7 @@ index fZ [] impossible
71deleteAt : Fin (S n) -> Vect (S n) a -> Vect n a
72deleteAt : Fin (S n) -> Vect (S n) a -> Vect n a
72deleteAt fZ (x::xs) = xs
73deleteAt fZ (x::xs) = xs
73deleteAt {n = S m} (fS k) (x::xs) = x :: deleteAt k xs
74deleteAt {n = S m} (fS k) (x::xs) = x :: deleteAt k xs
75+deleteAt {n = Z} (fS k) (x::xs) = absurd k
74deleteAt _ [] impossible
76deleteAt _ [] impossible
75
77
76||| Replace an element at a particlar index with another
78||| Replace an element at a particlar index with another
src/Idris/AbsSyntax.hs+4−3
@@ -1533,8 +1533,6 @@ matchClause' names i x y = checkRpts $ match (fullApp x) (fullApp y) where
1533 = do mf <- match' f f'
1533 = do mf <- match' f f'
1534 ms <- zipWithM matchArg args args'
1534 ms <- zipWithM matchArg args args'
1535 return (mf ++ concat ms)
1535 return (mf ++ concat ms)
1536−-- match (PRef _ n) (PRef _ n') | n == n' = return []
1537−-- | otherwise = Nothing
1538 match (PRef f n) (PApp _ x []) = match (PRef f n) x
1536 match (PRef f n) (PApp _ x []) = match (PRef f n) x
1539 match (PPatvar f n) xr = match (PRef f n) xr
1537 match (PPatvar f n) xr = match (PRef f n) xr
1540 match xr (PPatvar f n) = match xr (PRef f n)
1538 match xr (PPatvar f n) = match xr (PRef f n)
@@ -1544,7 +1542,10 @@ matchClause' names i x y = checkRpts $ match (fullApp x) (fullApp y) where
1544 (not (isConName n (tt_ctxt i) || isFnName n (tt_ctxt i))
1542 (not (isConName n (tt_ctxt i) || isFnName n (tt_ctxt i))
1545 || tm == Placeholder)
1543 || tm == Placeholder)
1546 = return [(n, tm)]
1544 = return [(n, tm)]
1545+ -- if one namespace is missing, drop the other
1547− | n == n' = return []
1546+ | n == n' || n == dropNS n' || dropNS n == n' = return []
1547+ where dropNS (NS n _) = n
1548+ dropNS n = n
1548 match (PRef _ n) tm
1549 match (PRef _ n) tm
1549 | not names && (not (isConName n (tt_ctxt i) ||
1550 | not names && (not (isConName n (tt_ctxt i) ||
1550 isFnName n (tt_ctxt i)) || tm == Placeholder)
1551 isFnName n (tt_ctxt i)) || tm == Placeholder)
src/Idris/Coverage.hs+19−7
@@ -18,10 +18,14 @@ import Debug.Trace
18
18
19import Control.Monad.State.Strict
19import Control.Monad.State.Strict
20
20
21+-- Generate a pattern from an 'impossible' LHS. (Need this to eliminate the
22+-- pattern clauses which have been provided explicitly from new clause
23+-- generation.)
24+
21mkPatTm :: PTerm -> Idris Term
25mkPatTm :: PTerm -> Idris Term
22mkPatTm t = do i <- getIState
26mkPatTm t = do i <- getIState
23 let timp = addImpl' True [] [] i t
27 let timp = addImpl' True [] [] i t
24− evalStateT (toTT timp) 0
28+ evalStateT (toTT (mapPT deNS timp)) 0
25 where
29 where
26 toTT (PRef _ n) = do i <- lift getIState
30 toTT (PRef _ n) = do i <- lift getIState
27 case lookupDef n (tt_ctxt i) of
31 case lookupDef n (tt_ctxt i) of
@@ -30,10 +34,16 @@ mkPatTm t = do i <- getIState
30 toTT (PApp _ t args) = do t' <- toTT t
34 toTT (PApp _ t args) = do t' <- toTT t
31 args' <- mapM (toTT . getTm) args
35 args' <- mapM (toTT . getTm) args
32 return $ mkApp t' args'
36 return $ mkApp t' args'
37+ -- For alternatives, pick the first and drop the namespaces. It doesn't
38+ -- really matter which is taken since matching will ignore the namespace.
39+ toTT (PAlternative _ (a : as)) = toTT a
33 toTT _ = do v <- get
40 toTT _ = do v <- get
34 put (v + 1)
41 put (v + 1)
35 return (P Bound (sMN v "imp") Erased)
42 return (P Bound (sMN v "imp") Erased)
36
43
44+ deNS (PRef f (NS n _)) = PRef f n
45+ deNS t = t
46+
37-- Given a list of LHSs, generate a extra clauses which cover the remaining
47-- Given a list of LHSs, generate a extra clauses which cover the remaining
38-- cases. The ones which haven't been provided are marked 'absurd' so that the
48-- cases. The ones which haven't been provided are marked 'absurd' so that the
39-- checker will make sure they can't happen.
49-- checker will make sure they can't happen.
@@ -50,10 +60,10 @@ genClauses fc n xs given
50 logLvl 5 $ "COVERAGE of " ++ show n
60 logLvl 5 $ "COVERAGE of " ++ show n
51 logLvl 5 $ show (map length argss) ++ "\n" ++ show (map length all_args)
61 logLvl 5 $ show (map length argss) ++ "\n" ++ show (map length all_args)
52 logLvl 10 $ show argss ++ "\n" ++ show all_args
62 logLvl 10 $ show argss ++ "\n" ++ show all_args
53− logLvl 10 $ "Original: \n" ++
63+ logLvl 1 $ "Original: \n" ++
54 showSep "\n" (map (\t -> showTm i (delab' i t True True)) xs)
64 showSep "\n" (map (\t -> showTm i (delab' i t True True)) xs)
55 -- add an infinite supply of explicit arguments to update the possible
65 -- add an infinite supply of explicit arguments to update the possible
56− -- cases for (the return type may be variadic, or function type, sp
66+ -- cases for (the return type may be variadic, or function type, so
57 -- there may be more case splitting that the idris_implicits record
67 -- there may be more case splitting that the idris_implicits record
58 -- suggests)
68 -- suggests)
59 let parg = case lookupCtxt n (idris_implicits i) of
69 let parg = case lookupCtxt n (idris_implicits i) of
@@ -61,10 +71,10 @@ genClauses fc n xs given
61 _ -> repeat (pexp Placeholder)
71 _ -> repeat (pexp Placeholder)
62 let tryclauses = mkClauses parg all_args
72 let tryclauses = mkClauses parg all_args
63 logLvl 2 $ show (length tryclauses) ++ " initially to check"
73 logLvl 2 $ show (length tryclauses) ++ " initially to check"
64− logLvl 5 $ showSep "\n" (map (showTm i) tryclauses)
74+ logLvl 1 $ showSep "\n" (map (showTm i) tryclauses)
65 let new = filter (noMatch i) (nub tryclauses)
75 let new = filter (noMatch i) (nub tryclauses)
66 logLvl 1 $ show (length new) ++ " clauses to check for impossibility"
76 logLvl 1 $ show (length new) ++ " clauses to check for impossibility"
67− logLvl 5 $ "New clauses: \n" ++ showSep "\n" (map (showTm i) new)
77+ logLvl 3 $ "New clauses: \n" ++ showSep "\n" (map (showTm i) new)
68-- ++ " from:\n" ++ showSep "\n" (map (showImp True) tryclauses)
78-- ++ " from:\n" ++ showSep "\n" (map (showImp True) tryclauses)
69 return new
79 return new
70-- return (map (\t -> PClause n t [] PImpossible []) new)
80-- return (map (\t -> PClause n t [] PImpossible []) new)
@@ -75,9 +85,11 @@ genClauses fc n xs given
75 lhsApp (PClause _ _ l _ _ _) = l
85 lhsApp (PClause _ _ l _ _ _) = l
76 lhsApp (PWith _ _ l _ _ _) = l
86 lhsApp (PWith _ _ l _ _ _) = l
77
87
88+ -- Return whether the given clause matches none of the input clauses
89+ -- (xs)
78 noMatch i tm = all (\x -> case matchClause i (delab' i x True True) tm of
90 noMatch i tm = all (\x -> case matchClause i (delab' i x True True) tm of
79− Right _ -> False
91+ Right ms -> False
80− Left miss -> True) xs
92+ Left miss -> True) xs
81
93
82
94
83 mkClauses :: [PArg] -> [[PTerm]] -> [PTerm]
95 mkClauses :: [PArg] -> [[PTerm]] -> [PTerm]
test/error004/FunErrTest.idr+1−1
@@ -6,7 +6,6 @@ import Language.Reflection.Utils
6
6
7%language ErrorReflection
7%language ErrorReflection
8
8
9−
10total
9total
11cadr : (xs : List a)
10cadr : (xs : List a)
12 -> {auto cons1 : isCons xs = True}
11 -> {auto cons1 : isCons xs = True}
@@ -14,6 +13,7 @@ cadr : (xs : List a)
14 -> a
13 -> a
15cadr (x :: (y :: _)) {cons1=refl} {cons2=refl} = y
14cadr (x :: (y :: _)) {cons1=refl} {cons2=refl} = y
16cadr (x :: []) {cons1=refl} {cons2=refl} impossible
15cadr (x :: []) {cons1=refl} {cons2=refl} impossible
16+cadr [] {cons1=refl} {cons2=refl} impossible
17
17
18extractList : TT -> Maybe TT
18extractList : TT -> Maybe TT
19extractList (App (App reflCon (App isCons lst)) _) = Just lst
19extractList (App (App reflCon (App isCons lst)) _) = Just lst