lean4-htt/doc/examples
Sebastian Ullrich 88b746dd48 feat: unfold and rewrap instances in inferInstanceAs and deriving
This PR adjusts the results of `inferInstanceAs` and the `def` `deriving` handler to conform to recently strengthened restrictions on reducibility. This change ensures that when deriving or inferring an instance for a semireducible type definition, the definition's RHS is not leaked when the instance is reduced at lower than semireducible transparency.

More specifically, given the "source type" and "target type" (the given and expected type for `inferInstanceAs`, the right-hand side and applied left-hand side of the `def` for `deriving`), we synthesize an instance for the source type and then unfold and rewrap its components (fields, nested instances) as necessary to make them compatible with the target type. The individual steps are represented by the following options, which all default to enabled and can be disabled to help with porting:
- `backward.inferInstanceAs.wrap`: master switch for instance adjustment in both `inferInstanceAs` and the default `deriving` handler
- `backward.inferInstanceAs.wrap.reuseSubInstances`: reuse existing instances for the target type for sub-instance fields to avoid non-defeq instance diamonds
- `backward.inferInstanceAs.wrap.instances`: wrap non-reducible instances in auxiliary definitions
- `backward.inferInstanceAs.wrap.data`: wrap data fields in auxiliary definitions (proof fields are always wrapped)

This PR is an extension and rewrite of prior work in Mathlib: https://github.com/leanprover-community/mathlib4/pull/36420

Last(?) part of fix for #9077

🤖 Prepared with Claude Code

# Breaking changes

Proofs that relied on the prior "defeq abuse" of these instance or that depended on their specific structure may need adjustments. As `inferInstanceAs A` now needs to know the source and target types exactly before it can continue, it cannot be used anymore as a synonym for `(inferInstance : A)`, use the latter instead when source and target type are identical.
2026-03-22 13:25:46 +01:00
..
Certora2022 feat: improve @[deprecated] attr (#3968) 2024-04-23 17:00:32 +00:00
compiler chore: improve how test suite interacts with stages (#12913) 2026-03-16 15:20:03 +00:00
ICERM2022 feat: replace List.lt with List.Lex (#6379) 2024-12-15 08:22:39 +00:00
IJCAR2026 doc: add IJCAR 2026 grind paper examples (#12462) 2026-02-13 04:02:11 +00:00
NFM2022 feat: improve @[deprecated] attr (#3968) 2024-04-23 17:00:32 +00:00
.gitignore chore: migrate more tests to new test suite (#12809) 2026-03-06 16:52:01 +00:00
bintree.lean chore: eliminate uses of intros x y z (#9983) 2025-08-19 06:09:13 +00:00
bintree.lean.out.expected chore: migrate more tests to new test suite (#12809) 2026-03-06 16:52:01 +00:00
deBruijn.lean chore: fix spelling mistakes in examples (doc/examples/) (#5434) 2024-09-23 21:44:55 +00:00
interp.lean feat: upstream definition of Vector from Batteries (#6197) 2024-11-24 23:01:32 +00:00
interp.lean.out.expected feat: unfold and rewrap instances in inferInstanceAs and deriving 2026-03-22 13:25:46 +01:00
palindromes.lean feat: String.toList_map (#11021) 2025-11-01 13:54:39 +00:00
palindromes.lean.out.expected chore: migrate more tests to new test suite (#12809) 2026-03-06 16:52:01 +00:00
phoas.lean chore: fix spelling mistakes in examples (doc/examples/) (#5434) 2024-09-23 21:44:55 +00:00
phoas.lean.out.expected chore: migrate more tests to new test suite (#12809) 2026-03-06 16:52:01 +00:00
README.md chore: remove old documentation site (#7974) 2025-05-14 14:31:33 +00:00
run_test.sh chore: check test output before exit code in piles (#12947) 2026-03-17 16:34:21 +00:00
tc.lean fix: remove obsolete sentence in doc-string (#6185) 2024-11-23 07:56:31 +00:00
widgets.lean chore: fix spelling mistakes in examples (doc/examples/) (#5434) 2024-09-23 21:44:55 +00:00

These examples are checked in Lean's CI to ensure that they continue to work. They are included in the documentation section of the Lean website via a script that copies the latest version, in order to ensure that the website tracks Lean releases rather than master.