Skip to content

Make all CF types Equatable and Hashable. #4394

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
Aug 19, 2016

Conversation

jrose-apple
Copy link
Contributor

Like NSObject, CFType has primitive operations CFEqual and CFHash, so Swift should allow those types to show up in Hashable positions (like dictionaries). The most general way to do this was to introduce a new protocol, _CFObject, and then have the importer automatically make all CF types conform to it.

This did require one additional change: the == implementation that calls through to CFEqual is in a new CoreFoundation overlay, but the conformance is in the underlying Clang module. Therefore, operator lookup for conformances has been changed to look in the overlay for an imported declaration (if there is one).

https://bugs.swift.org/browse/SR-2388


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

A smoke test on macOS does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library only for macOS. Simulator standard libraries and
    device standard libraries are not built.
  3. lldb is not built.
  4. The test and validation-test targets are run only for macOS. The optimized
    version of these tests are not run.

A smoke test on Linux does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library incrementally.
  3. lldb is built incrementally.
  4. The swift test and validation-test targets are run. The optimized version of these
    tests are not run.
  5. lldb is tested.

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@jrose-apple
Copy link
Contributor Author

@DougGregor and @jckarter, can you review this? I want to be very sure I didn't introduce something wonky.

@swift-ci Please test

if (isa<ProtocolDecl>(witness->getDeclContext())) {
continue;
}
enum Attempt {
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like too much of a special case -- can we generalize this somehow? Why are operators special? I see the operator in question is inside a type anyway, why isn't it found with the usual mechanisms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Operator lookup is always global right now. We can take it back out if/when that's no longer true or when it becomes a fallback path.

I want this to be narrow because there shouldn't be many cases where it happens; we can broaden it later if we need to.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I'll stop complaining. Let's tack this onto @DougGregor's todo list for his upcoming name lookup cleanup. :)

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - d33c94deea3196bb59c8463e72e339170e2ffe97
Test requested by - @jrose-apple

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test OS X platform

@jckarter
Copy link
Contributor

Overlay part LGTM. I defer to @slavapestov and @DougGregor on the sema parts.

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - d33c94deea3196bb59c8463e72e339170e2ffe97
Test requested by - @jrose-apple

@tkremenek
Copy link
Member

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - d33c94deea3196bb59c8463e72e339170e2ffe97
Test requested by - @tkremenek

@DougGregor
Copy link
Member

The change to operator lookup feels a bit weird as a one-off hack, but it looks like it will do the job. The rest looks good.

@gribozavr
Copy link
Contributor

gribozavr commented Aug 19, 2016

There's an extension CFBitVector : Hashable in validation-test/stdlib/AnyHashable.swift.gyb, should that be diagnosed by the compiler as a duplicate conformance?

Edit: I see that it is.

validation-test/stdlib/AnyHashable.swift.gyb:542:25: error: redundant conformance of 'CFBitVector' to protocol 'Hashable'

@jrose-apple
Copy link
Contributor Author

And this is why we run tests first. :-) Updating.

@jrose-apple
Copy link
Contributor Author

Yeah, I'm not happy about the operator change, but it's justifiable and unlikely to interfere with anything else.

Like NSObject, CFType has primitive operations CFEqual and CFHash,
so Swift should allow those types to show up in Hashable positions
(like dictionaries). The most general way to do this was to
introduce a new protocol, _CFObject, and then have the importer
automatically make all CF types conform to it.

This did require one additional change: the == implementation that
calls through to CFEqual is in a new CoreFoundation overlay, but the
conformance is in the underlying Clang module. Therefore, operator
lookup for conformances has been changed to look in the overlay for
an imported declaration (if there is one).

https://bugs.swift.org/browse/SR-2388
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test macOS

@jrose-apple
Copy link
Contributor Author

Status not updated, but the tests are running.

@jrose-apple
Copy link
Contributor Author

Tests passed, force-merging.

@jrose-apple jrose-apple merged commit 361ab62 into swiftlang:master Aug 19, 2016
@jrose-apple jrose-apple deleted the Hashable-CF branch August 19, 2016 20:21
@gparker42
Copy link
Contributor

Reverting. New test Interpreter/SDK/cf.swift fails in two places when built with --test-optimized. I don't know if it's a bug here or a miscompile of this code.
https://ci.swift.org/job/oss-swift_tools-RA_stdlib-RD_test-simulator/2033/

Also reverting #4417 on the 3.0 branch.

@jrose-apple
Copy link
Contributor Author

Well, shoot. Thanks, Greg.

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.

8 participants