Commits

Michael Gottesman committed b80c96a2e7b
[+0 self] Teach SILGen how to avoid emitting extra rr pairs when emitting RValues with Nominal Types and Tuples. Specifically this patch makes the following changes: 1. We properly propagate down the SGFContext of a tuple to its elements when extracting from a tuple. There was a typo that caused us to use data from the newly created default initialized copy instead of from the actual SGFContext of the parent tuple. 2. If we are accessing a member ref of self in a guaranteed context: a. If self is a struct, regardless of whether or not the field is a var or a let we no longer emit a retain. This is b/c self in a guaranteed context is immutable. This implies even a var in the struct can not be reassigned to. b. If self is a class, if the field is a let, we no longer emit an extra retain. This makes it so that the only rr traffic in IntTreeNode::find is in the block of code where we return self. class IntTreeNode { let value : Int let left, right : IntTreeNode init() {} // not needed for -emit-silgen func find(v : Int) -> IntTreeNode { if v == value { return self } if v < value { return left.find(v) } return right.find(v) } } One gets the same effect using a struct for IntTreeNode and a generic box class, i.e.: class Box<T> { let value: T init(newValue: T) { value = newValue } } class Kraken {} struct IntTreeNode { let k : Kraken // Just to make IntTreeNode non-trivial for rr purposes. let left, right : Box<IntTreeNode> init() {} // not needed for -emit-silgen func find(v : Int) -> IntTreeNode { if v == value { return self } if v < value { return left.value.find(v) } return right.value.find(v) } } There is more work that can be done here by applying similar logic to enums, i.e. switching on self in an enum should not generate any rr traffic over the switch. Also it seems that there are some places in SILGen where isGuaranteedValid is not being propagated to SILGenFunction::emitLoad. But that is for another day. I am going to gather data over night and send an email to the list. rdar://15729033 Swift SVN r27632