@@ -3892,6 +3892,9 @@ function expand_struct_def(ctx, ex, docs)
3892
3892
min_initialized = minimum ((_constructor_min_initalized (e) for e in inner_defs),
3893
3893
init= length (field_names))
3894
3894
newtype_var = ssavar (ctx, ex, " struct_type" )
3895
+ hasprev = ssavar (ctx, ex, " hasprev" )
3896
+ prev = ssavar (ctx, ex, " prev" )
3897
+ newdef = ssavar (ctx, ex, " newdef" )
3895
3898
layer = new_scope_layer (ctx, struct_name)
3896
3899
global_struct_name = adopt_scope (struct_name, layer)
3897
3900
if ! isempty (typevar_names)
@@ -3954,9 +3957,9 @@ function expand_struct_def(ctx, ex, docs)
3954
3957
# See https://github.com/JuliaLang/julia/pull/36121
3955
3958
@ast ctx ex [K " block"
3956
3959
[K " assert" " toplevel_only" :: K"Symbol" [K " inert" ex] ]
3960
+ [K " global" global_struct_name]
3957
3961
[K " scope_block" (scope_type= :hard )
3958
3962
[K " block"
3959
- [K " global" global_struct_name]
3960
3963
[K " local" struct_name]
3961
3964
[K " always_defined" struct_name]
3962
3965
typevar_stmts...
@@ -3975,40 +3978,37 @@ function expand_struct_def(ctx, ex, docs)
3975
3978
]
3976
3979
[K " =" struct_name newtype_var]
3977
3980
[K " call" (supertype) " _setsuper!" :: K"core" newtype_var supertype]
3978
- [K " if"
3979
- [K " call" " isdefinedglobal" :: K"core"
3980
- ctx. mod:: K"Value"
3981
- struct_name=> K " Symbol"
3982
- false :: K"Bool" ]
3983
- [K " if"
3984
- [K " call" " _equiv_typedef" :: K"core" global_struct_name newtype_var]
3985
- [K " block"
3986
- # If this is compatible with an old definition, use
3987
- # the existing type object and throw away the new
3988
- # type
3989
- [K " =" struct_name global_struct_name]
3990
- if ! isempty (typevar_names)
3991
- # And resassign the typevar_names - these may be
3992
- # referenced in the definition of the field
3993
- # types below
3994
- [K " ="
3995
- [K " tuple" typevar_names... ]
3996
- prev_typevars
3997
- ]
3998
- end
3999
- ]
3981
+ [K " =" hasprev
3982
+ [K " &&" [K " call" " isdefinedglobal" :: K"core"
3983
+ ctx. mod:: K"Value"
3984
+ struct_name=> K " Symbol"
3985
+ false :: K"Bool" ]
3986
+ [K " call" " _equiv_typedef" :: K"core" global_struct_name newtype_var]
3987
+ ]]
3988
+ [K " =" prev [K " if" hasprev global_struct_name false :: K"Bool" ]]
3989
+ [K " if" hasprev
3990
+ [K " block"
3991
+ # if this is compatible with an old definition, use the old parameters, but the
3992
+ # new object. This will fail to capture recursive cases, but the call to typebody!
3993
+ # below is permitted to choose either type definition to put into the binding table
3994
+ if ! isempty (typevar_names)
3995
+ # And resassign the typevar_names - these may be
3996
+ # referenced in the definition of the field
3997
+ # types below
3998
+ [K " =" [K " tuple" typevar_names... ] prev_typevars]
3999
+ end
4000
4000
]
4001
4001
]
4002
- [K "call " (type_body)
4003
- " _typebody! " :: K"core"
4004
- # TODO : if there is a previous compatible definition, re-use params. See #57253
4005
- false :: K"Bool"
4006
- newtype_var
4007
- [K " call" " svec" :: K"core" insert_struct_shim (ctx, field_types, struct_name)... ]
4008
- ]
4002
+ [K "= " newdef
4003
+ [ K " call " (type_body)
4004
+ " _typebody! " :: K"core"
4005
+ prev
4006
+ newtype_var
4007
+ [K " call" " svec" :: K"core" insert_struct_shim (ctx, field_types, struct_name)... ]
4008
+ ] ]
4009
4009
[K " constdecl"
4010
4010
global_struct_name
4011
- newtype_var
4011
+ newdef
4012
4012
]
4013
4013
[K " latestworld" ]
4014
4014
# Default constructors
0 commit comments