@@ -3883,6 +3883,9 @@ function expand_struct_def(ctx, ex, docs)
38833883 min_initialized = minimum ((_constructor_min_initalized (e) for e in inner_defs),
38843884 init= length (field_names))
38853885 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" )
38863889 layer = new_scope_layer (ctx, struct_name)
38873890 global_struct_name = adopt_scope (struct_name, layer)
38883891 if ! isempty (typevar_names)
@@ -3949,7 +3952,6 @@ function expand_struct_def(ctx, ex, docs)
39493952 # Needed for later constdecl to work, though plain global form may be removed soon.
39503953 [K " global" global_struct_name]
39513954 [K " block"
3952- [K " global" global_struct_name]
39533955 [K " local" struct_name]
39543956 [K " always_defined" struct_name]
39553957 typevar_stmts...
@@ -3968,40 +3970,37 @@ function expand_struct_def(ctx, ex, docs)
39683970 ]
39693971 [K " =" struct_name newtype_var]
39703972 [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
39933992 ]
39943993 ]
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+ ] ]
40024001 [K " constdecl"
40034002 global_struct_name
4004- newtype_var
4003+ newdef
40054004 ]
40064005 [K " latestworld" ]
40074006 # Default constructors
0 commit comments