julia
julia copied to clipboard
optimizer: don't insert `:throw_undef_if_not` for defined slots
As an application of JuliaLang/julia#55545, this commit avoids the insertion of :throw_undef_if_not nodes when the defined-ness of a slot is guaranteed by abstract interpretation.
julia> function isdefined_nothrow(c, x)
local val
if c
val = x
end
if @isdefined val
return val
end
return zero(Int)
end;
julia> @code_typed isdefined_nothrow(true, 42)
diff --git a/old b/new
index c4980a5c9c..3d1d6d30f0 100644
--- a/old
+++ b/new
@@ -4,7 +4,6 @@ CodeInfo(
3 ┄ %3 = φ (#2 => x, #1 => #undef)::Int64
│ %4 = φ (#2 => true, #1 => false)::Bool
└── goto #5 if not %4
-4 ─ $(Expr(:throw_undef_if_not, :val, :(%4)))::Any
-└── return %3
+4 ─ return %3
5 ─ return 0
) => Int64