Skip to content

Commit

Permalink
Adjust to upcoming base Julia change
Browse files Browse the repository at this point in the history
This adjusts the `@system` macro to be compatible with
JuliaLang/julia#56497, which
re-orders the point at which a type is published into
the bindings table until after it is complete. This
package was (uniquely among all julia packages) relying
on the binding existing during field definition (via
a call to `typefor`).

Unfortunately, there isn't really a great place to define
as the system (currently) does not gurantee an order of
the evaluation of field types with respect to other global
statements inside the struct evaluation. The only place
that satiesfies the criteria that
a) incomplete struct is avilable
b) it is evaluated before any field types
is the supertype declaration, so this PR shoves the definition
of `typefor` there.

This works both before and after the change, although
it is quite messy. In the future, there may be a way
to forward declare an incomplete type, but for the time
being, this is the best I could come up with.
  • Loading branch information
Keno committed Nov 9, 2024
1 parent c03f1c9 commit c3985d1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ end

genstate(v::VarInfo) = begin
name = Meta.quot(v.name)
alias = Meta.quot(v.alias)
alias = Meta.quot(v.alias)
value = istag(v, :extern) ? genextern(v, gendefault(v)) : gendefault(v)
stargs = [:($(esc(k))=$v) for (k, v) in filterconstructortags(v)]
@q $C.$(v.state)(; _name=$name, _alias=$alias, _value=$value, $(stargs...))
Expand Down Expand Up @@ -459,9 +459,14 @@ genstruct(name, type, infos, consts, substs, incl, scope) = begin
system = quote
Core.@__doc__ abstract type $S <: $T end
$S(; kw...) = $_S(; kw...)
$C.typefor(::Type{<:$S}) = $_S
let $(constpatches...)
Core.@__doc__ mutable struct $_S <: $S
# HACK: We want to define `typefor` before the type is fully defined
# because it may be used in the `fields`. Because of the order that
# struct definitions happen to get evaluated in, type supertype definition
# is the only place where we have access to the incomplete $_S before evaluating
# the fields. The extra let is required to due a lowering bug
# (https://github.com/JuliaLang/julia/issues/56510).
Core.@__doc__ mutable struct $_S <: ((let $_S=$_S; ($C.typefor(::Type{<:$S}) = $_S); end); $S)
$(fields...)
function $_S(; __kwargs__...)
$predecl
Expand Down

0 comments on commit c3985d1

Please sign in to comment.