fix(Tactic/Simps): skip @[defeq] inference for non-exposed definitions#32989
fix(Tactic/Simps): skip @[defeq] inference for non-exposed definitions#32989kim-em wants to merge 10 commits into
Conversation
PR summary b2d2bc6029Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
|
Now you don't need the srcDeclName field anymore right? |
|
The test file is not currently a module. So I don't see how it is testing what it says it is testing. |
Indeed, thanks. Fixed now. |
|
I copy-pasted the test file into the web editor, and it successfully build. Maybe you meant to add |
joneugster
left a comment
There was a problem hiding this comment.
Thank you, besides the adjustment to the test file mentioned this looks good!
6613418 to
141689c
Compare
|
🚀 Pull request has been placed on the maintainer queue by joneugster. |
Vierkantor
left a comment
There was a problem hiding this comment.
The fix itself looks good, some quibbles about implementation.
| let lhs : Expr := mkConst d.name <| d.levelParams.map Level.param | ||
| let todo := todo.eraseDups |>.map fun (proj, stx) ↦ (proj ++ "_", stx) | ||
| let mut cfg := cfg | ||
| let bodyExposed := (← getEnv).setExporting true |>.find? d.name |>.any (·.hasValue) |
There was a problem hiding this comment.
I was surprised that there is no easier way. This is the same check as in the delta-derive handler, so I don't expect any bug here. But it should really be something implemented in core.
There was a problem hiding this comment.
Agreed it would be nicer in core — left the check as-is for now since it mirrors Lean's delta-derive handler. Thanks.
There was a problem hiding this comment.
Actually, I've decided to just do this now, after realizing how much duplication we'd already produced in lean4.
Thanks for the suggestion.
|
(Also please note that the build is failing.) |
|
This pull request has conflicts, please merge |
|
@kim-em 🏓 would you have time to address the review above and fix the pipeline? |
When `@[simps]` is applied to a definition whose body is not exposed, the generated simp lemmas would trigger `@[defeq]` validation errors because `inferDefEqAttr` tries to validate the definitional equality in the exporting (public) scope where the definition body is not visible. This PR fixes the issue by checking whether the source definition's body is exposed before calling `inferDefEqAttr`. If not exposed, we skip the `@[defeq]` inference entirely, avoiding the validation error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Jovan Gerbscheid <56355248+JovanGerb@users.noreply.github.com>
Store the bodyExposed check as a Boolean in Config so it's only computed once instead of every time addProjectionSimp is called. This addresses the review comment on the PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move the test for @[simps] with non-exposed definition bodies to a separate file that uses `module`, so that definition bodies are properly non-exposed by default. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Jon Eugster <eugster.jon@gmail.com>
The `@[simps]` change skips `@[defeq]` for non-exposed definitions, which means `cat_disch` can no longer discharge this goal automatically. Provide an explicit proof using `ext` and `simp`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
338e61b to
177a992
Compare
…ig field Per Vierkantor's review: `bodyExposed` is internal state, not a user-facing option, so it does not belong in `Config` (a user setting it would be silently ignored). Remove the field and pass `bodyExposed` as an explicit parameter to `addProjection` and `addProjections`, computed once in `simpsTac`.
Vierkantor flagged that the `setExporting true |>.find? n |>.any (·.hasValue)` idiom should really live in core. leanprover/lean4#13868 adds `Environment.hasExposedBody` for exactly this. Leave the inline check in place for now (so the PR remains buildable on the current toolchain), and add a note next to it pointing at the follow-up refactor. Also note the other in-tree caller of the same idiom in `Mathlib/Tactic/Translate/Core.lean` even though it is strictly off-topic for this PR — it'll save a future grep.
|
This pull request has conflicts, please merge |
This PR makes
@[simps]check whether the source definition's body is exposed before callinginferDefEqAttr. When the body is not exposed, we skip the@[defeq]inference to avoid validation errors.Without this fix, using
@[simps]on a definition that is not@[expose]d produces an error like:The fix checks
(← getEnv).setExporting true |>.find? cfg.srcDeclName |>.any (·.hasValue)to determine if the definition body is visible in the public scope, and only callsinferDefEqAttrif it is.🤖 Prepared with Claude Code