-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Port JSONEncoder overlay changes to swift-corelibs-foundation #1561
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
|
@parkera All the JSONEncoder tests are passing successfully.However, two tests ( |
Foundation/JSONEncoder.swift
Outdated
|
|
||
| /// Produce JSON with dictionary keys sorted in lexicographic order. | ||
| @available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) | ||
| @available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this reverts some earlier changes made to normalize the availability macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @saiHemak this needs to match the version in the overlay: https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/JSONEncoder.swift#L35
| ("test_PersonNameComponents_JSON", test_PersonNameComponents_JSON), | ||
| ("test_UUID_JSON", test_UUID_JSON), | ||
| ("test_URL_JSON", test_URL_JSON), | ||
| // ("test_URL_JSON", test_URL_JSON), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll need to figure out the root cause of these before we can do a final merge. What were the failures you were seeing? Any clue as to what's causing them to fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, the two tests that now fail here are the only two tests in TestCodable that fail when run against Darwin's native foundation, so the tests could be wrong (although they don't look to be).
|
@millenomi is working on bringing bridging to SCL-foundation in parallel, so we may be able to simplify this patch if we can get that to land first. |
|
@parkera Sure ..Thanks .. |
|
Now that #1526 is merged we should rework this - hopefully it's easier now! |
|
Thanks @millenomi for the work on bridging. @ianpartridge I am working on this PR with bridging changes in place |
|
@saiHemak A thing that may not be obvious and I need to document is that you still need to use _SwiftValue.store()/.fetch() in the bridging code for this class to avoid bringing in non-Swift Foundation values when this code runs on Darwin. |
2946c2d to
8c78bea
Compare
|
@swift-ci please test |
Foundation/JSONEncoder.swift
Outdated
|
|
||
| fileprivate mutating func popContainer() -> NSObject { | ||
| precondition(!self.containers.isEmpty, "Empty container stack.") | ||
| precondition(self.containers.count > 0, "Empty container stack.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// - returns: A value of the requested type. | ||
| /// - throws: `DecodingError.dataCorrupted` if values requested from the payload are corrupted, or if the given data is not valid JSON. | ||
| /// - throws: An error if any value throws an error during decoding. | ||
| open func decode<T : Decodable>(_ type: T.Type, from data: Data) throws -> T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function looks very different to the overlay - https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/JSONEncoder.swift#L1102 ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have applied overlay changes on top of #1347. However still this implementation depends on bridgeToObjectiveC instead of ConevertedKey method.Hence only the changes pertaining to the ConvertedKey have been ignored.
fb8688f to
340727c
Compare
|
@ianpartridge please review |
|
Hi @itaiferber this is our latest effort to update |
itaiferber
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Content-wise, this looks good! My main question is: given the state of bridging on Linux right now, what (if anything) is now preventing us from merging the implementations? (/cc @millenomi as well)
Foundation/JSONEncoder.swift
Outdated
| fileprivate func box<T : Encodable>(_ value: T) throws -> NSObject { | ||
| return try self.box_(value) ?? NSDictionary() | ||
| } | ||
| //This method is called "box_" instead of "box" to disambiguate it from the overloads. Because the return type here is different from all of the "box" overloads (and is more general), any "box" calls in here would call back into "box" recursively instead of calling the appropriate overload, which is not what we want. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny style nit: missing newline before comment and space after //
Foundation/JSONEncoder.swift
Outdated
| overflow = true | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another tiny nit: unless GitHub's diff view is showing the new comment incorrectly, looks like the actual code here should be reformatted along with the new indentation.
340727c to
8cb7f29
Compare
8cb7f29 to
3c33746
Compare
|
Unfortunately we need slightly different code because the bridging syntax on Darwin can produce Darwin Foundation objects — cfr. |
|
@swift-ci please test |
|
@millenomi Got it. How much do we support running s-cl-f on Darwin? (Makes sense for testing but also feels a bit unfortunate that it prevents us from unifying these sorts of things right now.) |
|
For the record, the result of that discussion so far is:
thus it's not acceptable to break it on Darwin. The longer-term solution is to move the compile-time conditionals for Linux bridging to be runtime checks, so that we can e.g. have a |
|
@millenomi Fair enough, and sounds good! This is one such place that suffers in our code due to the bridging split, so if we can get to source stability internally it'll make things significantly easier to apply from the overlay, and vice versa. |
|
@millenomi I agree that SCF on Darwin only has value for developing SCF itself (inside Xcode) which is easier than on Linux. Maybe an alternative solution is to build an Xcode toolchain with This should mean that any bridging code that has to work with the ObjectiveC runtime can be removed and reduces the maintenance burden for SCF on Darwin. A secondary advantage may be that anyone targeting Swift on the (Linux) Server can use it to develop in Xcode using SCF so there are no surprises when they move to their code to Linux as the Im not sure if a toolchain can be built with |
|
Building a toolchain with There is little value in bifurcating the toolchain builds, though. It is infinitely more valuable to have a single toolchain that can be set up to understand either mode (so, turning the |
|
@swift-ci please test |
|
To summarize the thread: we can pursue the objc interop discussion separately because it can't be resolved in this particular PR. |
This PR is based on PR #1347 by @parkera .
@parkera I have applied some bridging fixes on top of your PR to make the tests pass.