SILGen: Fix 'multiple definitions of symbol' error for functions with @_backDeploy containing defer blocks
#62444
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.
If the emission of a function is delayed via
emitOrDelayFunction(), then the function is recorded on a list of delayed functions. If the delayed function is later referenced, then the function moves from the delayed list to the "forced" list which will cause it to actually be emitted later. The implementation ofemitOrDelayFunction()had a bug when called twice for the same delayable function - it would emit that function prematurely if the function moved to the forced list between the two invocations. Later, during forced function emission a multiple definitions of symbol diagnostic would be emitted since the function was not empty.This issue could be triggered by
@_backDeployfunctions that have auxilary delayable helper functions (e.g. defer blocks). SILGen visits@_backDeployfunctions twice (once for the copy of the function emitted into the client and once for the resilient copy of the function) soemitOrDelayFunction()is called twice for each of the helper functions and the helper functions could become referenced between the two calls.The fix is to check for an existing entry in the forced functions list before delaying or emitting a delayable function.
Resolves rdar://102909684