From c0d496f5638bb5e52b7177f659e000f0b8b0b31d Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 1 Feb 2018 17:07:27 -0500 Subject: [PATCH] Make empty mutable struct distinct Fixes #17149 --- src/cgutils.cpp | 9 ++------- src/datatype.c | 2 +- test/core.jl | 10 +++++++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index b222e3eaad6ae..51eb820802343 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -2357,7 +2357,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg assert(jl_is_concrete_type(ty)); jl_datatype_t *sty = (jl_datatype_t*)ty; size_t nf = jl_datatype_nfields(sty); - if (nf > 0) { + if (nf > 0 || sty->mutabl) { if (jl_justbits(ty)) { Type *lt = julia_type_to_llvm(ty); 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 } return strctinfo; } - else if (!sty->mutabl) { + else { // 0 fields, ghost or bitstype if (jl_datatype_nbits(sty) == 0) 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 assert(!isboxed); return mark_julia_type(ctx, UndefValue::get(lt), false, ty); } - else { - // 0 fields, singleton - assert(sty->instance != NULL); - return mark_julia_const(sty->instance); - } } static Value *emit_exc_in_transit(jl_codectx_t &ctx) diff --git a/src/datatype.c b/src/datatype.c index 63addb75c706c..2b8b25cd18812 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -222,7 +222,7 @@ unsigned jl_special_vector_alignment(size_t nfields, jl_value_t *t) STATIC_INLINE int jl_is_datatype_make_singleton(jl_datatype_t *d) { return (!d->abstract && jl_datatype_size(d) == 0 && d != jl_sym_type && d->name != jl_array_typename && - d->uid != 0 && (d->types == jl_emptysvec || !d->mutabl)); + d->uid != 0 && !d->mutabl); } STATIC_INLINE void jl_allocate_singleton_instance(jl_datatype_t *st) diff --git a/test/core.jl b/test/core.jl index f3ed01c6fabf8..629731048614f 100644 --- a/test/core.jl +++ b/test/core.jl @@ -4530,7 +4530,7 @@ undefined_x16090 = (Int,) @test_throws TypeError f16090() # issue #12238 -mutable struct A12238{T} end +struct A12238{T} end mutable struct B12238{T,S} a::A12238{B12238{Int,S}} end @@ -5977,3 +5977,11 @@ void24363 = A24363(nothing) f24363(a) = a.x @test f24363(int24363) === 65535 @test f24363(void24363) === nothing + +# issue 17149 +mutable struct Foo17149 +end +@test Foo17149() !== Foo17149() +let a = Foo17149() + @test a === a +end