Is it possible to restrict T in such a way that I am not getting this error?
(I only plan to use it with POD value types)
// -experimental-performance-annotations
struct Test<T> {
var x: T?
@_noLocks
init() {}
// ๐ error: Using type 'Test<T>' can cause metadata allocation or locks
}
As currently implemented, you have to apply @_noLocks to the caller of generic APIs, not to generic APIs themselves, since applying them to the generic function will attempt to restrict the unspecialized version of the generic function.
// -experimental-performance-annotations
@_noLocks
func foo<T>(_ v: T?) -> T {
if let v { // ๐ Using type 'T' can cause metadata allocation or locks
return v
}
while true {}
}
Ditto with a custom optional:
// -experimental-performance-annotations
enum MyOptional<Wrapped> {
case none, some(Wrapped)
}
@_noLocks
func foo<T>(_ v: MyOptional<T>) -> T {
switch v { // ๐ Using type 'MyOptional<T>' can cause metadata allocation or locks
case .none: while true {}
case let .some(v): return v
}
}
or just this:
// -experimental-performance-annotations
@_noLocks
func foo<T>(_ v: T) -> T {
v // ๐ Using type 'T' can cause metadata allocation or locks
}