[swift-evolution] [Proposal Draft] Flexible memberwise initialization

Félix Cloutier felixcca at yahoo.ca
Tue Dec 22 13:38:14 CST 2015


> Problem 2: This can cause very surprising performance issues, because it forces the let property to be stored.  With the previous example, it is a goal for us to be able to compile:
> 
> public class X {
>   let a = 42
> }
> 
> into the equivalent of:
> 
> public class X {
>   var a : Int { return 42 }
> }
> 
> because people like to use local lets as manifest constants (avoiding “magic numbers”).  With your proposal, we’d lose this capability, and we’d have to store them any time there is a memberwise initializer.
> 
> Neither of these problems apply to vars, which is why I think we can support vars in this model, but not lets.

Sorry to sidetrack the discussion, but does that mean that using `let` properties in a type where memory layout is important is possibly not forward-compatible?

Félix


More information about the swift-evolution mailing list