Skip to content

Commit c0d496f

Browse files
committed
Make empty mutable struct distinct
Fixes #17149
1 parent 6fd5319 commit c0d496f

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/cgutils.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
23572357
assert(jl_is_concrete_type(ty));
23582358
jl_datatype_t *sty = (jl_datatype_t*)ty;
23592359
size_t nf = jl_datatype_nfields(sty);
2360-
if (nf > 0) {
2360+
if (nf > 0 || sty->mutabl) {
23612361
if (jl_justbits(ty)) {
23622362
Type *lt = julia_type_to_llvm(ty);
23632363
unsigned na = nargs < nf ? nargs : nf;
@@ -2475,7 +2475,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
24752475
}
24762476
return strctinfo;
24772477
}
2478-
else if (!sty->mutabl) {
2478+
else {
24792479
// 0 fields, ghost or bitstype
24802480
if (jl_datatype_nbits(sty) == 0)
24812481
return ghostValue(sty);
@@ -2484,11 +2484,6 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
24842484
assert(!isboxed);
24852485
return mark_julia_type(ctx, UndefValue::get(lt), false, ty);
24862486
}
2487-
else {
2488-
// 0 fields, singleton
2489-
assert(sty->instance != NULL);
2490-
return mark_julia_const(sty->instance);
2491-
}
24922487
}
24932488

24942489
static Value *emit_exc_in_transit(jl_codectx_t &ctx)

src/datatype.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ unsigned jl_special_vector_alignment(size_t nfields, jl_value_t *t)
222222
STATIC_INLINE int jl_is_datatype_make_singleton(jl_datatype_t *d)
223223
{
224224
return (!d->abstract && jl_datatype_size(d) == 0 && d != jl_sym_type && d->name != jl_array_typename &&
225-
d->uid != 0 && (d->types == jl_emptysvec || !d->mutabl));
225+
d->uid != 0 && !d->mutabl);
226226
}
227227

228228
STATIC_INLINE void jl_allocate_singleton_instance(jl_datatype_t *st)

test/core.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -4530,7 +4530,7 @@ undefined_x16090 = (Int,)
45304530
@test_throws TypeError f16090()
45314531

45324532
# issue #12238
4533-
mutable struct A12238{T} end
4533+
struct A12238{T} end
45344534
mutable struct B12238{T,S}
45354535
a::A12238{B12238{Int,S}}
45364536
end
@@ -5977,3 +5977,11 @@ void24363 = A24363(nothing)
59775977
f24363(a) = a.x
59785978
@test f24363(int24363) === 65535
59795979
@test f24363(void24363) === nothing
5980+
5981+
# issue 17149
5982+
mutable struct Foo17149
5983+
end
5984+
@test Foo17149() !== Foo17149()
5985+
let a = Foo17149()
5986+
@test a === a
5987+
end

0 commit comments

Comments
 (0)