LCNF ReduceArity should also work for non-fix unused arguments.
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
In code such as
set_option trace.Compiler.reduceArity true in
def simple (n p : Nat) : Nat :=
match n with
| 0 => 0
| n+1 => 1 + simple n (n + p)
the p argument is in fact unused. However, as p is used in a computation to compute the next p, the compiler does currently not detect this (it only operates on fixed unused arguments) and thus fails to remove the argument.
Context
Reported by @ineol
Steps to Reproduce
Expected behavior: The p argument should be removed (and then latter the computation eliminated by the simplifier.
Actual behavior: p is left untouched.
Versions
Lean 4.30.0-rc1
Target: x86_64-unknown-linux-gnu
Additional Information
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproducer in the issue and run it with trace.Compiler.reduceArity enabled to observe the current behavior. Then locate the compiler's ReduceArity implementation and determine how the non-fixed unused argument is handled. Done means the p argument is removed and the subsequent computation can be eliminated by simplification.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100