Every inductive type gets an `unsafe` declaration `T.ctorIdx._impl`
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #16324 by @vincentqb — closed without merging
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 39/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- compilers
Research direction
Read the changes associated with #15407 and #16253, then inspect how inductive declarations generate T.ctorIdx and T.ctorIdx._impl. The issue reports that #16324 is a closed, unmerged pull request, so check its changes and status first. Done means safe-only files can use inductive types with multiple constructors without receiving the unwanted unsafe implementation or implemented_by attribute.
Written by the indexing model from the issue text.
Description
Since v4.36.0-rc1, declaring an inductive type T with more than one constructor also adds unsafe def T.ctorIdx._impl and marks T.ctorIdx with @[implemented_by T.ctorIdx._impl]. Files with only safe code therefore contain unsafe code, and tools that refuse unsafe or @[implemented_by] in the code they check refuse every such type. The values are correct, and v4.35.0 added neither.
inductive T | a | b (n : Nat)
#print T.ctorIdx._impl
-- v4.35.0: Unknown constant `T.ctorIdx._impl`
-- v4.36.0-rc2, nightly-2026-11-06: unsafe protected def T.ctorIdx._impl : T → Nat := fun x => getObjTagNat x
Related:
- #9951 generates
T.ctorIdxfor every inductive type. - #15407 added
T.ctorIdx._implso thatT.ctorIdxreads the constructor tag. - #16253 made
withPtrEqsafe by letting the compiler substitute its unsafe implementation, which is howT.ctorIdxcan read the tag without_impl.
- Dominant language
- Lean
- Stars
- 10.3k
- Forks
- 1.1k
- Avg merge
- 19h 8m
- Merged PRs (30d)
- 421
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from leanprover/lean4
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16681 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
leanprover/lean4#16305 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
leanprover/lean4#16299 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16257 ·
Maintainers usually reply within 1 day
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
leanprover/lean4#15683 ·
Maintainers usually reply within 1 day
All issues in leanprover/lean4
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
swc-project/swc-next-issues#817 ·
-
Magma mode: div:=, mod:= and the other keyword assignments (join:=, meet:=, diff:=, sdiff:=, and:=, or:=, xor:=) are refusedPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
sagemathinc/sagebrush#1683 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
microts: a model local that every branch assigns raises unused_assignments in the generated RustOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
pocket-stack/pocketjs#756 ·
-
bot-triaged module: aotinductor module: compile-time module: inductor module: performance module: rocm oncall: export oncall: pt2 triaged
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day