Skip to content

6.2: [TypeLowering] Record packs used in signatures. #81659

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

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented May 21, 2025

Explanation: Fix a compiler crash involving a stored propoerty of variadic type substituted with a non-variadic type.

Metadata packs are stored on the stack as an optimization. These allocations must obey stack discipline. This is enforced via the PackMetadataMarkerInserter pass. That pass inserts alloc_pack_metadata marker instructions before each instruction which may allocate an on-stack pack and inserts dealloc_pack_metadata instructions to indicate where those packs should be deallocated (the StackNesting utility ensures proper nesting, reflowing all stack deallocating instructions as needded). The pass relies on knowing whether an instruction may allocate an on-stack pack. This is determined by a recursive walk over the fields of each type of each operand of the instruction. That walk is done in TypeLowering.

Previously, the walk only regarded a type as involving a pack if it contained a pack in its storage. This was sufficient for non-resilient types because the metadata was not needed for types like S<each T> when each T was not stored (recursively). This doesn't work with resilient types however, whose storage is not known during the walk. The metadata for resilient struct S<each T> is still required.

Here, this is fixed by extending the condition under which a type is said to have a have a pack. In addition to considering a type which is itself a pack and types which store a pack, now types which have a pack in their signature are considered to have a pack as well.
Scope: Affects variadic generics across resilience boundaries.
Issue: rdar://147207926
Original PR: #81581
Risk: Low, this just makes the de/alloc_pack_metadata marker instructions be emitted slightly more frequently.
Testing: Added test.
Reviewer: Arnold Schwaighofer ( @aschwaighofer )

To determine whether an instruction may require pack metadata, the types
of its operands are examined.

Previously, the top level type was checked for having a pack in its
signature, and the whole type was checked for having a type anywhere in
its layout (via TypeLowering).  This didn't account for the case where
the metadata was required for a resilient type which uses a pack in its
signature.

Here, during type lowering, a type having a pack in its signature is
counted towards the type having a pack.

Fixes a compiler crash.

rdar://147207926
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review May 21, 2025 20:37
@nate-chandler nate-chandler requested a review from a team as a code owner May 21, 2025 20:37
@nate-chandler nate-chandler enabled auto-merge May 21, 2025 20:37
@nate-chandler nate-chandler merged commit 1887346 into swiftlang:release/6.2 May 21, 2025
5 checks passed
@nate-chandler nate-chandler deleted the cherrypick/release/6.2/rdar147207926 branch May 21, 2025 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants