@@ -3892,6 +3892,9 @@ function expand_struct_def(ctx, ex, docs)
38923892 min_initialized = minimum ((_constructor_min_initalized (e) for e in inner_defs),
38933893 init= length (field_names))
38943894 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" )
38953898 layer = new_scope_layer (ctx, struct_name)
38963899 global_struct_name = adopt_scope (struct_name, layer)
38973900 if ! isempty (typevar_names)
@@ -3954,9 +3957,9 @@ function expand_struct_def(ctx, ex, docs)
39543957 # See https://github.com/JuliaLang/julia/pull/36121
39553958 @ast ctx ex [K " block"
39563959 [K " assert" " toplevel_only" :: K"Symbol" [K " inert" ex] ]
3960+ [K " global" global_struct_name]
39573961 [K " scope_block" (scope_type= :hard )
39583962 [K " block"
3959- [K " global" global_struct_name]
39603963 [K " local" struct_name]
39613964 [K " always_defined" struct_name]
39623965 typevar_stmts...
@@ -3975,40 +3978,37 @@ function expand_struct_def(ctx, ex, docs)
39753978 ]
39763979 [K " =" struct_name newtype_var]
39773980 [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
40004000 ]
40014001 ]
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+ ] ]
40094009 [K " constdecl"
40104010 global_struct_name
4011- newtype_var
4011+ newdef
40124012 ]
40134013 [K " latestworld" ]
40144014 # Default constructors
0 commit comments