Skip to content

[4.2] Eagerly create init(from:) when looking up 'init' on a Decodable type #17732

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
merged 1 commit into from
Jul 4, 2018

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Jul 4, 2018

  • Explanation: When initializers are inherited onto a subclass, the compiler looks up all initializers on the base class via the name init. However, this was dodging the implicit synthesis logic for Decodable's init(from:), leading to the base class initializer being ignored and then silently inherited as-is onto the subclass (instead of making an override that knows to allocate a different type!). This resulted in a miscompile.

  • Scope: Affects all lookups of init and encode (without argument names), but only changes behavior if the type in question conforms to Decodable. A compiler performance smoke test showed no significant compile time change.

  • Issue: SR-8083 / rdar://problem/41426211

  • Risk: Medium-low. This is getting called in a lot more places, but most types don't conform to Decodable, and any that did were already running this code, just a little later.

  • Testing: Added compiler regression tests.

  • Reviewed by: @slavapestov, @itaiferber

…swiftlang#17712)

Otherwise, the initializer won't be inherited properly onto a
subclass, resulting in the base class being allocated instead of the
subclass when using Sub.init(from:).

https://bugs.swift.org/browse/SR-8083
(cherry picked from commit 9ee996c)
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please nominate

@jrose-apple jrose-apple merged commit f56a941 into swiftlang:swift-4.2-branch Jul 4, 2018
@jrose-apple jrose-apple deleted the 4.2-hard-innit branch July 4, 2018 05:52
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.

1 participant