[Pitch] Custom Metadata Attributes

I think that through compiler evaluation we can unite a lot of features that are currently discussed separately. Both upthread and in the macro threads, forms of static introspection/reflection were discussed. Besides the static guarantee and optimization, I don’t see how that’s different from metadata-based runtime reflections.

This feature also doesn’t seem that motivating. Marking types with metadata attributes is very similar to protocol conformances, so I don’t see why we don’t introduce a function to fetch all types conforming to a protocol (like what Echo offers). Now, local declarations would have no metadata mechanism, but that’s arguably okay. As previously mentioned, property wrappers are very similar to metadata markers, and general reflection could be used to look up properties. These properties could then be filtered for the property-wrapping storage type. This still leaves functions, which would no way to be marked; for functions either the name could be looked up (again through reflection), or we could introduce the much requested function wrappers. I know the current test method naming was specifically discussed in the proposal, but I haven’t personally faced any problems with the “test”-prefixed methods and didn’t find the pitch’s arguments convincing.

All in all, I think we should focus our efforts on a comprehensive reflection system. This opens the door to declarative metaprogramming where the compiler can make smart decisions. For example, the user can declare they’re looking for types conforming to a test protocol. Then it’s up to the compiler whether to constant fold and potentially remove the type’s metadata, or to explicitly use runtime reflections (perhaps for better code size).

2 Likes