experiment: rm_set_option.py after greedily deploying #35950's inferInstanceAs%#36573
experiment: rm_set_option.py after greedily deploying #35950's inferInstanceAs%#36573
rm_set_option.py after greedily deploying #35950's inferInstanceAs%#36573Conversation
…ed instances `inferInstanceAs%` is a drop-in replacement for `inferInstanceAs` that prevents "type leakage" in synthesized instances. When `inferInstanceAs` synthesizes an instance for a type alias, the resulting expression may contain lambda binder domains referring to unfolded forms of the carrier type rather than the declared alias. This is invisible at `default` transparency but causes `isDefEq` failures at `reducibleAndInstances` transparency — which is the level used by `grind`'s `checkInst`. The fix recursively normalizes the constructor tree: for each class-valued structure, it WHNFs to expose the constructor, patches the carrier type parameter via `isDefEq` matching, recursively processes instance-implicit fields, and replaces lambda binder domains in function fields. This fixes the `grind` failure in `FiniteResidueField` that was previously worked around with an `#adaptation_note` and manual proof. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Refactor the implementation: - Make `unfoldChain` iterative with built-in dedup and `skipHead` param - Extract `addUnfoldings` and `buildReplacements` from inline logic - Split `normalizeInstance` into `getCtorApp?`, `getFieldInfo`, and `normalizeCtorArgs` helpers (mutual block for recursion) Add deeper test hierarchy (TestInv → TestDivInvMonoid → TestField) reproducing the real grind failure pattern, with declarative examples showing defeq at default transparency but not at `instances` transparency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove extra leading spaces on continuation lines of docstrings to match mathlib convention (#8). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ard getAppFn Throw an error when source and expected types fail to unify, and check that the class heads match before comparing arguments pairwise (#1). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All code is `meta`, so `partial` is fine for termination. Remove the unnecessary fuel parameter from `normalizeCtorArgs` and `normalizeInstance`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…add option When `inferInstanceAs%` patches an instance, it now tries to synthesize sub-instances for the target carrier type. If a synthesized sub-instance is not defeq to the patched version at `reducibleAndInstances` transparency, a warning is emitted suggesting the user define it separately. The warning can be disabled with `set_option inferInstanceAsPercent.leakySubInstWarning false`. Also regenerates import files via `lake exe mk_all`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a sub-instance was already defined with `inferInstanceAs%`, the leaky sub-instance warning would still fire because the synthesized sub-instance differed from the freshly-patched version (different construction paths in the hierarchy). Now we check if `synthInst` is itself clean (normalizing it doesn't change it) before warning. Also improves the warning message to explain what's happening and how to suppress it. Reported by Sébastien Gouëzel. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…abbreviations
The head comparison used structural equality (`==`) on `Expr`, which
fails when the same constant appears at different universe levels
(e.g. `DecidableEq.{u+1}` vs `DecidableEq.{max 1 (u+1)}`) or when
source and expected types use different abbreviations (e.g.
`DecidableLT` vs `DecidableRel`).
Replace the strict check with `alignHeads`, which:
- compares only constant names (ignoring universe levels)
- tries unfolding both types to find a common head constant
Reported by Sébastien Gouëzel.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously, `normalizeCtorArgs` called `trySynthInstance` for every instance-implicit field at every level of the class hierarchy. For deep hierarchies like `Field`, this cascaded into ~30-40 expensive synthesis calls. Now only the top-level constructor's fields trigger synthesis (`trySynth = true`). Recursive normalization uses purely mechanical patching (`trySynth = false`): WHNF + carrier replacement + lambda domain patching, with no synthesis overhead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove `addUnfoldings` and simplify `buildReplacements` to just collect differing arg pairs — `matchesAnyDefeq` already uses `isDefEq` at `default` transparency, so explicit unfold chains are redundant. Rename `getCtorApp?` to `constructorAppWithUniverses?` referencing Lean core's `constructorApp?`. Extract `processInstFieldWithSynth` from the deeply nested trySynth logic in `normalizeCtorArgs`, and flatten the field loop with `continue`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR summary 95b694b853Import changes exceeding 2%
Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
| Current number | Change | Type |
|---|---|---|
| 127 | -1 | adaptation notes |
| 9399 | -769 | backward.isDefEq |
Current commit c0a1d99809
Reference commit 95b694b853
You can run this locally as
./scripts/reporting/technical-debt-metrics.sh pr_summary
- The
relativevalue is the weighted sum of the differences with weight given by the inverse of the current value of the statistic. - The
absolutevalue is therelativevalue divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
🚨 PR Title Needs FormattingPlease update the title to match our commit style conventions. Errors from script: Details on the required title formatThe title should fit the following format:
|
|
This pull request has conflicts, please merge |
Removes 769
set_option backwards.