Skip to content

Conversation

@kim-em
Copy link
Collaborator

@kim-em kim-em commented Nov 27, 2025

This PR fixes a panic in addChoice introduced by PR #11362.

PR #11362 added cleanup logic in merge that collapses choice values to top when all constructors of an inductive type are covered with all-top arguments. However, addChoice was not updated to handle merge returning top, causing a panic.

When addChoice merges two constructors with the same name, the result of merge is placed directly in the list. With the new cleanup logic, merge can return top, which then appears in the choice list. On subsequent iterations, addChoice tries to match top :: _ against v1@(ctor i1 _) :: cs and falls through to the panic.

This PR:

  1. Adds a case to addChoice to propagate top if it appears in the list
  2. Checks the result of merge and handles top appropriately
  3. Adds a check in cleanup to return top if any element is top

Closes #11393


🤖 Generated with Claude Code

PR leanprover#11362 added cleanup logic in `merge` that collapses `choice` values
to `top` when all constructors of an inductive type are covered with
all-`top` arguments. However, `addChoice` wasn't updated to handle
`merge` returning `top`, causing a panic.

When `addChoice` merges two constructors with the same name, the result
of `merge` is placed directly in the list. With the new cleanup logic,
`merge` can return `top`, which then appears in the choice list. On
subsequent iterations, `addChoice` tries to match `top :: _` against
`v1@(ctor i1 _) :: cs` and falls through to the panic.

This fix:
1. Adds a case to `addChoice` to propagate `top` if it appears in the list
2. Checks the result of `merge` and handles `top` appropriately
3. Adds a check in `cleanup` to return `top` if any element is `top`

Fixes leanprover#11393
@kim-em kim-em added the changelog-compiler Compiler, runtime, and FFI label Nov 27, 2025
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Nov 27, 2025
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 490d714486931629cad8163148c9e92a55ae4e63 --onto b0e6db322421ce368999f08870fd747e45242f86. You can force Mathlib CI using the force-mathlib-ci label. (2025-11-27 05:35:43)

@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 490d714486931629cad8163148c9e92a55ae4e63 --onto d3dda9f6d4428a906c096067ecb75e432afc4615. You can force reference manual CI using the force-manual-ci label. (2025-11-27 05:35:44)

@kim-em
Copy link
Collaborator Author

kim-em commented Nov 27, 2025

This problem seems to be gone again in nightly-2025-11-27. @hargoniX, I'll leave this for you to close, to make sure you know why the problem appear and disappeared!

@hargoniX hargoniX closed this Nov 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-compiler Compiler, runtime, and FFI toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ElimDeadBranches panic after PR #11362

4 participants