Repository navigation
Use Type{T} self-types for rules on types on Julia 1.14 - #714
Merged
Merged
Conversation
On Julia 1.14, `Core.Typeof(T)` returns `Core.TypeEgal{T}` for a type `T`,
making macro-generated rules ambiguous with hand-written `::Type{T}` rules.
Fixes #713
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devmotion
force-pushed
the
dmw/typeegal-selftype
branch
from
October 15, 2026 09:21
5aed1d8 to
0ee77b4
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #714 +/- ##
=======================================
Coverage 93.38% 93.39%
=======================================
Files 15 15
Lines 998 999 +1
=======================================
+ Hits 932 933 +1
Misses 66 66 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- `ProjectTo(::Symmetric)` returns a union of pointer-ful types, which is only returned unboxed since JuliaLang/julia#55045 (1.14.0-DEV.1348). Use `broken = VERSION < v"1.14.0-DEV.1348"` instead of the incorrect `VERSION > v"1.13"` cutoff. - Raise the StaticArrays test compat to 1.9.8: older versions import `require_one_based_indexing` from StaticArraysCore, which was removed in StaticArraysCore 1.4.4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #713.
On Julia 1.14,
Core.Typeof(T)returnsCore.TypeEgal{T}for a typeT(JuliaLang/julia#62001). The rule macros use it for the function argument, so@non_differentiable/@scalar_rule/@opt_outrules on types became ambiguous with hand-written, more specific::Type{T}rules. One example is@non_differentiable Array(::AbstractArray{Bool})vsrrule(::Type{Array}, ::HermOrSym)in ChainRules.jl.This PR replaces
Core.Typeofwith_selftype(@nospecialize(x)) = isa(x, Type) ? Type{x} : typeof(x). That is the definition ofCore.Typeofup to Julia 1.13 and ofCore.TypeEqOf, which lowering uses for method self-types on 1.14 (JuliaLang/julia#62287). Behaviour on Julia < 1.14 is unchanged.I added a regression test to
test/rule_definition_tools.jl. With ChainRulesCore 1.26.1 on 1.14.0-DEV.3529, the new test errors withMethodError: rrule(::Core.TypeEgal{NonDiffTypeExample}, ::Float64) is ambiguous. With this PR, the full test suite passes there.On Julia 1.13.1 locally, one allocation test (
projection.jl:462,ProjectTo(::Symmetric)) fails with 32 bytes allocated. It's unrelated to this change, and CI onmainlast ran before 1.13 was released.Docs: I removed the "check which to use with
Core.Typeof" tip fromwriting_good_rules.md, because on 1.14 it showsCore.TypeEgal{Bar}, the very signature that causes this issue. The@non_differentiableexpansion example inrule_definition_tools.mdnow shows the defined self-type::typeof(*).Version bumped to 1.26.2.
🤖 Generated with Claude Code