@@ -62,30 +62,30 @@ mkPatTm t = do i <- getIState
63-- This will only work after the given clauses have been typechecked and the
63-- This will only work after the given clauses have been typechecked and the
64-- names are fully explicit!
64-- names are fully explicit!
65−genClauses :: FC -> Name -> [([Name], Term)] -> -- (Argument names, LHS)
65+genClauses :: FC -> Name -> [([Name], Term)] -> -- (Argument names, LHS)
66 [PTerm] -> Idris [PTerm]
66 [PTerm] -> Idris [PTerm]
67-- No clauses (only valid via elab reflection). We should probably still do
67-- No clauses (only valid via elab reflection). We should probably still do
68-- a check here somehow, e.g. that one of the arguments is an obviously
68-- a check here somehow, e.g. that one of the arguments is an obviously
69-- empty type. In practice, this should only really be used for Void elimination.
69-- empty type. In practice, this should only really be used for Void elimination.
70−genClauses fc n lhs_tms [] = return []
70+genClauses fc n lhs_tms [] = return []
71genClauses fc n lhs_tms given
71genClauses fc n lhs_tms given
72 = do i <- getIState
72 = do i <- getIState
74− let lhs_given = zipWith removePlaceholders lhs_tms
74+ let lhs_given = zipWith removePlaceholders lhs_tms
75 (map (stripUnmatchable i) (map flattenArgs given))
75 (map (stripUnmatchable i) (map flattenArgs given))
77 logCoverage 5 $ "Building coverage tree for:\n" ++ showSep "\n" (map show (lhs_given))
77 logCoverage 5 $ "Building coverage tree for:\n" ++ showSep "\n" (map show (lhs_given))
78 let givenpos = mergePos (map getGivenPos given)
78 let givenpos = mergePos (map getGivenPos given)
80− (cns, ctree_in) <-
80+ (cns, ctree_in) <-
81 case simpleCase False (UnmatchedCase "Undefined") False
81 case simpleCase False (UnmatchedCase "Undefined") False
82 (CoverageCheck givenpos) emptyFC [] []
82 (CoverageCheck givenpos) emptyFC [] []
83− lhs_given
83+ lhs_given
84 (const []) of
84 (const []) of
85 OK (CaseDef cns ctree_in _) ->
85 OK (CaseDef cns ctree_in _) ->
86 return (cns, ctree_in)
86 return (cns, ctree_in)
87 Error e -> tclift $ tfail $ At fc e
87 Error e -> tclift $ tfail $ At fc e
89 let ctree = trimOverlapping (addMissingCons i ctree_in)
89 let ctree = trimOverlapping (addMissingCons i ctree_in)
90 let (coveredas, missingas) = mkNewClauses (tt_ctxt i) n cns ctree
90 let (coveredas, missingas) = mkNewClauses (tt_ctxt i) n cns ctree
91 let covered = map (\t -> delab' i t True True) coveredas
91 let covered = map (\t -> delab' i t True True) coveredas
@@ -94,9 +94,9 @@ genClauses fc n lhs_tms given
95 logCoverage 5 $ "Coverage from case tree for " ++ show n ++ ": " ++ show ctree
95 logCoverage 5 $ "Coverage from case tree for " ++ show n ++ ": " ++ show ctree
96 logCoverage 2 $ show (length missing) ++ " missing clauses for " ++ show n
96 logCoverage 2 $ show (length missing) ++ " missing clauses for " ++ show n
97− logCoverage 3 $ "Missing clauses:\n" ++ showSep "\n"
97+ logCoverage 3 $ "Missing clauses:\n" ++ showSep "\n"
98 (map showTmImpls missing)
98 (map showTmImpls missing)
99− logCoverage 10 $ "Covered clauses:\n" ++ showSep "\n"
99+ logCoverage 10 $ "Covered clauses:\n" ++ showSep "\n"
100 (map showTmImpls covered)
100 (map showTmImpls covered)
101 return missing
101 return missing
@@ -132,16 +132,16 @@ removePlaceholders (ns, tm) ptm = (ns, rp tm ptm, Erased)
132 | (tf, [tyl, tyr, tl, tr]) <- unApply tm
132 | (tf, [tyl, tyr, tl, tr]) <- unApply tm
133 = let tl' = rp tl pl
133 = let tl' = rp tl pl
134 tr' = rp tr pr in
134 tr' = rp tr pr in
135− mkApp tf [Erased, Erased, tl', tr']
135+ mkApp tf [Erased, Erased, tl', tr']
136 rp tm (PDPair _ _ _ pl pt pr)
136 rp tm (PDPair _ _ _ pl pt pr)
137 | (tf, [tyl, tyr, tl, tr]) <- unApply tm
137 | (tf, [tyl, tyr, tl, tr]) <- unApply tm
138 = let tl' = rp tl pl
138 = let tl' = rp tl pl
139 tr' = rp tr pr in
139 tr' = rp tr pr in
140− mkApp tf [Erased, Erased, tl', tr']
140+ mkApp tf [Erased, Erased, tl', tr']
141 rp tm _ = tm
141 rp tm _ = tm
143mkNewClauses :: Context -> Name -> [Name] -> SC -> ([Term], [Term])
143mkNewClauses :: Context -> Name -> [Name] -> SC -> ([Term], [Term])
144−mkNewClauses ctxt fn ns sc
144+mkNewClauses ctxt fn ns sc
145 = (map (mkPlApp (P Ref fn Erased)) $
145 = (map (mkPlApp (P Ref fn Erased)) $
146 mkFromSC True (map (\n -> P Ref n Erased) ns) sc,
146 mkFromSC True (map (\n -> P Ref n Erased) ns) sc,
147 map (mkPlApp (P Ref fn Erased)) $
147 map (mkPlApp (P Ref fn Erased)) $
@@ -149,7 +149,7 @@ mkNewClauses ctxt fn ns sc
150 mkPlApp f args = mkApp f (map erasePs args)
150 mkPlApp f args = mkApp f (map erasePs args)
152− erasePs ap@(App t f a)
152+ erasePs ap@(App t f a)
153 | (f, args) <- unApply ap = mkApp f (map erasePs args)
153 | (f, args) <- unApply ap = mkApp f (map erasePs args)
154 erasePs (P _ n _) | not (isConName n ctxt) = Erased
154 erasePs (P _ n _) | not (isConName n ctxt) = Erased
155 erasePs tm = tm
155 erasePs tm = tm
@@ -157,16 +157,16 @@ mkNewClauses ctxt fn ns sc
157 mkFromSC cov args sc = evalState (mkFromSC' cov args sc) []
157 mkFromSC cov args sc = evalState (mkFromSC' cov args sc) []
159 mkFromSC' :: Bool -> [Term] -> SC -> State [[Term]] [[Term]]
159 mkFromSC' :: Bool -> [Term] -> SC -> State [[Term]] [[Term]]
160− mkFromSC' cov args (STerm _)
160+ mkFromSC' cov args (STerm _)
161 = if cov then return [args] else return [] -- leaf of provided case
161 = if cov then return [args] else return [] -- leaf of provided case
162− mkFromSC' cov args (UnmatchedCase _)
162+ mkFromSC' cov args (UnmatchedCase _)
163 = if cov then return [] else return [args] -- leaf of missing case
163 = if cov then return [] else return [args] -- leaf of missing case
164 mkFromSC' cov args ImpossibleCase = return []
164 mkFromSC' cov args ImpossibleCase = return []
165 mkFromSC' cov args (Case _ x alts)
165 mkFromSC' cov args (Case _ x alts)
166 = do done <- get
166 = do done <- get
167 if (args `elem` done)
167 if (args `elem` done)
168 then return []
168 then return []
169− else do alts' <- mapM (mkFromAlt cov args x) alts
169+ else do alts' <- mapM (mkFromAlt cov args x) alts
170 put (args : done)
170 put (args : done)
171 return (concat alts')
171 return (concat alts')
172 mkFromSC' cov args _ = return [] -- Should never happen
172 mkFromSC' cov args _ = return [] -- Should never happen
@@ -178,7 +178,7 @@ mkNewClauses ctxt fn ns sc
178 args' = map (subst x argrep) args in
178 args' = map (subst x argrep) args in
179 mkFromSC' cov args' sc
179 mkFromSC' cov args' sc
180 mkFromAlt cov args x (ConstCase c sc)
180 mkFromAlt cov args x (ConstCase c sc)
181− = let argrep = Constant c
181+ = let argrep = Constant c
182 args' = map (subst x argrep) args in
182 args' = map (subst x argrep) args in
183 mkFromSC' cov args' sc
183 mkFromSC' cov args' sc
184 mkFromAlt cov args x (DefaultCase sc)
184 mkFromAlt cov args x (DefaultCase sc)
@@ -195,18 +195,18 @@ addMissingConsSt :: IState -> SC -> State Int SC
195addMissingConsSt ist (Case t n alts) = liftM (Case t n) (addMissingAlts n alts)
195addMissingConsSt ist (Case t n alts) = liftM (Case t n) (addMissingAlts n alts)
197 addMissingAlt :: CaseAlt -> State Int CaseAlt
197 addMissingAlt :: CaseAlt -> State Int CaseAlt
198− addMissingAlt (ConCase n i ns sc)
198+ addMissingAlt (ConCase n i ns sc)
199 = liftM (ConCase n i ns) (addMissingConsSt ist sc)
199 = liftM (ConCase n i ns) (addMissingConsSt ist sc)
200− addMissingAlt (FnCase n ns sc)
200+ addMissingAlt (FnCase n ns sc)
201 = liftM (FnCase n ns) (addMissingConsSt ist sc)
201 = liftM (FnCase n ns) (addMissingConsSt ist sc)
202− addMissingAlt (ConstCase c sc)
202+ addMissingAlt (ConstCase c sc)
203 = liftM (ConstCase c) (addMissingConsSt ist sc)
203 = liftM (ConstCase c) (addMissingConsSt ist sc)
204− addMissingAlt (SucCase n sc)
204+ addMissingAlt (SucCase n sc)
205 = liftM (SucCase n) (addMissingConsSt ist sc)
205 = liftM (SucCase n) (addMissingConsSt ist sc)
206− addMissingAlt (DefaultCase sc)
206+ addMissingAlt (DefaultCase sc)
207 = liftM DefaultCase (addMissingConsSt ist sc)
207 = liftM DefaultCase (addMissingConsSt ist sc)
209− addMissingAlts argn as
209+ addMissingAlts argn as
210-- | any hasDefault as = map addMissingAlt as
210-- | any hasDefault as = map addMissingAlt as
211 | cons@(n:_) <- mapMaybe collectCons as,
211 | cons@(n:_) <- mapMaybe collectCons as,
212 Just tyn <- getConType n,
212 Just tyn <- getConType n,
@@ -226,7 +226,7 @@ addMissingConsSt ist (Case t n alts) = liftM (Case t n) (addMissingAlts n alts)
226 addCases missing (DefaultCase rhs : rest)
226 addCases missing (DefaultCase rhs : rest)
227 = do missing' <- mapM (genMissingAlt rhs) missing
227 = do missing' <- mapM (genMissingAlt rhs) missing
228 return (mapMaybe id missing' ++ rest)
228 return (mapMaybe id missing' ++ rest)
229− addCases missing (c : rest)
229+ addCases missing (c : rest)
230 = liftM (c :) $ addCases missing rest
230 = liftM (c :) $ addCases missing rest
232 addCons missing [] = []
232 addCons missing [] = []
@@ -258,7 +258,7 @@ addMissingConsSt ist (Case t n alts) = liftM (Case t n) (addMissingAlts n alts)
258 case unApply (getRetTy (normalise (tt_ctxt ist) [] ty)) of
258 case unApply (getRetTy (normalise (tt_ctxt ist) [] ty)) of
259 (P _ tyn _, _) -> Just tyn
259 (P _ tyn _, _) -> Just tyn
260 _ -> Nothing
260 _ -> Nothing
262 -- for every constant in a term (at any level) take next one to make sure
262 -- for every constant in a term (at any level) take next one to make sure
263 -- that constants which are not explicitly handled are covered
263 -- that constants which are not explicitly handled are covered
264 nextConst (I c) = I (c + 1)
264 nextConst (I c) = I (c + 1)
@@ -312,7 +312,7 @@ trimOverlapping sc = trim [] [] sc
312 substMatch ca (_:cs) = substMatch ca cs
312 substMatch ca (_:cs) = substMatch ca cs
314 substNames [] sc = sc
314 substNames [] sc = sc
315− substNames ((n, n') : ns) sc
315+ substNames ((n, n') : ns) sc
316 = substNames ns (substSC n n' sc)
316 = substNames ns (substSC n n' sc)
318 notConMatch cs (ConCase cn t args sc) = cn `notElem` cs
318 notConMatch cs (ConCase cn t args sc) = cn `notElem` cs
@@ -358,14 +358,14 @@ recoverableCoverage ctxt (CantUnify r (topx, _) (topy, _) e _ _)
358 -- The state is a mapping of name to what it has failed to unify
358 -- The state is a mapping of name to what it has failed to unify
360 checkRec :: Term -> Term -> State [(Name, Term)] Bool
360 checkRec :: Term -> Term -> State [(Name, Term)] Bool
361− checkRec (P Bound x _) tm
361+ checkRec (P Bound x _) tm
362 | (P yt _ _, _) <- unApply tm,
362 | (P yt _ _, _) <- unApply tm,
363 conType yt = do nmap <- get
363 conType yt = do nmap <- get
364 case lookup x nmap of
364 case lookup x nmap of
365 Nothing -> do put ((x, tm) : nmap)
365 Nothing -> do put ((x, tm) : nmap)
366 return True
366 return True
367 Just y' -> checkRec tm y'
367 Just y' -> checkRec tm y'
368− checkRec tm (P Bound y _)
368+ checkRec tm (P Bound y _)
369 | (P xt _ _, _) <- unApply tm,
369 | (P xt _ _, _) <- unApply tm,
370 conType xt = do nmap <- get
370 conType xt = do nmap <- get
371 case lookup y nmap of
371 case lookup y nmap of
@@ -379,13 +379,13 @@ recoverableCoverage ctxt (CantUnify r (topx, _) (topy, _) e _ _)
379 (f', as') <- unApply fa'
379 (f', as') <- unApply fa'
380 = if (length as /= length as')
380 = if (length as /= length as')
381 then checkRec f f'
381 then checkRec f f'
382− else checkRecs (f : as) (f' : as')
382+ else checkRecs (f : as) (f' : as')
384 checkRecs [] [] = return True
384 checkRecs [] [] = return True
385 checkRecs (a : as) (b : bs) = do aok <- checkRec a b
385 checkRecs (a : as) (b : bs) = do aok <- checkRec a b
386 asok <- checkRecs as bs
386 asok <- checkRecs as bs
387 return (aok && asok)
387 return (aok && asok)
388− checkRec (P xt x _) (P yt y _)
388+ checkRec (P xt x _) (P yt y _)
389 | x == y = return True
389 | x == y = return True
390 | ntRec xt yt = return True
390 | ntRec xt yt = return True
391 checkRec _ _ = return False
391 checkRec _ _ = return False