Skip to content

Commit 3b854f4

Browse files
authored
Fix uniquerep predicate in codegen (#50295)
Fixes #50293. This code probably predates us being clear on what the uniquerep predicate is.
1 parent 0e147eb commit 3b854f4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/codegen.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,7 @@ static inline jl_cgval_t ghostValue(jl_codectx_t &ctx, jl_value_t *typ)
18621862
typ = (jl_value_t*)jl_typeofbottom_type->super;
18631863
}
18641864
if (jl_is_type_type(typ)) {
1865+
assert(is_uniquerep_Type(typ));
18651866
// replace T::Type{T} with T, by assuming that T must be a leaftype of some sort
18661867
jl_cgval_t constant(NULL, true, typ, NULL, best_tbaa(ctx.tbaa(), typ));
18671868
constant.constant = jl_tparam0(typ);
@@ -1933,16 +1934,14 @@ static inline jl_cgval_t value_to_pointer(jl_codectx_t &ctx, const jl_cgval_t &v
19331934

19341935
static inline jl_cgval_t mark_julia_type(jl_codectx_t &ctx, Value *v, bool isboxed, jl_value_t *typ)
19351936
{
1936-
if (jl_is_datatype(typ) && jl_is_datatype_singleton((jl_datatype_t*)typ)) {
1937-
// no need to explicitly load/store a constant/ghost value
1938-
return ghostValue(ctx, typ);
1939-
}
19401937
if (jl_is_type_type(typ)) {
1941-
jl_value_t *tp0 = jl_tparam0(typ);
1942-
if (jl_is_concrete_type(tp0) || tp0 == jl_bottom_type) {
1938+
if (is_uniquerep_Type(typ)) {
19431939
// replace T::Type{T} with T
19441940
return ghostValue(ctx, typ);
19451941
}
1942+
} else if (jl_is_datatype(typ) && jl_is_datatype_singleton((jl_datatype_t*)typ)) {
1943+
// no need to explicitly load/store a constant/ghost value
1944+
return ghostValue(ctx, typ);
19461945
}
19471946
Type *T = julia_type_to_llvm(ctx, typ);
19481947
if (type_is_ghost(T)) {

test/core.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8033,3 +8033,10 @@ bar50250(b, y) = (b ? Bar50250(y, y) : Bar50250(y)).x
80338033
@test_throws UndefRefError foo50250(false, 1)
80348034
@test bar50250(true, 1) === 1
80358035
@test_throws UndefRefError bar50250(false, 1)
8036+
8037+
# Test that Type{typeof(Union{})} doesn't get codegen'ed as a constant (#50293)
8038+
baz50293(x::Union{Type, Core.Const}) = Base.issingletontype(x)
8039+
bar50293(@nospecialize(u)) = (Base.issingletontype(u.a), baz50293(u.a))
8040+
let u = Union{Type{Union{}}, Type{Any}}, ab = bar50293(u)
8041+
@test ab[1] == ab[2] == false
8042+
end

0 commit comments

Comments
 (0)