0 | module TTImp.ProcessDecls.Totality
2 | import Core.Context.Log
3 | import Core.Termination
5 | import Libraries.Data.NameMap
10 | checkTotalityOK : {auto c : Ref Ctxt Defs} ->
11 | Name -> Core (Maybe Error)
12 | checkTotalityOK (NS _ (MN {})) = pure Nothing
13 | checkTotalityOK (NS _ (CaseBlock {})) = pure Nothing
15 | = do defs <- get Ctxt
16 | Just gdef <- lookupCtxtExact n (gamma defs)
17 | | Nothing => pure Nothing
18 | let fc = location gdef
20 | let treq = fromMaybe !getDefaultTotalityOption (findSetTotal (flags gdef))
24 | case definition gdef of
25 | TCon {} => ignore $
checkPositive fc n
29 | let tot = totality gdef
30 | log "totality" 3 $
show n ++ " must be: " ++ show treq
32 | PartialOK => pure Nothing
33 | CoveringOnly => checkCovering fc (isCovering tot)
34 | Total => checkTotality fc
36 | checkCovering : FC -> Covering -> Core (Maybe Error)
37 | checkCovering fc IsCovering = pure Nothing
38 | checkCovering fc cov
39 | = pure (Just (NotCovering fc n cov))
41 | checkTotality : FC -> Core (Maybe Error)
43 | = do ignore $
logTime 3 ("Checking Termination " ++ show n) (checkTotal fc n)
45 | t <- getTotality fc n
46 | err <- checkCovering fc (isCovering t)
47 | maybe (case isTerminating t of
48 | NotTerminating p => pure (Just (NotTotal fc n p))
58 | getTotalityErrors : {auto c : Ref Ctxt Defs} ->
61 | = do defs <- get Ctxt
62 | errs <- traverse checkTotalityOK (keys (toSave defs))
63 | pure (mapMaybe id errs)