2 ms·
Swift has `@_noAllocation`: @_noAllocation func foo() -> Int { return [1,2,3].randomElement()! } fails with "error: Using type 'Int' can cause metadata all
by weissi 3mo ago
Swift has `@_noAllocation`:
@_noAllocation
func foo() -> Int {
return [1,2,3].randomElement()!
}
fails with "error: Using type 'Int' can cause metadata allocation or locks"
but
@_noAllocation
func foo() -> Int {
return 1 + 2 + 3
}
compiles fine.
- eatonphil 3mo agoThank you! I've made an edit crediting you. This also led me to notice the nonallocating attribute in Clang, which I've now mentioned as well.