optimizer: apply `unwrap_unionall` after `widenconst` in `sroa_mutables!` (#61743)
`sroa_mutables!` derived the allocation `DataType` by calling
`unwrap_unionall` on the raw lattice element of a `:new` and only then
widening it. That order was incorrect: `unwrap_unionall` is meaningful
on a plain `Type`, not on any extended lattice elements (e.g.,
`PartialStruct` whose `.typ` may itself be a `UnionAll`), so when
inference produced a `PartialStruct`-typed `:new` the unwrap was a no-op
and the subsequent `typ::DataType` typeassert could fail on a
`UnionAll`. Reorder so `widenconst` runs first.
This was latent since `Core.PartialStruct` was extended to admit
`UnionAll` for `.typ` (#57304), and surfaced as a typeassert crash via
#61719, which made `:new` actually emit such `PartialStruct`s.
I also directed an AI-driven audit of related sites — every place under
`Compiler/src/` that derives a `DataType` from a lattice element which
could be a `PartialStruct` (passes, inlining, EscapeAnalysis, tfuncs,
typelattice) — and confirmed the rest already use
`unwrap_unionall(widenconst(...))` or guard with explicit `isa(_,
DataType)` / `argument_datatype` checks, so no other site needs the same
reordering.
Both the diagnosis and the patch were developed with the assistance of
generative AI.
Fixes #61740
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>