Skip to content

[Definite Initialization] Fix a bug that made the DI wrongly think that an unused access to "self" in a delegating initializer is a use of the form: type(of:self) #25483

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

ravikandhadai
Copy link
Contributor

@ravikandhadai ravikandhadai commented Jun 14, 2019

rdar://51198592

(cherry-picked from master ff3d081 PR: #25403)

that an unused access to "self" in a delegating initializer is a use
of the form: `type(of:self)`

<rdar://51198592>
@ravikandhadai
Copy link
Contributor Author

@swift-ci Please smoke test

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please test Source Compatibility

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please Test Source Compatibility

@ravikandhadai
Copy link
Contributor Author

@swift-ci please test

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please nominate

Explanation:
Swift compiler guarantees that memory locations are initialized before their use. This is enforced by a compiler pass: Definition Initialization (DI). In the case of convenience initializers of classes, this pass enforces that the 'self' reference is never used in any construct other than 'type(of: self)' before being initialized by a call to a designated initializer. The bug fixed by this patch causes DI to erroneously think that the convenience initializer has a 'type(of: self)' expression when there is none, which eventually results in a compiler crash.

Scope: The compiler crash fixed by this patch occurs frequently. It is consistently in the top 20 crashes of SourceKit.

Radar: rdar://problem/51198592

Risk:
This patch changes the behavior of the compiler from crashing to producing a compiler error. It affects only code containing convenience initializers that use 'self' before it is initialized. Any bugs in the fix could cause miscompiles and/or produce spurious compiler errors in such code.

Testing:
This patch is tested with Swift CI tests and with source compatibility tests. This patch was also merged with the open-source master branch and has been tested by the test bots without any issues.

@devincoughlin devincoughlin merged commit 93bf6ba into swiftlang:swift-5.1-branch-06-12-2019 Jun 15, 2019
@ravikandhadai
Copy link
Contributor Author

Thanks Devin. This fix is also merged with 5.1-branch: #25499

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