Skip to content

Commit

Permalink
Fix uniquerep predicate in codegen (#50295)
Browse files Browse the repository at this point in the history
Fixes #50293. This code probably predates us being clear on what
the uniquerep predicate is.
  • Loading branch information
Keno authored Jun 27, 2023
1 parent 0e147eb commit 3b854f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,7 @@ static inline jl_cgval_t ghostValue(jl_codectx_t &ctx, jl_value_t *typ)
typ = (jl_value_t*)jl_typeofbottom_type->super;
}
if (jl_is_type_type(typ)) {
assert(is_uniquerep_Type(typ));
// replace T::Type{T} with T, by assuming that T must be a leaftype of some sort
jl_cgval_t constant(NULL, true, typ, NULL, best_tbaa(ctx.tbaa(), typ));
constant.constant = jl_tparam0(typ);
Expand Down Expand Up @@ -1933,16 +1934,14 @@ static inline jl_cgval_t value_to_pointer(jl_codectx_t &ctx, const jl_cgval_t &v

static inline jl_cgval_t mark_julia_type(jl_codectx_t &ctx, Value *v, bool isboxed, jl_value_t *typ)
{
if (jl_is_datatype(typ) && jl_is_datatype_singleton((jl_datatype_t*)typ)) {
// no need to explicitly load/store a constant/ghost value
return ghostValue(ctx, typ);
}
if (jl_is_type_type(typ)) {
jl_value_t *tp0 = jl_tparam0(typ);
if (jl_is_concrete_type(tp0) || tp0 == jl_bottom_type) {
if (is_uniquerep_Type(typ)) {
// replace T::Type{T} with T
return ghostValue(ctx, typ);
}
} else if (jl_is_datatype(typ) && jl_is_datatype_singleton((jl_datatype_t*)typ)) {
// no need to explicitly load/store a constant/ghost value
return ghostValue(ctx, typ);
}
Type *T = julia_type_to_llvm(ctx, typ);
if (type_is_ghost(T)) {
Expand Down
7 changes: 7 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8033,3 +8033,10 @@ bar50250(b, y) = (b ? Bar50250(y, y) : Bar50250(y)).x
@test_throws UndefRefError foo50250(false, 1)
@test bar50250(true, 1) === 1
@test_throws UndefRefError bar50250(false, 1)

# Test that Type{typeof(Union{})} doesn't get codegen'ed as a constant (#50293)
baz50293(x::Union{Type, Core.Const}) = Base.issingletontype(x)
bar50293(@nospecialize(u)) = (Base.issingletontype(u.a), baz50293(u.a))
let u = Union{Type{Union{}}, Type{Any}}, ab = bar50293(u)
@test ab[1] == ab[2] == false
end

0 comments on commit 3b854f4

Please sign in to comment.