Finding existentials for `any`

Now that Swift 5.6 is out, and the any keyword is available (but not yet mandatory) for marking existentials, are there any tools to help me identify places in my code where I can use it? I really like this feature and want to proactively update my code before Swift 6.

6 Likes

Wondering the same thing myself, actually. I was expecting to fix a gazillion warnings this morning, only to find none. :sweat_smile:
Edit: swift-evolution/0335-existential-any.md at main · apple/swift-evolution · GitHub

There isn't currently a way to turn on warnings for missing anys in your code. That's intentional; we're working on a lot of generics ergonomics features right now that may change the way programmers update their current use of existential types.

A lot of Swift code today uses existential types where it doesn't need to because existential types were the more natural thing to write. With opaque parameters and existential opening for function arguments that's being worked on right now, a lot of code can switch from an any type to a some type with better performance, fewer limitations, and the code behaving in the same way. When warnings are eventually added for missing any, we'll take these new features into account and suggest the best transition possible for the given code.

17 Likes

Heh, so you're saying I jumped the gun by eagerly applying them everywhere?

Oh well, at least this explicitness makes them really easy to audit! I'll comb through all the usages in the future and see if any can be replaced with opaque parameter types! :smiley:

1 Like