@@ -3883,6 +3883,9 @@ function expand_struct_def(ctx, ex, docs)
3883
3883
min_initialized = minimum ((_constructor_min_initalized (e) for e in inner_defs),
3884
3884
init= length (field_names))
3885
3885
newtype_var = ssavar (ctx, ex, " struct_type" )
3886
+ hasprev = ssavar (ctx, ex, " hasprev" )
3887
+ prev = ssavar (ctx, ex, " prev" )
3888
+ newdef = ssavar (ctx, ex, " newdef" )
3886
3889
layer = new_scope_layer (ctx, struct_name)
3887
3890
global_struct_name = adopt_scope (struct_name, layer)
3888
3891
if ! isempty (typevar_names)
@@ -3949,7 +3952,6 @@ function expand_struct_def(ctx, ex, docs)
3949
3952
# Needed for later constdecl to work, though plain global form may be removed soon.
3950
3953
[K " global" global_struct_name]
3951
3954
[K " block"
3952
- [K " global" global_struct_name]
3953
3955
[K " local" struct_name]
3954
3956
[K " always_defined" struct_name]
3955
3957
typevar_stmts...
@@ -3968,40 +3970,37 @@ function expand_struct_def(ctx, ex, docs)
3968
3970
]
3969
3971
[K " =" struct_name newtype_var]
3970
3972
[K " call" (supertype) " _setsuper!" :: K"core" newtype_var supertype]
3971
- [K " if"
3972
- [K " call" " isdefinedglobal" :: K"core"
3973
- ctx. mod:: K"Value"
3974
- struct_name=> K " Symbol"
3975
- false :: K"Bool" ]
3976
- [K " if"
3977
- [K " call" " _equiv_typedef" :: K"core" global_struct_name newtype_var]
3978
- [K " block"
3979
- # If this is compatible with an old definition, use
3980
- # the existing type object and throw away the new
3981
- # type
3982
- [K " =" struct_name global_struct_name]
3983
- if ! isempty (typevar_names)
3984
- # And resassign the typevar_names - these may be
3985
- # referenced in the definition of the field
3986
- # types below
3987
- [K " ="
3988
- [K " tuple" typevar_names... ]
3989
- prev_typevars
3990
- ]
3991
- end
3992
- ]
3973
+ [K " =" hasprev
3974
+ [K " &&" [K " call" " isdefinedglobal" :: K"core"
3975
+ ctx. mod:: K"Value"
3976
+ struct_name=> K " Symbol"
3977
+ false :: K"Bool" ]
3978
+ [K " call" " _equiv_typedef" :: K"core" global_struct_name newtype_var]
3979
+ ]]
3980
+ [K " =" prev [K " if" hasprev global_struct_name false :: K"Bool" ]]
3981
+ [K " if" hasprev
3982
+ [K " block"
3983
+ # if this is compatible with an old definition, use the old parameters, but the
3984
+ # new object. This will fail to capture recursive cases, but the call to typebody!
3985
+ # below is permitted to choose either type definition to put into the binding table
3986
+ if ! isempty (typevar_names)
3987
+ # And resassign the typevar_names - these may be
3988
+ # referenced in the definition of the field
3989
+ # types below
3990
+ [K " =" [K " tuple" typevar_names... ] prev_typevars]
3991
+ end
3993
3992
]
3994
3993
]
3995
- [K "call " (type_body)
3996
- " _typebody! " :: K"core"
3997
- # TODO : if there is a previous compatible definition, re-use params. See #57253
3998
- false :: K"Bool"
3999
- newtype_var
4000
- [K " call" " svec" :: K"core" insert_struct_shim (ctx, field_types, struct_name)... ]
4001
- ]
3994
+ [K "= " newdef
3995
+ [ K " call " (type_body)
3996
+ " _typebody! " :: K"core"
3997
+ prev
3998
+ newtype_var
3999
+ [K " call" " svec" :: K"core" insert_struct_shim (ctx, field_types, struct_name)... ]
4000
+ ] ]
4002
4001
[K " constdecl"
4003
4002
global_struct_name
4004
- newtype_var
4003
+ newdef
4005
4004
]
4006
4005
[K " latestworld" ]
4007
4006
# Default constructors
0 commit comments