Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inference: override InterConditional result with Const carefully #44668

Merged
merged 2 commits into from
Mar 22, 2022

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
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
```
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 <kcarlsson89@gmail.com>
@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