Skip to content

Commit

Permalink
disable broken emit_isa codegen optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jrevels committed Jul 6, 2018
1 parent 4e60aa2 commit 9f71211
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,26 +1060,33 @@ static void emit_type_error(jl_codectx_t &ctx, const jl_cgval_t &x, Value *type,

static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type, const std::string *msg)
{
Optional<bool> known_isa;
jl_value_t *intersected_type = type;
if (x.constant)
known_isa = jl_isa(x.constant, type);
else if (jl_subtype(x.typ, type))
known_isa = true;
else {
intersected_type = jl_type_intersection(x.typ, type);
if (intersected_type == (jl_value_t*)jl_bottom_type)
known_isa = false;
}
if (known_isa) {
if (!*known_isa && msg) {
emit_type_error(ctx, x, literal_pointer_val(ctx, type), *msg);
ctx.builder.CreateUnreachable();
BasicBlock *failBB = BasicBlock::Create(jl_LLVMContext, "fail", ctx.f);
ctx.builder.SetInsertPoint(failBB);
}
return std::make_pair(ConstantInt::get(T_int1, *known_isa), true);
}

// TODO: This optimization suffers from incorrectness issues due to broken subtyping for
// kind types (see https://github.com/JuliaLang/julia/issues/27078). For actual `isa`
// calls, this optimization should already have been performed upstream anyway, but
// having this optimization in codegen might still be beneficial for `typeassert`s
// if we can make it correct.
//
// Optional<bool> known_isa;
// if (x.constant)
// known_isa = jl_isa(x.constant, type);
// else if (jl_subtype(x.typ, type))
// known_isa = true;
// else {
// intersected_type = jl_type_intersection(x.typ, type);
// if (intersected_type == (jl_value_t*)jl_bottom_type)
// known_isa = false;
// }
// if (known_isa) {
// if (!*known_isa && msg) {
// emit_type_error(ctx, x, literal_pointer_val(ctx, type), *msg);
// ctx.builder.CreateUnreachable();
// BasicBlock *failBB = BasicBlock::Create(jl_LLVMContext, "fail", ctx.f);
// ctx.builder.SetInsertPoint(failBB);
// }
// return std::make_pair(ConstantInt::get(T_int1, *known_isa), true);
// }

// intersection with Type needs to be handled specially
if (jl_has_intersect_type_not_kind(type)) {
Expand Down

0 comments on commit 9f71211

Please sign in to comment.