Public print typediff#14
Open
adienes wants to merge 2 commits into
Open
Conversation
adienes
force-pushed
the
public_print_typediff
branch
from
June 7, 2026 17:42
0833cf3 to
862fb1a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
JuliaLang#61651 added machinery to highlight where two types differ — it's
what marks the mismatched arguments in
MethodError"Closest candidates" lists.That machinery is private to
errorshow.jl. This PR exposes its entry point asBase.Experimental.print_type_diff(next to the existingregister_error_hint/show_error_hintserror-UX APIs), so custom exceptiontypes can reuse the same highlighting in their own
showerrormethods.Prints
a, highlighting the subtrees that differ fromb.highlight(io, part)controls how a differing subtree renders, defaulting to red under
:colorand!Matched{part}otherwise:The internal recursion (
show_type_diff) andMethodError's use of it areunchanged except for two additions that make it reusable: a
markcallback forrendering a differing subtree, and an
a === bfast path so callers can diff eachelement of a signature without pre-checking equality.
Why
Custom errors that compare types currently re-implement this by hand. Motivating
case: Reactant.jl throws
MisMatchedThunkTypeErrorwhen a compiled function is called with arguments whosetypes differ from what it was compiled for. The two type lists are large and
nearly identical, so the actual mismatch is invisible in the current message.
Because those lists are already
Tuple{...}types, the entire hook reduces to twocalls:
In a real Lux/Reactant training loop, where a layer's state gains one extra
convnesting level per step, the full (~2 KB) argument tuple is printed with every
matching argument dimmed and only the differing subtree highlighted, so the
mismatch is the only thing that stands out. The matching arguments are abbreviated
as
...below for readability (nothing is actually elided — they print in full):(
!Matched{...}is the no-color rendering; under:colorthat subtree is shown inerror_colorinstead.)This pull request was written with the assistance of generative AI.
🤖 Generated with Claude Code