Skip to content

fix: mark delta-derived instances as meta when type is meta#13315

Open
kim-em wants to merge 3 commits intoleanprover:masterfrom
kim-em:issue-13313
Open

fix: mark delta-derived instances as meta when type is meta#13315
kim-em wants to merge 3 commits intoleanprover:masterfrom
kim-em:issue-13313

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Apr 8, 2026

This PR fixes processDefDeriving to propagate the meta attribute to
instances derived via delta deriving. Previously, deriving BEq inside a
public meta section for a definition would produce a non-meta instance,
causing the LCNF visibility checker to reject meta definitions that use ==.

The fix has two parts:

  1. Compute isMeta from the meta section scope and the type's meta status,
    and use it for both wrapInstance aux declarations and the main instance.
  2. Use addAndCompile (markMeta := isMeta) (from feat: add markMeta parameter to addAndCompile #13311) so the meta tag
    is set before compilation, matching how the normal command elaboration
    pipeline handles meta definitions.

Audited all other deriving handlers:

  • Handler-based deriving (BEq, Repr, Hashable, etc. for inductives) all use
    elabCommand within the withScope isMeta context, so they already
    correctly produce meta instances.

  • SizeOf auto-generated instances use addDecl with .abbrev hints (not
    compiled), so they need separate handling — deferred for now.

  • depends on: feat: add markMeta parameter to addAndCompile #13311

Closes #13313

🤖 Prepared with Claude Code

@kim-em kim-em added the changelog-language Language features and metaprograms label Apr 8, 2026
kim-em and others added 2 commits April 8, 2026 12:22
Downstream projects that dynamically create definitions derived from
`meta` declarations need to split `addAndCompile` into `addDecl` +
`markMeta` + `compileDecl` to propagate the meta marking before
compilation. Adding an optional `markMeta` flag avoids this boilerplate.

Also updates `ParserCompiler` to use the new parameter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The import is only used in the body of `addAndCompile`, not in its
public signature.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kim-em kim-em force-pushed the issue-13313 branch 2 times, most recently from daf1256 to 1d8b608 Compare April 8, 2026 02:29
This PR fixes `processDefDeriving` to propagate the `meta` attribute to
instances derived via delta deriving. Previously, `deriving BEq` inside a
`public meta section` for a definition would produce a non-meta instance,
causing the LCNF visibility checker to reject meta definitions that use `==`.

The fix has two parts:
1. Compute `isMeta` from the meta section scope and the type's meta status,
   and use it for both `wrapInstance` aux declarations and `addAndCompile`.
2. Use `addAndCompile (markMeta := isMeta)` (from leanprover#13311) so the meta tag
   is set before compilation, matching how the normal command elaboration
   pipeline handles meta definitions.

Closes leanprover#13313

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@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 Apr 8, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 30dca7b5458c58aa01e55993ee1b56ad9e1d0639 --onto 4f6bcc5adac8d6234a9e3def3675402cb89823c6. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-08 03:26:52)

@leanprover-bot
Copy link
Copy Markdown
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 30dca7b5458c58aa01e55993ee1b56ad9e1d0639 --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-08 03:26:53)

if isPrivateName declName then
instName := mkPrivateName env instName
let isMeta := (← read).declName?.any (isMarkedMeta (← getEnv))
let isMeta := (← read).isMetaSection || isMarkedMeta (← getEnv) declName
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't seem to match the PR title or be motivated in the test

Comment on lines +261 to +262
if isMeta then
modifyEnv (markMeta · instName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport releases/v4.30.0 changelog-language Language features and metaprograms 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.

deriving BEq inside public meta section does not produce a meta instance

3 participants