Skip to content

[Clang importer] Make sure that the first argument of Set/Dictionary types are Hashable. #10602

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

DougGregor
Copy link
Member

Explanation: Eliminate a crash due to importing an Objective-C API with a Set or Dictionary aren't that is a non-Hashable struct or enum type. For example, instead of importing NSSet<NSSet<id>> as the nonsensical type Set<Set<Any>> (because Set isn't Hashable), import it as the safer Set<AnyHashable>.
Scope: The scope of the fix is pretty limited, since Swift would complain or crash if you ever actually tried to import such an API. However, see Risk.
Radar: rdar://problem/30622665
Risk: The fix performs a conformance check in a new place in the Clang importer. We have seen some problems with performing conformance checks elsewhere in the Clang importer that manifest as circularity issues that would crash the compiler. It's hard to assess whether such circularities will come up beyond just "qualify the compiler and see if it breaks".
Testing: Compiler regression testing.

…types are Hashable.

Extend the check to make sure that the first type argument to an
imported Set or Dictionary type is Hashable actually checks
struct/enum types for Hashable conformances.

Fixes rdar://problem/30622665.

(cherry picked from commit aa215e7)
@DougGregor
Copy link
Member Author

@jrose-apple let's make management decide :)

@DougGregor
Copy link
Member Author

@swift-ci please test

@jckarter
Copy link
Contributor

Set is in fact hashable, it's Any that isn't. Set<Set<AnyHashable>> would work.

@DougGregor
Copy link
Member Author

Ah. The actual example is a Set<Dictionary<String, Any>>. The importer would form such an invalid type

@DougGregor DougGregor merged commit 52a0d92 into swiftlang:swift-4.0-branch Jun 27, 2017
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