Skip to content
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

[SR-7865] swift-corelibs-foundation does not compile on macOS after 'as' bridging was merged #1579

Merged
merged 4 commits into from
Jun 7, 2018
Merged

Conversation

millenomi
Copy link
Contributor

@millenomi millenomi commented Jun 4, 2018

The new primitives are only available if Objective-C isn't. Guard them with #canImport(ObjectiveC).

(Additionally, see below for discussion.)

Resolves SR-7865.

@millenomi
Copy link
Contributor Author

@swift-ci please test

@millenomi
Copy link
Contributor Author

cc @spevans

@spevans
Copy link
Contributor

spevans commented Jun 4, 2018 via email

@spevans
Copy link
Contributor

spevans commented Jun 4, 2018 via email

@pushkarnk
Copy link
Member

@millenomi @spevans Can we have this merged please?

@millenomi
Copy link
Contributor Author

I forgot to run tests in Xcode; once I do today.

…y as AnyObject casts on Darwin, and move all code back to _SwiftValue.store/fetch.
@millenomi
Copy link
Contributor Author

@swift-ci please test

@millenomi
Copy link
Contributor Author

Here's what I found:

  • On Darwin, x as AnyObject can return the native _SwiftValue class, or Foundation.NSNull()where Foundation is the native framework from /System/Frameworks, not SwiftFoundation for nil values.

The solution is to prevent usage of as AnyObject in the SCF codebase — it is not safe to assume this expression returns a SwiftFoundation.NSObject all the time (as we instead guarantee on Linux). SCF code must use _SwiftFoundation.store() instead to produce a SwiftFoundation.NSObject; this patch uses SwiftFoundation.NSNull() and intercepts and substitutes native _SwiftValue boxes with SwiftFoundation._SwiftValue boxes.

This patch isn't done; we need to make sure that objects passed in by an author work, and to this extent I need to make SwiftFoundation._SwiftValue.fetch() able to unbox native _SwiftFoundation boxes.

@millenomi
Copy link
Contributor Author

After some experimentation: we can just return the native box from .fetch(), since it will be casted immediately afterward to the desired type.

@millenomi
Copy link
Contributor Author

@swift-ci please test

@millenomi
Copy link
Contributor Author

This addresses the latter point.

@millenomi
Copy link
Contributor Author

cc @spevans

@spevans
Copy link
Contributor

spevans commented Jun 7, 2018

Confirmed working on 2018-06-04 toolchain (macOS 10.13.5, Xcode 9.4) and Ubuntu 16.04.

@millenomi
Copy link
Contributor Author

@swift-ci please test

@millenomi
Copy link
Contributor Author

It’s breaking the SwiftPM build.

@millenomi
Copy link
Contributor Author

Investigating.

@millenomi
Copy link
Contributor Author

I cannot reproduce locally. Triggering a new build here in case it was transient.

@millenomi
Copy link
Contributor Author

@swift-ci please test

@millenomi
Copy link
Contributor Author

Found the issue:

We are implementing NSNull roundtrip in _SwiftValue.fetch(), but it is spurious. Darwin does not unpack NSNulls unless they are explicitly casted to an optional type:

let x: [Int?] = [nil]
print((x as [AnyObject]) as [Any]) // -> [<null>]
print(((x as [AnyObject]) as [Any]).map { type(of: $0) }) // -> [NSNull]

Since bridging already works on both platforms to unpack it in that case, we may want to stop explicitly unpacking it in our case. However, we need to figure out how to treat SwiftFoundation.NSNull in that case, since Darwin bridging will not unpack it. (A solution could be to make it _ObjectiveCBridgeable on Darwin only.)

@millenomi
Copy link
Contributor Author

I'm going to check if us not unpacking is enough to let things be unblocked while we work on a longer term solution (which hinges on whether we desire SCF to be used on Darwin as a general purpose library or not).

@millenomi
Copy link
Contributor Author

@swift-ci please test

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.

3 participants