I work for Facebook on Swift adoption and recently we faced a case where it makes sense for us to be able to enable reflection metadata selectively.
At this moment, the only option is to keep it enabled/disabled for a whole module without fine-grained options to control it.
-disable-reflection-names also doesn't help much, saving up only several bytes of binary size.
Therefore, we'd like to start a discussion about implementing that feature upstream.
Currently, I see two ways:
After reading some threads on the forum I saw a few mentions about some new Reflection API which is pretty desirable, but not a lot of work is done in that direction yet. I think the best option would be to support Pay-For-What-You-Use in the design of a new API.
To create an addition for current API:
Introduce a new flag
-enable-selective-reflection-metadataand some options to let the compiler know which types require enabled metadata like:
- Custom attribute for a declaration.
- Introduce a new protocol like
- Reusing an existing protocol like
While the first option is definitely better in long term, the further direction of Reflection evolution is not clear, Reflection Manifesto doesn't exist yet and the implementation can take a lot of time.
The second approach looks not so great as the first one but can help a lot for teams that care about binary size. Moreover, it doesn't seem very difficult and time-consuming from implementation point of view.
Any opinions on that?
Do you think it would be a good feature to have in the Language?