[Pitch] Custom Metadata Attributes

Having used attribute-based patterns in other languages (Java, Kotlin), this seems rather antithetical to Swift's common approach of compile time verification. Attribute-based programming suffers in readability, reasonability, debugability, and documentability. It's an obvious solution to the motivating problems, and well precedented in other languages, but these patterns are also kind of hated in those languages, especially by newer programmers. Is there no other solution to these problems?

Aside from my fundamental concerns, the proposal seems rather under specified in regards to how these attributes interact with other attributes and attribute-like constructs. What do these things see when attached to @MainActor or @SomePropertyWrapper? How does ordering impact things?

There's also no notion of how it applies to async constructs. There doesn't seem to be any initializers that deal with them. I would hope we wouldn't introduce any new features that don't work with async, especially while existing features, like property wrappers or dynamic member lookup, don't.

Additionally, I'm wary of adding yet another attribute type when the tooling for other attribute types is still so poor. Is there anything, generally, that can be done to give these sorts of things a better experience out of the box? I know that sort of thing isn't supposed to be part of the proposals, but the situation is getting dire and I'd rather not add yet another Swift feature that has no compiler guidance for implementation.

(As a general aside, I'd really like to see Swift's existing feature set fleshed out, especially concurrency, rather than introducing a bunch of new features.)

11 Likes