[Pitch] Compile-Time Constant Values

This kind of inhabits a different space. To be honest, there is very little reason to use StaticString these days over a regular String, as the regular String is initialized with a pointer to a string in the const section and won't perform any reference counting. There may be a teeny tiny edge because at runtime StaticString doesn't even need to check if it's in this form – but the need is so small that if StaticString didn't exist today, I don't think it would be worth proposing.

But what's being pitched here is one step more constant, because while a StaticString itself is static, the value of a StaticString variable isn't:

struct Bar {
  let greeting: StaticString = Bool.random ? "Hello" : "Goodbye"
}

The goal of const here is to guarantee the value of greeting is known at compile time, unlike in this example.

10 Likes