Skip to content

SILGen: Fix 'multiple definitions of symbol' error for functions with @_backDeploy containing defer blocks #62444

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

Merged

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Dec 7, 2022

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 of emitOrDelayFunction() 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 @_backDeploy functions that have auxilary delayable helper functions (e.g. defer blocks). SILGen visits @_backDeploy functions twice (once for the copy of the function emitted into the client and once for the resilient copy of the function) so emitOrDelayFunction() 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

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to make sense, thank you @tshortli !

@tshortli tshortli force-pushed the back-deploy-attr-duplicate-symbols-error branch from 2f6b024 to 2dd809c Compare December 8, 2022 00:15
@tshortli
Copy link
Contributor Author

tshortli commented Dec 8, 2022

@swift-ci please test

… `@_backDeploy` containing defer blocks.

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 of `emitOrDelayFunction()` 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 `@_backDeploy` functions that have auxilary delayable helper functions (e.g. defer blocks). SILGen visits `@_backDeploy` functions twice (once for the copy of the function emitted into the client and once for the resilient copy of the function) so `emitOrDelayFunction()` 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
@tshortli tshortli force-pushed the back-deploy-attr-duplicate-symbols-error branch from 2dd809c to 95a9310 Compare December 8, 2022 04:51
@tshortli
Copy link
Contributor Author

tshortli commented Dec 8, 2022

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 76d337c into swiftlang:main Dec 8, 2022
@tshortli tshortli deleted the back-deploy-attr-duplicate-symbols-error branch December 8, 2022 17:38
tshortli added a commit to tshortli/swift that referenced this pull request Jan 10, 2023
Older versions of the 5.8 compiler have a bug when generating SIL for functions with `@_backDeploy` containing defer blocks (swiftlang#62444) and for now we need the standard library interface to be compatible with those older compilers.

Resolves rdar://104045168
tshortli added a commit to tshortli/swift that referenced this pull request Jan 10, 2023
…tandard library.

Older versions of the 5.8 compiler have a bug when generating SIL for functions with `@_backDeploy` containing defer blocks (swiftlang#62444) and for now we need the standard library interface to be compatible with those older compilers.

Resolves rdar://104045168
tshortli added a commit to tshortli/swift that referenced this pull request Jan 10, 2023
…tandard library.

Older versions of the 5.8 compiler have a bug when generating SIL for functions with `@_backDeploy` containing defer blocks (swiftlang#62444) and for now we need the standard library interface to be compatible with those older compilers.

Resolves rdar://104045168
tshortli added a commit to tshortli/swift that referenced this pull request Jan 10, 2023
…tandard library.

Older versions of the 5.8 compiler have a bug when generating SIL for functions with `@_backDeploy` containing defer blocks (swiftlang#62444) and for now we need the standard library interface to be compatible with those older compilers.

Resolves rdar://104045168
tshortli added a commit to tshortli/swift that referenced this pull request Jan 10, 2023
…tandard library.

Older versions of the 5.8 compiler have a bug when generating SIL for functions with `@_backDeploy` containing defer blocks (swiftlang#62444) and for now we need the standard library interface to be compatible with those older compilers.

Resolves rdar://104045168
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.

3 participants