fix: expose ctorIdx and per-constructor elims (#10301)

This PR exposes ctorIdx and per-constructor eliminators. Fixes #10299.
This commit is contained in:
Joachim Breitner 2025-09-08 12:04:19 +02:00 committed by GitHub
parent 4a73532fbe
commit 3e24d5dee8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 4 deletions

View file

@ -223,9 +223,11 @@ public def mkCtorElim (indName : Name) : MetaM Unit := do
let recInfo ← getConstInfo (mkRecName indName)
unless recInfo.levelParams.length > indVal.levelParams.length do return
mkCtorElimType indName
mkIndCtorElim indName
mkConstructorElim indName
-- Expose if indName is not private
withExporting (isExporting := ! isPrivateName indName) do
mkCtorElimType indName
mkIndCtorElim indName
mkConstructorElim indName
/--

View file

@ -33,7 +33,8 @@ returns the constructor index of the given value.
Does nothing if `T` does not eliminate into `Type` or if `T` is unsafe.
Assumes `T.casesOn` to be defined already.
-/
public def mkCtorIdx (indName : Name) : MetaM Unit := do
public def mkCtorIdx (indName : Name) : MetaM Unit :=
withExporting (isExporting := ! isPrivateName indName) do
prependError m!"failed to construct `T.ctorIdx` for `{.ofConstName indName}`:" do
unless genCtorIdx.get (← getOptions) do return
let declName := mkCtorIdxName indName

View file

@ -1,5 +1,7 @@
#include "util/options.h"
// please update
namespace lean {
options get_default_options() {
options opts;

View file

@ -0,0 +1,7 @@
module
/-! Tests that ctorIdx and constructor elims are exposed, i.e. reduce properly -/
example : Nat.ctorIdx 0 = 0 := rfl
example : Nat.succ.elim 1 rfl (fun n => n) = 0 := rfl