-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[RFC] Restore using __SwiftValue in store on Linux #2500
Conversation
CC: @millenomi |
@swift-ci please test |
Wait, how does this solve the problem? |
Before #1526 you could never cast [T] to a NSArray without an explicit __SwiftValue.store(), so the commit message makes little sense to me. |
@millenomi I was recently checking a dynamic cast issue (made a test here #2874) and it looks related to code mentioned in this patch.
The stack trace leads exactly to
The last trace of crash in Foundation is Bridging.swift:199. Applying this patch fixes the crash in my test, and allows it to pass. Could you please revisit this? Maybe with additional context it would make more sense. |
I'm very confused because casting [T] to a NSArray for some T should produce a NSArray of T-containing __SwiftValues, and also because you're eliminating the Darwin special handling that was there to prevent us from messing up when we were double-boxing (wrapping a T in a Darwin Foundation NSObject and then trying to access it as a SwiftFoundation NSObject.) tl;dr: I need to be explained why the patch fixes the problem of NSArray failing to bridge the Ts to __SwiftValue boxes, rather than just avoiding a crash. |
Just to be sure:
is the expected result, right? What I see is happening in current code:
I.e. it actually tries to do what we expecting: produce a
For non-Darwin there is no additional checks, and we are just doing forced cast:
This cast crashes when value is not NSObject. What this patch suggests, is to make Darwin part not only for Darwin, but "unlock" it for all platforms, as there we have explicit wrapping into Sadly, I am not familiar with mechanics of Swift bridging and casting. For me non-Darwin part even not tries to wrap value into |
Ah, whoops — turns out you're correct on all counts, and I just didn't make the connection there. You are also correct to note that a non-NSObject result of (x as AnyObject) can and does exist. Let's just fix your conflicts and take this patch; it is correct. |
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |
Currently bridging may crash on
as!
if you try to cast[T]
toNSArray
where T is not inherit from of NSObjectBefore #1526 such cases covered by boxing into __SwiftValue. This change restores that behavior