Skip to content

Commit 198b618

Browse files
committed
re-enable the nonbroken part of the codegen emit_isa optimization
1 parent 94e9c5d commit 198b618

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/cgutils.cpp

+19-18
Original file line numberDiff line numberDiff line change
@@ -1062,31 +1062,32 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
10621062
{
10631063
jl_value_t *intersected_type = type;
10641064

1065-
// TODO: This optimization suffers from incorrectness issues due to broken subtyping for
1066-
// kind types (see https://github.com/JuliaLang/julia/issues/27078). For actual `isa`
1067-
// calls, this optimization should already have been performed upstream anyway, but
1068-
// having this optimization in codegen might still be beneficial for `typeassert`s
1069-
// if we can make it correct.
1070-
//
1071-
// Optional<bool> known_isa;
1072-
// if (x.constant)
1073-
// known_isa = jl_isa(x.constant, type);
1065+
// TODO: The commented-out part of this optimization suffers from incorrectness issues
1066+
// due to broken subtyping for kind types (see
1067+
// https://github.com/JuliaLang/julia/issues/27078). For actual `isa` calls, this
1068+
// optimization should already have been performed upstream anyway, but having this
1069+
// optimization in codegen might still be beneficial for `typeassert`s if we can make it
1070+
// correct.
1071+
Optional<bool> known_isa;
1072+
if (x.constant) {
1073+
known_isa = jl_isa(x.constant, type);
1074+
}
10741075
// else if (jl_subtype(x.typ, type))
10751076
// known_isa = true;
10761077
// else {
10771078
// intersected_type = jl_type_intersection(x.typ, type);
10781079
// if (intersected_type == (jl_value_t*)jl_bottom_type)
10791080
// known_isa = false;
10801081
// }
1081-
// if (known_isa) {
1082-
// if (!*known_isa && msg) {
1083-
// emit_type_error(ctx, x, literal_pointer_val(ctx, type), *msg);
1084-
// ctx.builder.CreateUnreachable();
1085-
// BasicBlock *failBB = BasicBlock::Create(jl_LLVMContext, "fail", ctx.f);
1086-
// ctx.builder.SetInsertPoint(failBB);
1087-
// }
1088-
// return std::make_pair(ConstantInt::get(T_int1, *known_isa), true);
1089-
// }
1082+
if (known_isa) {
1083+
if (!*known_isa && msg) {
1084+
emit_type_error(ctx, x, literal_pointer_val(ctx, type), *msg);
1085+
ctx.builder.CreateUnreachable();
1086+
BasicBlock *failBB = BasicBlock::Create(jl_LLVMContext, "fail", ctx.f);
1087+
ctx.builder.SetInsertPoint(failBB);
1088+
}
1089+
return std::make_pair(ConstantInt::get(T_int1, *known_isa), true);
1090+
}
10901091

10911092
// intersection with Type needs to be handled specially
10921093
if (jl_has_intersect_type_not_kind(type)) {

0 commit comments

Comments
 (0)