Every inductive type gets an `unsafe` declaration `T.ctorIdx._impl`

Aperta
#16,323 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #16324 di @vincentqb — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
39/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.ctorIdx for every inductive type.
  • #15407 added T.ctorIdx._impl so that T.ctorIdx reads the constructor tag.
  • #16253 made withPtrEq safe by letting the compiler substitute its unsafe implementation, which is how T.ctorIdx can read the tag without _impl.
Lingua principale
Lean
Stelle
10.3k
Fork
1.1k
Merge medio
19h 8m
PR unite (30g)
421

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di leanprover/lean4

Tutte le issue di leanprover/lean4

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.