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: propagate partially initialized mutable structs more #55533

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

aviatesk
Copy link
Member

Following up #55297.
A mutable struct can have undefined fields in a non-contiguous manner, but PartialStruct cannot model such a state. So in #55297 PartialStruct was used to represent only the mutable objects where the field following the minimum initialized fields is also defined.

As a follow-up for the PR, this commit implements a minor improvement that, in cases when the mutable object is already represented as a PartialStruct, allows inference to add one more isdefined-field information on top of those implied by its fields.

mutable struct PartiallyInitialized2
    a; b; c
    PartiallyInitialized2(a) = (@nospecialize; new(a))
    PartiallyInitialized2(a, b) = (@nospecialize; new(a, b))
    PartiallyInitialized2(a, b, c) = (@nospecialize; new(a, b, c))
end

@test Base.infer_effects((PartiallyInitialized2,); optimize=false) do x
    if isdefined(x, :b)
        if isdefined(x, :c)
            return x.c
        end
        return x.b
    end
    return nothing
end |> Core.Compiler.is_nothrow

@nanosoldier runtests()

@aviatesk aviatesk force-pushed the avi/follow-up-55297 branch 2 times, most recently from 266d635 to 288d601 Compare August 20, 2024 06:23
@nanosoldier
Copy link
Collaborator

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

@aviatesk
Copy link
Member Author

@nanosoldier runtests(["ASEconvert", "EarlyStopping", "BayesianQuadrature", "HMMER", "LazySets", "GeometricIntegrators", "AstrodynamicalModels", "TimeseriesFeatures", "DifferentialEvolutionMCMC", "ClimaDiagnostics", "SpeedyWeather", "CellMLToolkit", "FaultTolerantControl", "CellularPotts", "HighVoronoi", "VLBIPlots", "EnvironmentalTransport", "QuantumAnnealingAnalytics"])

@giordano giordano added the compiler:inference Type inference label Aug 20, 2024
Following up #55297.
A mutable struct can have undefined fields in a non-contiguous manner,
but `PartialStruct` cannot model such a state. So in #55297
`PartialStruct` was used to represent only the mutable objects where the
field following the minimum initialized fields is also defined.

As a follow-up for the PR, this commit implements a minor improvement
that, in cases when the mutable object is already represented as a
`PartialStruct`, allows inference to add one more `isdefined`-field
information on top of those implied by its `fields`.

```julia
mutable struct PartiallyInitialized2
    a; b; c
    PartiallyInitialized2(a) = (@nospecialize; new(a))
    PartiallyInitialized2(a, b) = (@nospecialize; new(a, b))
    PartiallyInitialized2(a, b, c) = (@nospecialize; new(a, b, c))
end

@test Base.infer_effects((PartiallyInitialized2,); optimize=false) do x
    if isdefined(x, :b)
        if isdefined(x, :c)
            return x.c
        end
        return x.b
    end
    return nothing
end |> Core.Compiler.is_nothrow
```
@nanosoldier
Copy link
Collaborator

The package evaluation job you requested has completed - no new issues were detected.
The full report is available.

@aviatesk aviatesk merged commit 58c7186 into master Aug 22, 2024
4 of 7 checks passed
@aviatesk aviatesk deleted the avi/follow-up-55297 branch August 22, 2024 02:54
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.

4 participants