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: refine branched Conditional types #55216

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

aviatesk
Copy link
Member

Separated from #40880.
This subtle adjustment allows for more accurate type inference in the following kind of cases:

function condition_object_update2(x)
    cond = x isa Int
    if cond # `cond` is known to be `Const(true)` within this branch
        return !cond ? nothing : x # ::Int
    else
        return  cond ? nothing : 1 # ::Int
    end
end
@test Base.infer_return_type(condition_object_update2, (Any,)) == Int

Also cleans up typelattice.jl a bit.

Separated from #40880.
This subtle adjustment allows for more accurate type inference in the
following kind of cases:
```julia
function condition_object_update2(x)
    cond = x isa Int
    if cond # `cond` is known to be `Const(true)` within this branch
        return !cond ? nothing : x # ::Int
    else
        return  cond ? nothing : 1 # ::Int
    end
end
@test Base.infer_return_type(condition_object_update2, (Any,)) == Int
```
@tecosaur tecosaur added performance Must go faster compiler:inference Type inference labels Jul 23, 2024
@aviatesk aviatesk merged commit 24cfe6e into master Jul 24, 2024
9 checks passed
@aviatesk aviatesk deleted the avi/refine-condition-object branch July 24, 2024 06:36
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Jul 24, 2024
Separated from JuliaLang#40880.
This subtle adjustment allows for more accurate type inference in the
following kind of cases:
```julia
function condition_object_update2(x)
    cond = x isa Int
    if cond # `cond` is known to be `Const(true)` within this branch
        return !cond ? nothing : x # ::Int
    else
        return  cond ? nothing : 1 # ::Int
    end
end
@test Base.infer_return_type(condition_object_update2, (Any,)) == Int
```

Also cleans up typelattice.jl a bit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants