-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[SR-2384] remove NSUniqueObject #563
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
The one differential here is that NSUniqueObject did allow non hashable items to be stored whereas AnyHashable conversion will not store a non hashable item |
@swift-ci Please test linux and merge |
@swift-ci Please test and merge |
Not since aa504dc though. |
A bigger issue is whether we can encode non-NSObjects. Trying to do so causes some crashes, Any not supporting AnyHashable by default is one of them but there are a few others. Investigating. (I guess we don’t have this on Darwin because as far as ObjC is concerned, everything is a NSObject?)
|
@phausler, we can fix this regression by boxing with _SwiftValue – does this make sense? It is only useful in conjunction with some other (pending) fixes to support encoding of non-NSObjects. |
We don't need to encode non-NSObjects (especially not structs). It's not something supported on Darwin, at least. |
Ah, I thought the Any API change implied Darwin supported it. Well, there’s a patch in PR 574, see which bits are useful – in any case, there could be better error reporting for encoding non-NSObjects (owing to a bug it crashes before reporting that non-NSObjects cannot be encoded). Also, should value types (e.g. UUID) be transparently bridged? Best to continue this on aforementioned pull request or SR-2416.
www.lukehoward.com |
What'll happen is that the internal |
As for the value types, we probably have some work to do here to covert them into their object types when passed to keyed archiver. @phausler was making sure that the swift-corelibs-foundation |
This is for value types, right? What happens if you encode, say, [1, 2, 3] on Darwin, will it work or crash? In the case of classes that do not explicitly subclass NSObject (but implement NSCoding), presumably these work on Darwin by implicitly subclassing NSObject (because NSCoding is @objc)? So in order to have source compatibility where ObjC is not available, we’d want to support arbitrary classes implementing NSCoding. |
Right, I was a little uncertain as to which things the compiler does implicitly (and on which platforms). The patch in #574 will do this. |
If you encode I'm not super concerned about supporting a use case of not subclassing |
On Darwin, if you do: class Foo : NSCoding { it will be implicitly a subclass of NSObject, right, because NSCoding is @objc? Whereas without the ObjC runtime this wouldn't be the case. That was the use case I was referring to. |
In any case, if we don't want to support this use case I'll at least clean it up so that it fatalErrors in a useful place (indicating the problem at runtime). |
Ah, I see. Yah I'm still ok with not supporting that. =) |
When you have a chance please review #574 and see which bits you want me to ditch :) |
[pull] swiftwasm from main
NSKeyedArchiver uses an internal struct, NSUniqueObject to box unhashable objects so they may be used as dictionary keys. AnyHashable, if my understanding is correct, obviates the need for this.