`simpDiscrCtor?` is broken in the presence of non-type parameters
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
The compiler fails to identify constructor applications as equal to the applications from a cases when the constructor application contains "relevant" parameters (i.e. not a type former or proof).
Context
Writing algorithms on sorted assoc lists.
Steps to Reproduce
inductive MyType (α : Type) (f : α → α → α) where
| none
| some (x : α)
set_option trace.Compiler.result true in
def MyType.merge {f : α → α → α} :
MyType α f → MyType α f → MyType α f
| .none, x => x
| x, .none => x
| .some a, .some b => .some (f a b)
Expected behavior:
In the resulting compiled code, the some _, none branch simply returns the left value and does not perform any allocations.
Actual behavior:
The some _, none branch compiles to a constructor application guarded behind a shared RC check.
Versions
Lean 4.36.0-nightly-2026-09-16
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 by running the minimal MyType.merge example with trace.Compiler.result enabled and compare the generated code for the some _, none branch. Investigate the compiler path handling constructor applications and cases with relevant parameters; done means the branch returns the existing left value without the unnecessary allocation or shared RC check.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100