Commits
Chris Lattner committed 7d9ae2f4189
Use the power of ManagedValue to pass along +1 ownership of the base
receiver until something consumes it. This means that something with
writeback (which invokes both the getter and setter) needs to copy the
managed value (since two things consume the +1), but that's what
ManagedValue is for.
Upshot of this is that we stop emitting redundant retain/release calls
in cases where writeback isn't needed. For example:
class Foo {
var x : Int { get: set: }
}
func test(let f : Foo, let i : Int) {
f.x = i
}
used to silgen to:
sil @_TF1t4testFTCS_3FooSi_T_ : $@thin (@owned Foo, Int64) -> () {
bb0(%0 : $Foo, %1 : $Int64):
strong_retain %0 : $Foo // id: %2
strong_retain %0 : $Foo // id: %3
// function_ref t.Foo.x.setter : swift.Int64
%4 = function_ref @_TFC1t3Foos1xSi : $@cc(method) @thin (Int64, @owned Foo) -> () // user: %5
%5 = apply %4(%1, %0) : $@cc(method) @thin (Int64, @owned Foo) -> ()
strong_release %0 : $Foo // id: %6
strong_release %0 : $Foo // id: %7
%8 = tuple () // user: %9
return %8 : $() // id: %9
}
now it silgen's to:
sil @_TF1t4testFT1fCS_3Foo1iSi_T_ : $@thin (@owned Foo, Int64) -> () {
bb0(%0 : $Foo, %1 : $Int64):
strong_retain %0 : $Foo // id: %2
// function_ref t.Foo.x.setter : swift.Int64
%3 = function_ref @_TFC1t3Foos1xSi : $@cc(method) @thin (Int64, @owned Foo) -> () // user: %4
%4 = apply %3(%1, %0) : $@cc(method) @thin (Int64, @owned Foo) -> ()
strong_release %0 : $Foo // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
}
When writeback is needed, we still emit the two retains (balanced with the
get and set calls).
Swift SVN r11854