Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inference: propagate partially initialized mutable structs more
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 ```
- Loading branch information