Skip to content

[downstream PR] Julia's instance check - #14536

Draft
datokrat wants to merge 16 commits into
leanprover:paul/nightly-2026-08-16-testfrom
datokrat:julias-instance-check
Draft

[downstream PR] Julia's instance check#14536
datokrat wants to merge 16 commits into
leanprover:paul/nightly-2026-08-16-testfrom
datokrat:julias-instance-check

Conversation

@datokrat

Copy link
Copy Markdown
Contributor

No description provided.

@datokrat datokrat added the downstream Request a downstream-lean4 adaptation PR. label Jul 24, 2026
@downstream-lean4

downstream-lean4 Bot commented Jul 24, 2026

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#16.

@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 Jul 24, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Jul 24, 2026

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-07-22 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-24 14:33:12)
  • 💥 Mathlib branch lean-pr-testing-14536 build failed against this PR. (2026-08-14 16:10:50) View Log
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-08-16 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-18 09:53:40)

@leanprover-bot

leanprover-bot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-07-22 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-07-24 14:33:13)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-08-14 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-08-14 16:01:19)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-08-16 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-08-18 09:53:42)

@datokrat

Copy link
Copy Markdown
Contributor Author

Note to self: No longer on downstream-green. Generally, I should migrate this to nightly-with-mathlib, so that I can get benchmarks.

@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Aug 14, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Aug 14, 2026
@datokrat datokrat removed the downstream Request a downstream-lean4 adaptation PR. label Aug 18, 2026
@datokrat
datokrat force-pushed the julias-instance-check branch from bb2ac20 to cc7922e Compare August 18, 2026 09:22
datokrat and others added 5 commits August 20, 2026 12:58
This PR makes `simp` and `dsimp` check, after they rewrite an argument of an application, the instance arguments whose types depend on that argument. When such an instance no longer has the expected type at `.instances` transparency, a replacement instance is synthesized and adopted if it is defeq to the old one at `.implicit` transparency; otherwise the rewrite of the argument is refused and a warning is logged. Previously the rewrite was applied unconditionally, leaving behind an instance argument that later lemmas mentioning that instance no longer match.

The check is controlled by `dsimp.resynthInstances` (default `true`), its warning by `dsimp.resynthInstances.warning` (default `true`). Adoptions and refusals are traced under `Meta.Tactic.simp.resynthInstances`.

Both entry points run the same fix-up: `simpApp` covers every argument-wise rebuild in `simp` (`simpAppUsingCongr`, `congrArgs`, and the `.fixed` branch of `tryAutoCongrTheorem?`), and standalone `dsimp` uses a new `postApp` hook of `transformWithCache`. The arguments an instance depends on carry forward dependencies, so `simp` can only ever have changed them definitionally; reverting or replacing them therefore keeps an already-built `Result.proof?` valid.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXiCjRqcz5MmCqu6YxoBFR
…nstance check

This PR adds the `@[lax_instance_defeq]` attribute, which exempts a class from the strict instance-argument discipline of `backward.isDefEq.respectTransparency.instances`: values assigned to instance metavariables of an exempt class are not required to match the metavariable's type at `.instances` transparency, and the instance-argument checks of `simp`/`dsimp` (`dsimp.resynthInstances`) and `linter.tacticCheckInstances` skip the class as well. Propositional classes are exempt by default, since proof irrelevance makes a stale instance argument harmless there.

The attribute is backed by a scoped environment extension, so it supports `local`/`scoped` use and can be applied retroactively to classes from other modules. The exemption is consulted in `isInstanceMVar` (which also feeds `spineMVarsAdmissible`), in `Simp.resynthInstanceArgs`, and in `Meta.findInstanceArgMismatch?`. The `backward.isDefEq.respectTransparency.instanceSearchTypes` path is deliberately not affected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXiCjRqcz5MmCqu6YxoBFR
The option's default is a property of the toolchain and governs every package built with it, including dependencies such as Batteries that do not receive Mathlib's `leanOptions`. This branch (worktree `julia-instance-mvars`) keeps the backward-compatible behavior by default; the sibling branch `instance-strict-dsimp` enables the check by default. The feature test sets the option explicitly so it passes under either default.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXiCjRqcz5MmCqu6YxoBFR
@datokrat
datokrat changed the base branch from master to paul/nightly-2026-08-16-test August 28, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN 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.

3 participants