Repository navigation
feat: add structured TraceResult to TraceData - #12698
Conversation
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
This PR adds `#defeq_abuse in`, a tactic/command combinator for diagnosing `backward.isDefEq.respectTransparency` failures. It runs the given tactic or command with the option both `true` and `false`, and when the strict setting fails, walks the trace tree to identify the specific `isDefEq` checks that are root causes. Reusable trace-tree analysis utilities are extracted into `Mathlib.Lean.MessageData.Trace`: - `TraceResult` / `traceResultOf` — structured access to the ✅/❌/💥 status encoding - `foldTraceNodes` — generic fold over `MessageData` trace trees - `stripTraceResultPrefix` / `dedupByString` — helpers for trace content comparison Companion lean4 PRs that will simplify this further: - leanprover/lean4#12698 — structured `TraceResult` field on `TraceData` - leanprover/lean4#12699 — `Meta.synthInstance.apply` trace class See https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency 🤖 Prepared with Claude Code Co-authored-by: Thomas R. Murrills <[email protected]>
…ity#35750) This PR adds `#defeq_abuse in`, a tactic/command combinator for diagnosing `backward.isDefEq.respectTransparency` failures. It runs the given tactic or command with the option both `true` and `false`, and when the strict setting fails, walks the trace tree to identify the specific `isDefEq` checks that are root causes. Reusable trace-tree analysis utilities are extracted into `Mathlib.Lean.MessageData.Trace`: - `TraceResult` / `traceResultOf` — structured access to the ✅/❌/💥 status encoding - `foldTraceNodes` — generic fold over `MessageData` trace trees - `stripTraceResultPrefix` / `dedupByString` — helpers for trace content comparison Companion lean4 PRs that will simplify this further: - leanprover/lean4#12698 — structured `TraceResult` field on `TraceData` - leanprover/lean4#12699 — `Meta.synthInstance.apply` trace class See https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency 🤖 Prepared with Claude Code Co-authored-by: Thomas R. Murrills <[email protected]>
|
Thanks @thorimur, very helpful comments. I've made the changes. |
|
@kim-em Great! (Though I'm guessing they're stuck on the other fork as before? :) ) |
Thanks for your patience... It's a bug in my worktree creation script, sometimes not setting tracking branches for PRs correctly, and then Claude being "helpful". I think I have my script right now, hopefully this won't keep happening. Commits now in the right place. |
thorimur
left a comment
There was a problem hiding this comment.
Looks good to me! (Minor cleanups suggested, one namespace fix)
I'm not 100% sure why Lean.SubExpr is changed in this PR (hmm, it has something to do with Except?) but it does also look good to me.
Adds a `result? : Option TraceResult` field to `TraceData`, so that `withTraceNode` and `withTraceNodeBefore` record structured success/failure information alongside the existing emoji in the rendered header. This allows metaprograms that walk trace trees to determine success or failure by checking `td.result?` instead of string-matching on emoji characters in the rendered `MessageData`. For `withTraceNodeBefore`, `result?` is derived from the emoji computed by `ExceptToEmoji`, correctly handling `Bool` (where `.ok false` = failure) and `Option` (where `.ok none` = failure). For `withTraceNode`, `result?` defaults to `.ok _ => success`, `.error _ => failure`. Callers needing different semantics can pass `result?` explicitly. Trace nodes not created by `withTraceNode`/`withTraceNodeBefore` (e.g. from `addTrace` or diagnostic formatting) get `result? := none`. Motivated by mathlib's `#defeq_abuse` diagnostic tactic (mathlib4#35750) which currently has to string-match on emoji to determine trace node outcomes. Co-Authored-By: Claude Opus 4.6 <[email protected]>
`withTraceNode` doesn't have access to `ExceptToEmoji`, so it can't distinguish `Except.ok none` (failure) from `Except.ok (some _)` (success). Defaulting to `none` is the honest choice; callers that need structured results can pass `result?` explicitly. `withTraceNodeBefore` is unaffected — it correctly derives from the emoji string via `ExceptToEmoji`. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…raceNodeBefore Both `withTraceNode` and `withTraceNodeBefore` now take a `mkResult? : Except ε α → Option TraceResult` callback instead of a fixed `result? : Option TraceResult`. This lets callers compute the structured result from the actual `Except` outcome. - `withTraceNode`: defaults to `fun _ => none` (callers opt in) - `withTraceNodeBefore`: defaults to inferring from `ExceptToEmoji` (success if emoji == checkEmoji, failure otherwise) This addresses the semantic mismatch where `Except.ok none` or `Except.ok false` would need to be reported as failure, not success. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The bomb emoji (💥) indicates an exception was thrown, which is semantically different from a normal failure (❌). Lumping them together as `.failure` loses this distinction. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This replaces the `ExceptToEmoji` typeclass with `ExceptToTraceResult`, making `TraceResult` the primary representation. `withTraceNodeBefore` now computes a `TraceResult` directly via the typeclass instead of deriving it from emoji string comparison. Adds `TraceResult.toEmoji` to convert back to emoji for display. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add `Except.toTraceResult`, `withTraceNode` auto-prepends emoji when `mkResult?` yields `some`, remove redundant `mkResult` param from `withTraceNodeBefore`, improve docstrings and examples. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Since withTraceNode now auto-prepends emoji via ExceptToTraceResult, remove all manual emoji embedding from ~31 callers across 25 source files. Remove the now-unused exceptEmoji, exceptBoolEmoji, exceptOptionEmoji helpers and custom emoji functions in AppBuilder and LibrarySearch. Update all test expected outputs to match. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
a04cf13 to
6cf80c5
Compare
…ity#35750) This PR adds `#defeq_abuse in`, a tactic/command combinator for diagnosing `backward.isDefEq.respectTransparency` failures. It runs the given tactic or command with the option both `true` and `false`, and when the strict setting fails, walks the trace tree to identify the specific `isDefEq` checks that are root causes. Reusable trace-tree analysis utilities are extracted into `Mathlib.Lean.MessageData.Trace`: - `TraceResult` / `traceResultOf` — structured access to the ✅/❌/💥 status encoding - `foldTraceNodes` — generic fold over `MessageData` trace trees - `stripTraceResultPrefix` / `dedupByString` — helpers for trace content comparison Companion lean4 PRs that will simplify this further: - leanprover/lean4#12698 — structured `TraceResult` field on `TraceData` - leanprover/lean4#12699 — `Meta.synthInstance.apply` trace class See https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency 🤖 Prepared with Claude Code Co-authored-by: Thomas R. Murrills <[email protected]>
This PR adds a `result? : Option TraceResult` field to `TraceData` and populates it in `withTraceNode` and `withTraceNodeBefore`, so that metaprograms walking trace trees can determine success/failure structurally instead of string-matching on emoji. `TraceResult` has three cases: `.success` (checkEmoji), `.failure` (crossEmoji), and `.error` (bombEmoji, exception thrown). An `ExceptToTraceResult` typeclass converts `Except` results to `TraceResult` directly, with instances for `Bool` and `Option`. `TraceResult.toEmoji` converts back to emoji for display. This replaces the previous `ExceptToEmoji` typeclass — `TraceResult` is now the primary representation rather than being derived from emoji strings. `withTraceNodeBefore` (used by `isDefEq`) uses `ExceptToTraceResult.toTraceResult` directly, correctly handling `Bool` (`.ok false` = failure) and `Option` (`.ok none` = failure), with `Except.error` mapping to `.error`. For `withTraceNode`, `result?` defaults to `none`. Callers can pass `mkResult?` to provide structured results; when set, the corresponding emoji is auto-prepended to the message. Motivated by mathlib's `#defeq_abuse` diagnostic tactic (leanprover-community/mathlib4#35750) which currently string-matches on emoji to determine trace node outcomes. See https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency 🤖 Prepared with Claude Code --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
…ity#35750) This PR adds `#defeq_abuse in`, a tactic/command combinator for diagnosing `backward.isDefEq.respectTransparency` failures. It runs the given tactic or command with the option both `true` and `false`, and when the strict setting fails, walks the trace tree to identify the specific `isDefEq` checks that are root causes. Reusable trace-tree analysis utilities are extracted into `Mathlib.Lean.MessageData.Trace`: - `TraceResult` / `traceResultOf` — structured access to the ✅/❌/💥 status encoding - `foldTraceNodes` — generic fold over `MessageData` trace trees - `stripTraceResultPrefix` / `dedupByString` — helpers for trace content comparison Companion lean4 PRs that will simplify this further: - leanprover/lean4#12698 — structured `TraceResult` field on `TraceData` - leanprover/lean4#12699 — `Meta.synthInstance.apply` trace class See https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency 🤖 Prepared with Claude Code Co-authored-by: Thomas R. Murrills <[email protected]>
withTraceNode and withTraceNodeBefore previously baked TraceResult.toEmoji into the header MessageData. Now that TraceData.result? exists (#12698), the emoji is redundant in the stored header. Move it to the rendering layer (formatAux, InteractiveDiagnostic) so programmatic consumers get clean headers without string manipulation. Rendered output is unchanged. Closes #13069 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
withTraceNode and withTraceNodeBefore previously baked TraceResult.toEmoji into the header MessageData. Now that TraceData.result? exists (#12698), the emoji is redundant in the stored header. Move it to the rendering layer (formatAux, InteractiveDiagnostic) so programmatic consumers get clean headers without string manipulation. Rendered output is unchanged. Closes #13069 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
`exceptBoolEmoji` was removed when `TraceResult` replaced `ExceptToEmoji` (#12698); `withTraceNode` now prefixes the emoji itself, so the header message just drops it. `DiscrTree.values` moved to `Lean.Meta.DiscrTree.Util` in the `DiscrTree` refactor (#11875), which `Lean.Meta.Tactic.Simp.SimpTheorems` no longer pulls in, so import it directly. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WGQ4cXuC9bBbZQ3psYLZUA
This PR adds a
result? : Option TraceResultfield toTraceDataand populates it inwithTraceNodeandwithTraceNodeBefore, so that metaprograms walking trace trees can determine success/failure structurally instead of string-matching on emoji.TraceResulthas three cases:.success(checkEmoji),.failure(crossEmoji), and.error(bombEmoji, exception thrown). AnExceptToTraceResulttypeclass convertsExceptresults toTraceResultdirectly, with instances forBoolandOption.TraceResult.toEmojiconverts back to emoji for display. This replaces the previousExceptToEmojitypeclass —TraceResultis now the primary representation rather than being derived from emoji strings.withTraceNodeBefore(used byisDefEq) usesExceptToTraceResult.toTraceResultdirectly, correctly handlingBool(.ok false= failure) andOption(.ok none= failure), withExcept.errormapping to.error.For
withTraceNode,result?defaults tonone. Callers can passmkResult?to provide structured results; when set, the corresponding emoji is auto-prepended to the message.Motivated by mathlib's
#defeq_abusediagnostic tactic (leanprover-community/mathlib4#35750) which currently string-matches on emoji to determine trace node outcomes. See https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency🤖 Prepared with Claude Code