leanprover / leanprover/lean4

LCNF ReduceArity should also work for non-fix unused arguments.

Open
#13,355 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug code-generator P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.