Skip to content

Commit 5c288d9

Browse files
committed
More bpart changes
Changes from JuliaLang/julia#57253 (bpart: Fully switch to partitioned semantics). This fixes one failing test and realigns struct desugaring to match lisp for now. Also changed: the expected result of redefining a primitive type (now allowed).
1 parent f07980e commit 5c288d9

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

src/desugaring.jl

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/typedefs.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ end
255255
JuliaLowering.include_string(test_mod, "struct X36104; x::Int; end")
256256
@test fieldtypes(test_mod.X36104) == (Int,)
257257
JuliaLowering.include_string(test_mod, "primitive type P36104 8 end")
258-
@test_throws ErrorException("invalid redefinition of constant TestMod.P36104") #=
259-
=# JuliaLowering.include_string(test_mod, "primitive type P36104 16 end")
258+
JuliaLowering.include_string(test_mod, "const orig_P36104 = P36104")
259+
JuliaLowering.include_string(test_mod, "primitive type P36104 16 end")
260+
@test test_mod.P36104 !== test_mod.orig_P36104
260261

261262
# Struct with outer constructor where one typevar is constrained by the other
262263
# See https://github.com/JuliaLang/julia/issues/27269)

0 commit comments

Comments
 (0)