mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Otherwise the code as written miscompiles code like:
```
@inline(never)
func consumeSelf<T>(_ t : __owned T) {
print("Consuming self!")
print(t)
}
class Klass {}
struct S<T> {
let t: T? = (Klass() as! T)
@inline(__always)
__consuming func foo(_ t: T) {
consumeSelf(self)
}
}
public func test<T>(_ t: __owned T) {
let k = S<T>()
let f = k.foo
for _ in 0..<1024 {
f(t)
}
}
test(Klass())
```
As one can tell, without annotations it is hard to create an example like the
above, but there is no reason why we couldn't emit more code like this from the
frontend.
If the parameter is guaranteed though, the current impl is fine for
@in_guaranteed since in the loop, we do not need to retain or release the
value.
rdar://58885352
31 lines
433 B
Swift
31 lines
433 B
Swift
// RUN: %target-run-simple-swift(-Osize)
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
@inline(never)
|
|
func consumeSelf<T>(_ t : __owned T) {
|
|
print("Consuming self!")
|
|
print(t)
|
|
}
|
|
|
|
class Klass {}
|
|
struct S<T> {
|
|
let t: T? = (Klass() as! T)
|
|
|
|
@inline(__always)
|
|
__consuming func foo(_ t: T) {
|
|
consumeSelf(self)
|
|
}
|
|
}
|
|
|
|
public func test<T>(_ t: __owned T) {
|
|
let k = S<T>()
|
|
let f = k.foo
|
|
|
|
for _ in 0..<1024 {
|
|
f(t)
|
|
}
|
|
}
|
|
|
|
test(Klass())
|