Codable Improvements and Refinements

Hi Itai,

It has been my dream for some time that we tackle this with a two step process.

  1. Introduce user-defined attributes. These would get @foo syntax (potentially with a prefix or some other distinguished syntax to get them out of the system attribute namespace). Such attributes would get encoded into the runtime metadata systems for decls for use by a future awesome reflection API. Ideally, some attributes such as the IB and core data attributes would switch to being library defined attributes instead of builtin (probably not possible for all of them until other language features come in).

  2. Introduce a way to define default protocol implementations as a macro, and allow that macro to iterate over stored properties (incl. their attributes). All of the synthesis stuff in the compiler (codable, but also equatable, hashable, and the stuff in the S4TF branch) could switch to using this, leading to a great reduction of special cases in the compiler, but also allowing more flexible patterns.

Allowing the macros to be conditionalized on the user defined attributes would allow you to achieve the stuff you're seeking without hacking it all into the compiler.

-Chris

19 Likes