Commits

Chris Lattner committed af7821e23a6
Implement a narrow but effective hack to dramatically reduce retains and releases produced by SILGen for non-@mutating struct methods. Before, we would retain the entire struct (which, if it contained class pointers would emit an actual retain operations) even when accessing only some part of it. Handle a special case where we just retain the accessed field. For example, this testcase: class C {} struct SomeStruct { var c : C var i = 42 func foo() -> Int { return i } } used to compile into: sil @_TFV2t210SomeStruct3foofS0_FT_Si : $@cc(method) @thin (@owned SomeStruct) -> Int64 { bb0(%0 : $SomeStruct): debug_value %0 : $SomeStruct // this retains "c" %2 = copy_value %0 : $SomeStruct %3 = struct_extract %2 : $SomeStruct, #i // this releases "c" destroy_value %2 : $SomeStruct // free the +1 argument. destroy_value %0 : $SomeStruct return %3 : $Int64 } now it produces: sil @_TFV2t210SomeStruct3foofS0_FT_Si : $@cc(method) @thin (@owned SomeStruct) -> Int64 { bb0(%0 : $SomeStruct): debug_value %0 : $SomeStruct // let self // id: %1 %2 = struct_extract %0 : $SomeStruct, #i // user: %4 destroy_value %0 : $SomeStruct // id: %3 return %2 : $Int64 // id: %4 } As mentioned, this is a narrow hack intended to specifically benefit String, a more general approach will come as I have time to implement it. Swift SVN r12658