Skip to content

Conversation

@aviatesk
Copy link
Member

I found that a tricky thing can happen when constant inference derives
Const-result while non-constant inference has derived (non-constant)
InterConditional result beforehand. In such a case, currently we discard
the result with constant infernece (since !(Const ⊑ InterConditional)),
but we can achieve more accuracy by not discarding that Const-information, e.g.:

julia> iszero_simple(x) = x === 0
iszero_simple (generic function with 1 method)

julia> @test Base.return_types() do
           iszero_simple(0) ? nothing : missing
       end |> only === Nothing
Test Passed

@aviatesk aviatesk added the compiler:inference Type inference label Mar 18, 2022
@aviatesk aviatesk requested a review from vtjnash March 18, 2022 07:15
Base automatically changed from avi/refac to master March 18, 2022 16:39
@aviatesk aviatesk force-pushed the avi/constintercond branch from 74383af to ef23805 Compare March 19, 2022 00:34
I found that a tricky thing can happen when constant inference derives
`Const`-result while non-constant inference has derived (non-constant)
`InterConditional` result beforehand. In such a case, currently we discard
the result with constant infernece (since `!(Const ⊑ InterConditional)`),
but we can achieve more accuracy by not discarding that `Const`-information, e.g.:
```julia
julia> iszero_simple(x) = x === 0
iszero_simple (generic function with 1 method)

julia> @test Base.return_types() do
           iszero_simple(0) ? nothing : missing
       end |> only === Nothing
Test Passed
```
@aviatesk aviatesk force-pushed the avi/constintercond branch from ef23805 to f4e47e5 Compare March 19, 2022 03:03
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. Someday, the appropriate call here would be a symmetric tmeet (type-intersection), which we don't now implement, to be extract the most info

Co-authored-by: Kristoffer Carlsson <[email protected]>
@aviatesk aviatesk added the backport 1.8 Change should be backported to release-1.8 label Mar 20, 2022
@aviatesk aviatesk merged commit 7cde4be into master Mar 22, 2022
@aviatesk aviatesk deleted the avi/constintercond branch March 22, 2022 02:44
@KristofferC KristofferC mentioned this pull request Mar 23, 2022
22 tasks
aviatesk added a commit that referenced this pull request Mar 24, 2022
…44668)

I found that a tricky thing can happen when constant inference derives
`Const`-result while non-constant inference has derived (non-constant)
`InterConditional` result beforehand. In such a case, currently we discard
the result with constant inference (since `!(Const ⊑ InterConditional)`),
but we can achieve more accuracy by not discarding that `Const`-information, e.g.:
```julia
julia> iszero_simple(x) = x === 0
iszero_simple (generic function with 1 method)

julia> @test Base.return_types() do
           iszero_simple(0) ? nothing : missing
       end |> only === Nothing
Test Passed
```
@KristofferC KristofferC removed the backport 1.8 Change should be backported to release-1.8 label Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:inference Type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants