Skip to content

Commit 20c8571

Browse files
authored
feat: unnecessary termination_by clauses cause warnings, not errors (#4809)
fixes #4804
1 parent 9f1eb47 commit 20c8571

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/Lean/Elab/PreDefinition/Main.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def checkTerminationByHints (preDefs : Array PreDefinition) : CoreM Unit := do
114114
if !structural && !preDefsWithout.isEmpty then
115115
let m := MessageData.andList (preDefsWithout.toList.map (m!"{·.declName}"))
116116
let doOrDoes := if preDefsWithout.size = 1 then "does" else "do"
117-
logErrorAt termBy.ref (m!"Incomplete set of `termination_by` annotations:\n"++
117+
logErrorAt termBy.ref (m!"incomplete set of `termination_by` annotations:\n"++
118118
m!"This function is mutually with {m}, which {doOrDoes} not have " ++
119119
m!"a `termination_by` clause.\n" ++
120120
m!"The present clause is ignored.")

src/Lean/Elab/PreDefinition/TerminationHint.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ structure TerminationHints where
5757

5858
def TerminationHints.none : TerminationHints := ⟨.missing, .none, .none, .none, 0
5959

60-
/-- Logs warnings when the `TerminationHints` are present. -/
60+
/-- Logs warnings when the `TerminationHints` are unexpectedly present. -/
6161
def TerminationHints.ensureNone (hints : TerminationHints) (reason : String) : CoreM Unit := do
6262
match hints.terminationBy??, hints.terminationBy?, hints.decreasingBy? with
6363
| .none, .none, .none => pure ()
6464
| .none, .none, .some dec_by =>
65-
logErrorAt dec_by.ref m!"unused `decreasing_by`, function is {reason}"
65+
logWarningAt dec_by.ref m!"unused `decreasing_by`, function is {reason}"
6666
| .some term_by?, .none, .none =>
67-
logErrorAt term_by? m!"unused `termination_by?`, function is {reason}"
67+
logWarningAt term_by? m!"unused `termination_by?`, function is {reason}"
6868
| .none, .some term_by, .none =>
69-
logErrorAt term_by.ref m!"unused `termination_by`, function is {reason}"
69+
logWarningAt term_by.ref m!"unused `termination_by`, function is {reason}"
7070
| _, _, _ =>
71-
logErrorAt hints.ref m!"unused termination hints, function is {reason}"
71+
logWarningAt hints.ref m!"unused termination hints, function is {reason}"
7272

7373
/-- True if any form of termination hint is present. -/
7474
def TerminationHints.isNotNone (hints : TerminationHints) : Bool :=

tests/lean/termination_by.lean.expected.out

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
termination_by.lean:9:2-9:18: error: unused `termination_by`, function is not recursive
2-
termination_by.lean:12:2-12:21: error: unused `decreasing_by`, function is not recursive
3-
termination_by.lean:15:2-16:21: error: unused termination hints, function is not recursive
4-
termination_by.lean:19:2-19:18: error: unused `termination_by`, function is partial
5-
termination_by.lean:22:2-22:21: error: unused `decreasing_by`, function is partial
6-
termination_by.lean:25:2-26:21: error: unused termination hints, function is partial
7-
termination_by.lean:29:0-29:16: error: unused `termination_by`, function is unsafe
8-
termination_by.lean:32:2-32:21: error: unused `decreasing_by`, function is unsafe
9-
termination_by.lean:35:2-36:21: error: unused termination hints, function is unsafe
10-
termination_by.lean:40:4-40:20: error: unused `termination_by`, function is not recursive
11-
termination_by.lean:44:4-44:20: error: unused `termination_by`, function is not recursive
12-
termination_by.lean:54:2-54:18: error: unused `termination_by`, function is not recursive
13-
termination_by.lean:62:2-62:23: error: Incomplete set of `termination_by` annotations:
1+
termination_by.lean:9:2-9:18: warning: unused `termination_by`, function is not recursive
2+
termination_by.lean:12:2-12:21: warning: unused `decreasing_by`, function is not recursive
3+
termination_by.lean:15:2-16:21: warning: unused termination hints, function is not recursive
4+
termination_by.lean:19:2-19:18: warning: unused `termination_by`, function is partial
5+
termination_by.lean:22:2-22:21: warning: unused `decreasing_by`, function is partial
6+
termination_by.lean:25:2-26:21: warning: unused termination hints, function is partial
7+
termination_by.lean:29:0-29:16: warning: unused `termination_by`, function is unsafe
8+
termination_by.lean:32:2-32:21: warning: unused `decreasing_by`, function is unsafe
9+
termination_by.lean:35:2-36:21: warning: unused termination hints, function is unsafe
10+
termination_by.lean:40:4-40:20: warning: unused `termination_by`, function is not recursive
11+
termination_by.lean:44:4-44:20: warning: unused `termination_by`, function is not recursive
12+
termination_by.lean:54:2-54:18: warning: unused `termination_by`, function is not recursive
13+
termination_by.lean:62:2-62:23: error: incomplete set of `termination_by` annotations:
1414
This function is mutually with isOdd, which does not have a `termination_by` clause.
1515
The present clause is ignored.
1616
Try this: termination_by x1 => x1
17-
termination_by.lean:79:2-79:27: error: Incomplete set of `termination_by` annotations:
17+
termination_by.lean:79:2-79:27: error: incomplete set of `termination_by` annotations:
1818
This function is mutually with Test.f, Test.h and Test.i, which do not have a `termination_by` clause.
1919
The present clause is ignored.
2020
termination_by.lean:101:2-101:27: error: Invalid `termination_by`; this function is mutually recursive with Test2.f, which is marked as `termination_by structural` so this one also needs to be marked `structural`.

0 commit comments

Comments
 (0)