-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Dynamic Casting] Overhauled Runtime #33561
[Dynamic Casting] Overhauled Runtime #33561
Conversation
This is a completely refactored version of the core swift_dynamicCast runtime method. This fixes a number of bugs, especially in the handling of multiply-wrapped types such as Optional within Any. The result should be much closer to the behavior specified by `docs/DynamicCasting.md`. Most of the type-specific logic is simply copied over from the earlier implementation, but the overall structure has been changed to be uniformly recursive. In particular, this provides uniform handling of Optional, existentials, Any and other common "box" types along all paths. The consistent structure should also be easier to update in the future with new general types. Benchmarking does not show any noticable performance implications. **Temporarily**, the old implementation is still available. Setting the environment variable `SWIFT_OLD_DYNAMIC_CAST_RUNTIME` before launching a program will use the old runtime implementation. This is only to facilitate testing; once the new implementation is stable, I expect to completely remove the old implementation.
The old `tryCastFromNil` could never fail (hence doesn't need to "try") and doesn't need all the arguments we were giving it.
We know this memoization makes a big difference for String, but the wins for Dictionary are less clear. It's easy to add it back later if it proves helpful.
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 got partway through reviewing this today and thought I'd send the comments I have so far. More to come, presumably.
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.
Read through the rest of it. Didn't see a whole lot!
Overall, this looks fantastic. It's very clear, both in details and in the overall structure. I definitely feel like I'd be able to take a bug report and go straight to the relevant code, rather than stepping through line by line waiting to see where something went wrong like I often did with the old code. Thanks very much for taking this on and seeing it through.
Clarify the unreachable messaging a bit: * "Unexpected" means I knew about it but thought it could never appear here * "Unknown" means I didn't know about it when I wrote this code
@swift-ci Please test |
Build failed |
Looks like I failed to properly mark some code that depends on Obj-C interop. |
@swift-ci Please test |
Build failed |
Linux had an unexpected "PASS" of some of the casting tests because of a mis-match between build optimizations. The test in question should not be marked as XFAIL for optimized mode, because it ignores the test mode and always builds without optimizations. (It always builds without optimizations because the point of the test is to exercise runtime functions that are not called when the compiler can optimize the cast in question.) I've removed the XFAIL marker. |
@swift-ci Please test |
Build failed |
Invalid SHA |
Build failed |
Also invalid SHA |
@swift-ci Please test Windows platform |
@swift-ci Please test |
@swift-ci Please benchmark |
@swift-ci Please test Windows platform |
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
Build failed |
@swift-ci Please test |
This is a completely refactored version of the core swift_dynamicCast
runtime method. (Separated out from PR #29658 )
This fixes a number of bugs, especially in the handling of multiply-wrapped
types such as Optional within Any. The result should be much closer to the
behavior specified by
docs/DynamicCasting.md
.Most of the type-specific logic is simply copied over from the
earlier implementation, but the overall structure has been changed
to be uniformly recursive. In particular, this provides consistent
handling of Optional, existentials, Any and other common "box"
types along all paths. The consistent structure should also be
easier to update in the future with new general types.
Benchmarking does not show any noticable performance implications.
Temporarily, the old implementation is still available. Setting the
environment variable
SWIFT_OLD_DYNAMIC_CAST_RUNTIME
before launching a programwill use the old runtime implementation. This is only to facilitate testing;
once the new implementation is stable, I expect to completely remove the old
implementation.
Partially Resolves: SR-1999 SR-2289 SR-4552 SR-6126 SR-8964