Repository navigation
Description
The termination_by? command suffix shows the inferred termination argument to the user and offers a “Try this” command to replace it. It works fine for non-mutual recursive function, but for mutual recursive functions, there is a problem.
Consider
mutual
def foo : Nat → Nat
| 0 => 0
| n+1 => bar n
termination_by? -- Try this: termination_by x1 => x1
def bar : Nat → Nat
| 0 => 0
| n+1 => foo n
end
If the user clicks on the Try this action, they get a broken file
mutual
def foo : Nat → Nat
| 0 => 0
| n+1 => bar n
termination_by x1 => x1
def bar : Nat → Nat -- Missing `termination_by`; this function is mutually
-- recursive with foo, which has a `termination_by` clause.
| 0 => 0
| n+1 => foo n
end
because (right now) either every or no function of a clique can have a termination_by annotation.
Possible ways forward:
-
Show the inferred termination measure for every function, and offer a code action that replaces
all of them at once.This requires extending the Try this functionality.
-
If some functions have a
termination_byand others don’t, ignore thetermination_by(with a warning), so that the user can writemutual def foo : Nat → Nat | 0 => 0 | n+1 => bar n termination_by x1 => x1 -- Warning: ignored until every function has one def bar : Nat → Nat | 0 => 0 | n+1 => foo n termination_by? endand still have GuessLex running and be able to click on
termination_by?. -
If some functions have a
termination_byand others don’t, do not complain, run GuessLex as usual, and afterwards check that the inferred measure matches the given one.So
termination_bycan be used to assert the inferred measure and document it, and only if all functions in a clique have one, one gets the benefit of not running GuessLex at all. -
If some functions have a
termination_byand others don’t, do not complain, and run GuessLex in a way that extends the given termination argument to the other functions. (I don’t think this is easily possible or worth it, just listing for completeness.)
So far nobody complained, so this isn’t very pressing.
Versions
4.8.0
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Activity
Ignore incomplete set of termination_by clauses
feat: termination_by structural (#4542)