Skip to content

Commit 89dfb68

Browse files
authored
inference: improve isdefined_tfunc accuracy for MustAlias (JuliaLang#58743)
1 parent 24b3273 commit 89dfb68

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Compiler/src/tfuncs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ end
405405
return isdefined_tfunc(𝕃, arg1, sym)
406406
end
407407
@nospecs function isdefined_tfunc(𝕃::AbstractLattice, arg1, sym)
408+
if arg1 isa MustAlias
409+
arg1 = widenmustalias(arg1)
410+
end
408411
arg1t = arg1 isa Const ? typeof(arg1.val) : isconstType(arg1) ? typeof(arg1.parameters[1]) : widenconst(arg1)
409412
a1 = unwrap_unionall(arg1t)
410413
if isa(a1, DataType) && !isabstracttype(a1)

Compiler/test/inference.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,12 +2313,6 @@ let 𝕃ᵢ = InferenceLattice(MustAliasesLattice(BaseInferenceLattice.instance)
23132313
@test ifelse_tfunc(MustAlias(2, AliasableField{Any}, 1, Int), Int, Int) === Union{}
23142314
end
23152315

2316-
@testset "issue #56913: `BoundsError` in type inference" begin
2317-
R = UnitRange{Int}
2318-
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, Vararg{R}})
2319-
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, R, Vararg{R}})
2320-
end
2321-
23222316
maybeget_mustalias_tmerge(x::AliasableField) = x.f
23232317
maybeget_mustalias_tmerge(x) = x
23242318
@test Base.return_types((Union{Nothing,AliasableField{Any}},); interp=MustAliasInterpreter()) do x
@@ -2593,6 +2587,19 @@ end |> only === Compiler.InterMustAlias
25932587
return 0
25942588
end == Integer
25952589

2590+
# `isdefined` accuracy for `MustAlias`
2591+
@test Base.infer_return_type((Any,); interp=MustAliasInterpreter()) do x
2592+
xx = Ref{Any}(x)
2593+
xxx = Some{Any}(xx)
2594+
Val(isdefined(xxx.value, :x))
2595+
end == Val{true}
2596+
2597+
@testset "issue #56913: `BoundsError` in type inference" begin
2598+
R = UnitRange{Int}
2599+
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, Vararg{R}})
2600+
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, R, Vararg{R}})
2601+
end
2602+
25962603
function f25579(g)
25972604
h = g[]
25982605
t = (h === nothing)

0 commit comments

Comments
 (0)