5.9: [IRGen] Add metadata pack markers for more instructions. #67497
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description: Cleanup pack metadata when it's allocated for a destroy, alloc_stack, or other instruction when it involves a pack type.
SIL has no notion of metadata or witness tables. SIL, however, is the right level at which to fixup stack nesting, ensuring that the various stack allocated things obey stack discipline. When certain instructions are IRGen'd, packs of metadata and witness tables may be allocated on the stack. Forcing these stack allocations to obey stack has two parts: (1) IRGen's SIL pass PackMetadataMarkerInserter and (2) IRGen itself. In (1), a list (which this patch extends) of instructions which may result in pack metadata being allocated on the stack is consulted; each such instruction results in new marker instructions being inserted: a single
alloc_pack_metadata
instruction is inserted before it, and some number ofdealloc_pack_metadata
instructions are inserted on its boundary. In (2), the on-stack metadata and witness tables emitted while IRGen'ing each such instruction are recorded. Then when eachdealloc_pack_metadata
instruction is visited, those metadata and witness tables are cleaned up in reverse order.The purpose of the list of instructions used by (1) is to limit the number of such marker instructions that are created. Here, three new instructions are conditionally added to the list:
destroy_addr
,destroy_value
andalloc_stack
. Such instructions only get markers if the type that they are destroying involves a pack.Finally, all (non-stack allocating, non-function exiting) other instructions are also given markers if any of their operands or results involve a pack type. This will help to avoid similar problems in the future.
Risk: Low. The change is just to expand the list of instructions that get these markers.
Scope: Narrow. This only affects variadic generics code.
Original PR: #67493 , #67567 , #67569 , #67778
Reviewed By: @aschwaighofer
Testing: Added @slavapestov's source-level test cases that previously hit an assertion failure.
Resolves: rdar://112792831