Skip to content

Conversation

@dgrove-oss
Copy link
Contributor

What's in this pull request?

Resolved bug number: (SR-)


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
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

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

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

Make the ObjectiveCBridgeable protocol available
and minimal pieces of the runtime support for it
available even without an ObjectiveC runtime.
This is motivated by supporting bridging in
swift-corelibs-foundation on Linux via the
compiler/runtime support provided by
ObjectiveCBridgeable.

@dgrove-oss
Copy link
Contributor Author

@parkera
Copy link
Contributor

parkera commented Apr 1, 2016

The idea here is to start work on enabling bridging to work on all platforms equally.

Copy link
Contributor

Choose a reason for hiding this comment

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

This entry point should not be needed on the native runtime. There are no unknown objects in the native runtime, all objects are Swift objects.

@dgrove-oss
Copy link
Contributor Author

I enabled two existing test cases on Linux that touch on ObjectiveCBridgeable. My original thinking is that most of the testing of the functionality would be done as part of testing swift-corelibs-foundation.

@gribozavr
Copy link
Contributor

Sorry, but we can't rely on other repositories for complier and standard library testing.

@dgrove-oss
Copy link
Contributor Author

It's unfortunate that many of the test cases already in swift/tests for ObjectiveCBridgeable import Foundation (grep 'import Foundation' in tests/1_stdlib). It would be nice to simply be able to start enabling them on Linux using swift-corelibs-foundation.

@jckarter
Copy link
Contributor

jckarter commented Apr 1, 2016

Do we want bridging to work on Linux? If corelibs Foundation is written mostly in Swift, and is doing things like widening AnyObject to Any to better interop with arbitrary native Swift types, a lot of our motivation for bridging on Apple platforms goes away.

@dgrove-oss
Copy link
Contributor Author

My understanding from Tony is that the goal (which maybe is just a medium-term tactical improvement, not the ultimate destination) is that we want to reduce the cross-platform differences in bridging. On Linux, we will be bridging between two Swift types (eg String and NSString), but we want the end user program to look the same (someStr as NSString should just work).

@jckarter
Copy link
Contributor

jckarter commented Apr 1, 2016

Fair enough, I can see the desire for functional parity. I would hope long term we can reduce the need for the runtime magic, though ObjectiveCBridgeable remains useful for static bridging of imported C/ObjC interfaces.

@parkera
Copy link
Contributor

parkera commented Apr 1, 2016

swift-corelibs-foundation isn't actually written mostly in Swift, it's written mostly in C (via CoreFoundation). This includes things like plist parsing. They are creating CFTypeRefs (which we've laid out like SwiftObjects), but having to go through a manual conversion instead of having our usual bridging in place is pretty expensive.

@jckarter
Copy link
Contributor

jckarter commented Apr 1, 2016

IIUC, that isn't what this provides though; to avoid the manual conversion, you'd need to implement support in Array/Dictionary/etc. to be able to carry a bridged CFArray/CFDictionary/etc. Otherwise, the Bridgeable implementation would still have to do the expensive copy anyway, wouldn't it?

@dgrove-oss
Copy link
Contributor Author

Optimistically squashed into a single commit and updated the commit comment to indicate that the change is also enabling the handful of existing testcase for ObjectiveCBridgeable that don't require Foundation or Objective-C to pass (all pass in my Linux environment with this change).

Make the ObjectiveCBridgeable protocol available
and minimal pieces of the runtime support for it
available even without an Objective-C runtime.
This is motivated by supporting bridging in
swift-corelibs-foundation on Linux via the
compiler/runtime support provided by
ObjectiveCBridgeable.

Also enable the six existing testcases for
ObjectiveCBridgeable that don't import Foundation
or truly rely on an Objective-C runtime being present.
@dgrove-oss
Copy link
Contributor Author

rebased to master as of 4/25

@dgrove-oss
Copy link
Contributor Author

@gribozavr @parkera I've rebased to refresh the change set. I think this is ready to go....anything else we need to do? Thanks.

@dgrove-oss
Copy link
Contributor Author

@parkera Any feedback from the Swift core team on whether reusing ObjectiveCBridgeable like this on Linux is going to fly?

@parkera
Copy link
Contributor

parkera commented May 6, 2016

Hm, nothing yet. @gribozavr, @dabrahams, @DougGregor : can you help weigh in on this? It obviously became more important due to SE-0069.

@dabrahams
Copy link
Contributor

@parkera, the code looks basically OK to me. Forgive my cluelessness, but what, specifically, are you asking us to weigh in on? “Whether reusing ObjectiveCBridgeable like this on Linux is going to fly” seems like a big open-ended question to me, and though I’ve read the foregoing comments I’m not sure I understand what we’re trying to accomplish.

@jckarter
Copy link
Contributor

jckarter commented May 6, 2016

If we accept SE-0083, we wouldn't need this runtime magic. The bridging conversions could then be provided as normal API.

@parkera
Copy link
Contributor

parkera commented May 6, 2016

@dabrahams I'll try to make this more concrete. Today, the bridging code here is guarded by the presence of ObjC interop. However, in order to make things like NSData -> struct Data work on Linux, we will need the bridging to work there as well. This was already the case for NSArray -> struct Array, but by adding a lot of new bridged types in Foundation, it became a more pressing problem to solve.

@parkera
Copy link
Contributor

parkera commented May 6, 2016

@jckarter if you think SE-0083 will solve this then I am willing to wait a few more days.

@DougGregor
Copy link
Member

There's a much larger design point here. Bridging between values and objects is an important part of Objective-C interoperability (this is part of the discussion to be had for SE-0083), but it doesn't necessarily belong in Swift when there isn't an Objective-C runtime.

@parkera
Copy link
Contributor

parkera commented May 9, 2016

@DougGregor you're clearly aware of how important the ability to bridge is for the Foundation value types work, but without support on Linux we will introduce an even larger source incompatibility between platforms. What is your proposed solution to that?

@colemancda
Copy link
Contributor

I think this behavior is not needed on Linux, and instead the Corelib Foundation library should be adapted to use value types. I would like to contribute to that, where can I start?

@dgrove-oss
Copy link
Contributor Author

Not needed; closing.

@dgrove-oss dgrove-oss closed this Aug 17, 2016
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.

7 participants