Skip to content

compat: Support the TypeEq type-system refactor (JuliaLang/julia#61915)#11

Open
Keno wants to merge 1 commit into
Taaitaaiger:mainfrom
KenoAIStaging:kf/typeeq-compat
Open

compat: Support the TypeEq type-system refactor (JuliaLang/julia#61915)#11
Keno wants to merge 1 commit into
Taaitaaiger:mainfrom
KenoAIStaging:kf/typeeq-compat

Conversation

@Keno

@Keno Keno commented Jun 4, 2026

Copy link
Copy Markdown

[This PR is partly a heads up with a Claude-suggested change - please check carefully and further refinements may be required]

Under the TypeEq type-system refactor, typeof(Type{T}) is TypeEq rather than DataType. As a consequence Type{T} is no longer isa DataType, so it can neither satisfy a ::DataType return annotation (the implicit convert(DataType, Type{T}) throws a MethodError) nor be used as a key in an IdDict{DataType,Layout}.

Reflect.basetype(Core.Type) walks Core.Type to its innermost body Type{T}, which made insertbuiltins! throw the moment any layout was reflected. Loosen the partialtype/basetype return annotations to ::Type, short-circuit basetype for Base.isType bodies (whose .name access is also deprecated), guard the abstract Type builtin registration so a non-DataType key is not inserted, and route Type{T}-typed struct fields to a WeakValue directly via Base.isType (previously handled through the fieldtype isa DataType branch). Behavior on released Julia versions is unchanged.

This change was made with the assistance of generative AI (Claude Code).

Under the TypeEq type-system refactor, `typeof(Type{T})` is `TypeEq` rather
than `DataType`. As a consequence `Type{T}` is no longer `isa DataType`, so it
can neither satisfy a `::DataType` return annotation (the implicit
`convert(DataType, Type{T})` throws a `MethodError`) nor be used as a key in an
`IdDict{DataType,Layout}`.

`Reflect.basetype(Core.Type)` walks `Core.Type` to its innermost body `Type{T}`,
which made `insertbuiltins!` throw the moment any layout was reflected. Loosen
the `partialtype`/`basetype` return annotations to `::Type`, short-circuit
`basetype` for `Base.isType` bodies (whose `.name` access is also deprecated),
guard the abstract `Type` builtin registration so a non-`DataType` key is not
inserted, and route `Type{T}`-typed struct fields to a `WeakValue` directly via
`Base.isType` (previously handled through the `fieldtype isa DataType` branch).
Behavior on released Julia versions is unchanged.

This change was made with the assistance of generative AI (Claude Code).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Taaitaaiger

Copy link
Copy Markdown
Owner

Thanks for the heads-up!

Comment thread src/Reflect.jl
return false
elseif !has_pointer_free_partialtype(ty, env)
return false
end

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elseif Base.isType(ty)
return false
end

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added branch in structfield was never reached by the tests, I wrote a quick test and noticed this one needs to be added as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants