Regarding the "Protocol @const
property" aspect of the proposal, I'm struggling to see the motivation.
If the intent is to enforce that the property's value is "static" (eg, make sure the database keys or printf-string are not runtime-able values), then that should be expressed in the type, as you'd want to propagate this quality through function calls, even if you select among values at runtime (flag ? key1 : key2
). Expressing frozen/static typing is interesting and useful independent of this proposal.
If the intent is to enforce that the value doesn't change for an instance/class (eg, the property will be used as a key in a dictionary or an input to a hash that should be stable), then that is an interesting direction! But I would propose that we should implement that independent of any "build-time-ness" requirement as it's more generally useful.
For example, the proposal offers an example:
protocol NeedsConstGreeting {
@const static let greeting: String
}
It's not clear what @const
actually adds here. Wouldn't just plain static let greeting: String
express the interesting part? You could even use StaticString
to cover the other axis too.
I suggest the authors expand the proposal with a more concrete example that actually relies on the compiler doing something interesting at build time for the protocol property use-case.