leanprover / leanprover/lean4

`simpDiscrCtor?` is broken in the presence of non-type parameters

Open
#15,200 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.