This is a neat idea, and really inline with this post by @Ben_Cohen: [Pre-pitch] SwiftPM Manifest based on Result Builders - #28 by Ben_Cohen
Maybe you'd not declare a variable as const var
, but you'd need functions that can be executed at compile time:
func makeValue() const -> String { ... }
const value = makeValue()
I'm not sure "functions that can be executed at compile time" are part of the pitch, but they are a nice extension indeed.
For this, I think we'd need reconst
, or else we'd be quite crippled (not even able to perform string concatenation):
// New declaration of String concatenation in the stdlib:
func + (const lhs: String, const rhs: String) reconst -> String { ... }
// OK now
func makeValue() const -> String {
"foo" + "bar"
}