<div dir="ltr"><div>if it wasn't already discussed here is the preliminary proposal, if it was then my +1 to the feature.</div><div><br></div><div>i propose we have an explicit apparatus to denote classes having stack storage.</div><div><br></div><div>stack class StackObject { // guaranteed to be on stack</div><div>}</div><div><br></div><div>class NonStackObject { // is not guaranteed to be on stack, can be on heap as well</div><div>}</div><div><br></div><div>this is for performance reasons. sometimes what we need is “structs with deinit” and as this is not going to happen the next best thing could be “lightweight” classes. this shall be self obvious, here are few examples:</div><div><br></div><div>stack class StackObject {</div><div> var variable = 0</div><div><br></div><div> func foo() {</div><div> print(“i am ok to live on stack”)</div><div> }</div><div>}</div><div><br></div><div>stack class BadObject {</div><div> var variable = 0</div><div><br></div><div> func foo() {</div><div> DispatchQueue.main.async { // error: can’t be a stack class</div><div> self.variable = 1</div><div> }</div><div> }</div><div>}</div><div><br></div><div>class NonStackObject {</div><div> …</div><div>}</div><div><br></div><div>foo() {</div><div> let stackObject = StackObject()</div><div><br></div><div> DispatchQueue.main.async {</div><div> stackObject.foo() // error: can’t use a stack object in this context</div><div> }</div><div>}</div><div><br></div></div>