Skip to content

Commit

Permalink
inference: stronger state update from branching
Browse files Browse the repository at this point in the history
This change addresses
<#40832 (review)>
  • Loading branch information
aviatesk committed Jul 22, 2024
1 parent 6e8d7a4 commit cc5a8c3
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2207,22 +2207,34 @@ end |> only === String
c === 42 ? :a : "b"
end |> only === String

@testset "conditional constraint propagation from non-`Conditional` object" begin
@test Base.return_types((Bool,)) do b
@testset "state update on branching" begin
# refine condition type into constant boolean value on branching
@test Base.infer_return_type((Bool,)) do b
if b
return !b ? nothing : 1 # ::Int
else
return 0
end
end == Any[Int]
end == Int

@test Base.return_types((Any,)) do b
# even when the original type isn't boolean type
@test Base.infer_return_type((Any,)) do b
if b
return b # ::Bool
else
return nothing
end
end == Any[Union{Bool,Nothing}]
end == Union{Bool,Nothing}

# even when the original type is `Conditional`
@test Base.infer_return_type((Any,)) do a
b = isa(a, Int)
if b
return !b ? nothing : a # ::Int
else
return 0
end
end == Int
end

@testset "`from_interprocedural!`: translate inter-procedural information" begin
Expand Down

0 comments on commit cc5a8c3

Please sign in to comment.