Skip to content

Commit 1e00277

Browse files
authored
[ fix #1859 ] Undo my mistakes (#1866)
1 parent 2d7ddc6 commit 1e00277

File tree

10 files changed

+59
-14
lines changed

10 files changed

+59
-14
lines changed

libs/contrib/System/Console/GetOpt.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ getOpt : ArgOrder a -- non-option handling
237237
getOpt _ _ [] = emptyRes
238238
getOpt ordering descs (arg::args) =
239239
let (opt,rest) = getNext (unpack arg) args descs
240-
res = getOpt ordering descs rest
240+
res = getOpt ordering descs (assert_smaller args rest)
241241
in case (opt,ordering) of
242242
(Opt x, _) => {options $= (x::)} res
243243
(UnreqOpt x, _) => {unrecognized $= (x::)} res

libs/contrib/Text/Lexer/Tokenizer.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ tokenise reject tokenizer line col acc str
121121
end = endFn tag
122122
beginTok'' = MkBounded (mapBegin beginTok') False (MkBounds line col line' col')
123123
(midToks, (reason, line'', col'', rest'')) =
124-
tokenise end middle line' col' [] rest
124+
assert_total (tokenise end middle line' col' [] rest)
125125
in case reason of
126126
(ComposeNotClosing _ _) => Left reason
127127
_ => let Just (endTok', lineEnd, colEnd, restEnd) =

libs/contrib/Text/PrettyPrint/Prettyprinter/SimpleDocTree.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ sdocToTreeParser (SLine i rest) = case sdocToTreeParser rest of
7070
sdocToTreeParser (SAnnPush ann rest) = case sdocToTreeParser rest of
7171
(tree, Nothing) => (Nothing, Nothing)
7272
(Just tree, Nothing) => (Just $ STAnn ann tree, Nothing)
73-
(Just tree, Just rest') => case sdocToTreeParser rest' of
73+
(Just tree, Just rest') => case sdocToTreeParser (assert_smaller rest rest') of
7474
(Just tree', rest'') => (Just $ STConcat [STAnn ann tree, tree'], rest'')
7575
(Nothing, rest'') => (Just $ STAnn ann tree, rest'')
76-
(Nothing, Just rest') => assert_total $ sdocToTreeParser rest'
76+
(Nothing, Just rest') => sdocToTreeParser (assert_smaller rest rest')
7777
(Nothing, Nothing) => (Nothing, Nothing)
7878
sdocToTreeParser (SAnnPop rest) = (Nothing, Just rest)
7979

src/Core/Termination.idr

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,11 @@ mutual
384384
log "totality.termination.sizechange" 10 $ "Looking under " ++ show !(toFullNames fn)
385385
aSmaller <- resolved (gamma defs) (NS builtinNS (UN "assert_smaller"))
386386
cond [(fn == NS builtinNS (UN "assert_total"), pure [])
387-
-- #1782: this breaks totality!
388-
-- ,(caseFn fn,
389-
-- do mps <- getCasePats defs fn pats args
390-
-- case mps of
391-
-- Nothing => pure Prelude.Nil
392-
-- Just ps => do scs <- traverse (findInCase defs g) ps
393-
-- pure (concat scs))
387+
,(caseFn fn,
388+
do scs1 <- traverse (findSC defs env g pats) args
389+
mps <- getCasePats defs fn pats args
390+
scs2 <- traverse (findInCase defs g) $ fromMaybe [] mps
391+
pure (concat (scs1 ++ scs2)))
394392
]
395393
(do scs <- traverse (findSC defs env g pats) args
396394
pure ([MkSCCall fn

src/Libraries/Text/Lexer/Tokenizer.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ tokenise reject tokenizer line col acc str
121121
end = endFn tag
122122
beginTok'' = MkBounded (mapBegin beginTok') False (MkBounds line col line' col')
123123
(midToks, (reason, line'', col'', rest'')) =
124-
tokenise end middle line' col' [] rest
124+
assert_total $ tokenise end middle line' col' [] rest
125125
in case reason of
126126
(ComposeNotClosing _ _) => Left reason
127127
_ => let Just (endTok', lineEnd, colEnd, restEnd) =

src/Libraries/Text/PrettyPrint/Prettyprinter/SimpleDocTree.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ sdocToTreeParser (SLine i rest) = case sdocToTreeParser rest of
7171
sdocToTreeParser (SAnnPush ann rest) = case sdocToTreeParser rest of
7272
(tree, Nothing) => (Nothing, Nothing)
7373
(Just tree, Nothing) => (Just $ STAnn ann tree, Nothing)
74-
(Just tree, Just rest') => case sdocToTreeParser rest' of
74+
(Just tree, Just rest') => case sdocToTreeParser (assert_smaller rest rest') of
7575
(Just tree', rest'') => (Just $ STConcat [STAnn ann tree, tree'], rest'')
7676
(Nothing, rest'') => (Just $ STAnn ann tree, rest'')
77-
(Nothing, Just rest') => assert_total $ sdocToTreeParser rest'
77+
(Nothing, Just rest') => sdocToTreeParser (assert_smaller rest rest')
7878
(Nothing, Nothing) => (Nothing, Nothing)
7979
sdocToTreeParser (SAnnPop rest) = (Nothing, Just rest)
8080

tests/idris2/total011/Issue1859-2.idr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%default total
2+
3+
tailRecId : (a -> Either a b) -> a -> b
4+
tailRecId f a = case f a of
5+
Left a2 => tailRecId f a2
6+
Right b => b
7+
8+
iamvoid : Void
9+
iamvoid = tailRecId go ()
10+
where go : () -> Either () Void
11+
go () = Left ()

tests/idris2/total011/Issue1859.idr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
%default total
2+
3+
fix : Void
4+
fix = case the (Either () Void) (Left ()) of
5+
Left () => fix
6+
Right p => absurd p

tests/idris2/total011/expected

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,31 @@ Issue1460:3:1--3:43
1414
3 | nonproductive : Stream a -> (Stream a, ())
1515
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

17+
1/1: Building Issue1859 (Issue1859.idr)
18+
Error: fix is not total, possibly not terminating due to recursive path Main.fix -> Main.fix
19+
20+
Issue1859:3:1--3:11
21+
1 | %default total
22+
2 |
23+
3 | fix : Void
24+
^^^^^^^^^^
25+
26+
1/1: Building Issue1859-2 (Issue1859-2.idr)
27+
Error: iamvoid is not total, possibly not terminating due to recursive path Main.iamvoid -> Main.tailRecId -> Main.tailRecId
28+
29+
Issue1859-2:8:1--8:15
30+
4 | tailRecId f a = case f a of
31+
5 | Left a2 => tailRecId f a2
32+
6 | Right b => b
33+
7 |
34+
8 | iamvoid : Void
35+
^^^^^^^^^^^^^^
36+
37+
Error: tailRecId is not total, possibly not terminating due to recursive path Main.iamvoid -> Main.tailRecId -> Main.tailRecId
38+
39+
Issue1859-2:3:1--3:40
40+
1 | %default total
41+
2 |
42+
3 | tailRecId : (a -> Either a b) -> a -> b
43+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+

tests/idris2/total011/run

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ rm -rf build
22

33
$1 --no-color --console-width 0 Issue1782.idr --check
44
$1 --no-color --console-width 0 Issue1460.idr --check
5+
$1 --no-color --console-width 0 Issue1859.idr --check
6+
$1 --no-color --console-width 0 Issue1859-2.idr --check

0 commit comments

Comments
 (0)