Skip to content

Re-apply "Make all CF types Equatable and Hashable." #4568

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
May 8, 2017

Conversation

jrose-apple
Copy link
Contributor

This re-applies #4394, reverted in #4435, now that John has fixed CF casting logic in the optimizer. The round-trip casting test is also passing now.

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

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@DougGregor, @parkera, this is technically a source-breaking change since someone may have manually added Hashable or Equatable to a CF type. Then again, that's both a type and protocol they don't own, which isn't really safe because anyone could do it ("what if two people did this?"). Do you think we can commit this or do we have to be more circumspect?

@lattner
Copy link
Contributor

lattner commented Aug 31, 2016

This seems like acceptable risk to me.

// RUN: %target-run-simple-swift | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: objc_interop
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically only requires a platform where CF is part of the SDK, doesn't it?

What do you think about moving/copying this test in to Foundation and running it on all platforms?

@jrose-apple
Copy link
Contributor Author

I've found at least one case on GitHub where someone is doing exactly this on CFString, so it's definitely a source-breaking change. May have to wait until Swift 4.

Copy link

@thomasbarwanitz thomasbarwanitz left a comment

Choose a reason for hiding this comment

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

Thank you

Copy link

@thomasbarwanitz thomasbarwanitz left a comment

Choose a reason for hiding this comment

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

Thhhhxzzzzzzzzzz

@jrose-apple
Copy link
Contributor Author

Resurrecting this. It's almost certainly breaking, and we don't have a way to conditionalize it on Swift 3/4, but it is an improvement. What do people think?

@dabrahams
Copy link
Contributor

Even if this breaks somebody, it's really simple to fix. +1

@DougGregor
Copy link
Member

I'm definitely +1 on doing this

@jrose-apple jrose-apple force-pushed the Hashable-CF-take-2 branch 2 times, most recently from febd73e to ba1d754 Compare April 28, 2017 03:19
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

@jrose-apple
Copy link
Contributor Author

I still want to do a full test on Apple platforms but there's an error in one test right now.

@swift-ci Please smoke test

@jrose-apple jrose-apple force-pushed the Hashable-CF-take-2 branch 3 times, most recently from f1c1eb8 to f2ff372 Compare May 4, 2017 04:38
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented May 4, 2017

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

@jrose-apple
Copy link
Contributor Author

@akyrtzi, we're now running into the old issue where -include doesn't actually count as having included something (rdar://problem/22083824). Are you okay with the change to test/IDE/print_clang_header.swift to kick that can down the road a little further?

@jrose-apple jrose-apple force-pushed the Hashable-CF-take-2 branch from f2ff372 to e360e13 Compare May 4, 2017 15:30
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test macOS

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test Linux

@swift-ci
Copy link
Contributor

swift-ci commented May 4, 2017

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

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

1 similar comment
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

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).

This re-applies 361ab62, reverted in
f50b1e7, after a /very/ long interval
where we decided if it was worth breaking people who've added these
conformances on their own. Since the workaround isn't too difficult---
use `#if swift(>=3.2)` to guard the extension introducing the
conformance---it was deemed acceptable.

https://bugs.swift.org/browse/SR-2388
@jrose-apple jrose-apple force-pushed the Hashable-CF-take-2 branch from e360e13 to 631250b Compare May 8, 2017 17:43
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 01cb554 into swiftlang:master May 8, 2017
@jrose-apple jrose-apple deleted the Hashable-CF-take-2 branch May 8, 2017 21:05
jrose-apple added a commit to jrose-apple/swift that referenced this pull request May 8, 2017
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).

This re-applies 361ab62, reverted in
f50b1e7, after a /very/ long interval
where we decided if it was worth breaking people who've added these
conformances on their own. Since the workaround isn't too difficult---
use `#if swift(>=3.2)` to guard the extension introducing the
conformance---it was deemed acceptable.

https://bugs.swift.org/browse/SR-2388
stmitt added a commit to stmitt/BlueRSA that referenced this pull request Feb 9, 2021
dannys42 pushed a commit to Kitura/BlueRSA that referenced this pull request Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants