Skip to content

Commit

Permalink
Merge pull request #25854 from JuliaLang/kf/distinctmutable
Browse files Browse the repository at this point in the history
Make empty mutable struct distinct
  • Loading branch information
Keno authored Feb 2, 2018
2 parents d5a06e1 + c0d496f commit f7fe60b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 2 additions & 7 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit f7fe60b

Please sign in to comment.