Skip to content

[Coding] Make Codable conformances for Optional and collections conditional. #13178

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

DougGregor
Copy link
Member

Array, Set, Dictionary, and Optional all provide unconditional conformances
to Encodable & Decodable that dynamically check whether their type arguments
are Encodable/Decodable. Now that we have conditional conformances, make
these unconditional conformances properly conditional, removing all of
the Swift 4-era type-erasure hacks.

Fixes rdar://problem/34989162.

…tional.

Array, Set, Dictionary, and Optional all provide unconditional conformances
to Encodable & Decodable that dynamically check whether their type arguments
are Encodable/Decodable. Now that we have conditional conformances, make
these unconditional conformances properly conditional, removing all of
the Swift 4-era type-erasure hacks.

Fixes rdar://problem/34989162.
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 89343e2

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

Copy link
Contributor

@itaiferber itaiferber left a comment

Choose a reason for hiding this comment

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

These look good! (I have pretty much line for line the same diff on a local branch here.) We can further simplify DerivedConformanceCodable.cpp by removing the explicit checks for Array, Dictionary, Set, and Optional as well — mentioned this via email but wanted to make sure the commend didn't get lost.

The Codable synthesis code was checking the conditional requirements of
Optional/Array/Set/Dictionary's Codable conformances, which had to be
unconditional. Now that they are properly conditional conformances, we
no longer need the hack.

Thanks to @itaiferber for pointing this out!
Copy link
Contributor

@itaiferber itaiferber left a comment

Choose a reason for hiding this comment

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

Excellent, thank you, Doug! 😄

@DougGregor
Copy link
Member Author

@swift-ci please test and merge

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 89343e2

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 89343e2

@DougGregor DougGregor merged commit 33de34b into swiftlang:master Nov 30, 2017
@DougGregor DougGregor deleted the coding-conditional-conformances branch November 30, 2017 21:43
@itaiferber
Copy link
Contributor

🎉🙌

@norio-nomura
Copy link
Contributor

Are [Any] and [String: Any] no longer Codable?

@itaiferber
Copy link
Contributor

@norio-nomura [Any] and [String : Any] never really were Codable because Any doesn’t (and can’t truly) conform to Codable — it would just fail at runtime if you tried. Now that is caught statically.

@norio-nomura
Copy link
Contributor

@itaiferber Oh, yes. I was a bit confused. Thank you very much.

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.

4 participants