Repository navigation
Normalize type projections when computing pointer metadata - #4815
Conversation
|
Approved. just a note: The normalization itself looks right, and it lines up One asymmetry inside Should |
Kani crashed with "Error in struct_expr; must be given a struct_tag" when codegening an unsized coercion of a struct whose unsized tail is an associated type projection, e.g. `Wrap<Array<N>>` to `Wrap<Slice>` where the tail of `Wrap<Slice>` is `<Slice as Storage>::Buffer = [()]`. The `normalize_type` callback passed to `ptr_metadata_ty_or_tail` and `ptr_metadata_ty` skipped normalization, so the projection stayed unresolved, `use_thin_pointer` treated the reference as thin, and the unsized cast then tried to build a slice fat pointer with a thin pointer type, causing the panic. Normalize the projection (falling back to the unnormalized type when normalization fails, e.g. for types with generic parameters) so that pointer-width decisions agree with the actual monomorphized type. Resolves model-checking#4812
f257905 to
15358ae
Compare
|
Good catch! Fixed in 15358ae. |
Kani crashed with
Error in struct_expr; must be given a struct_tagwhen codegening an unsized coercion of a struct whose unsized tail is an associated type projection, e.g.&Wrap<Array<N>>to&Wrap<Slice>where the tail ofWrap<Slice>is<Slice as Storage>::Buffer = [()].The
normalize_typecallback passed toptr_metadata_ty_or_tail/ptr_metadata_tyskipped normalization (the TODO from #752), so the projection stayed unresolved,use_thin_pointerclassified the reference as a thin pointer, and the unsized cast then tried to build a slice fat pointer with a thin pointer type, hitting the panic inslice_fat_ptr.This PR normalizes the projection when computing pointer metadata, falling back to the unnormalized type when normalization fails (e.g., for types that still contain generic parameters), so that the thin/fat pointer decision agrees with the actual monomorphized type.
Testing
tests/kani/UnsizedCoercion/assoc_type_tail_coercion.rs(crashes without the fix, verifies successfully with it), covering both a non-ZST element type and the original ZST reproducer.cargo kani autoharness -Z autoharness) now verifies successfully.kaniandexpectedcompiletest suites pass locally.Resolves #4812
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.