Commits

Michael Gottesman committed 0d0285bc53d
[closure-specializer] Fix various parts of the closure specializer. Before this commit the closure specializer was broken in the following ways: 1. We assumed that the closure was always passed in at +1. This meant that we would leak the closure in guaranteed contexts. 2. For correctness reasons we were relying on the closure having only one user, the apply to the function we were going to specialize. This was important since we reused the retain of the partial apply's captured arguments as the @owned retain for each of the captured variables at the specialized callsite. If one has multiple such specializations then one needs to insert additional retains for each capture for each specialization. Since the partial_apply only had one use and consumed the captured arguments, the partial_apply could always be eliminated and we could rely on the new partial apply in the specialized function to consume the captured arguments. If a partial_apply has multiple uses then there are extra retain, releases. We need to be able to identify the set of post-dominating releases of the closure and insert releases of the captured arguments at those points. 3. The captured parameters signature in the specialized function was not being set appropriately to be +1. If it was passed in @guaranteed or unowned into the closure's callee function, we would reuse that signature instead of changing it to @owned. We /were/ balancing the ref counts correctly though as mentioned before by reusing the retains resulting from the captured arguments being passed into the partial apply. Now the algorithm works as follows: 1. We are no longer attempting to perform a "move" of the closure into the specialized function. Instead we now perform a "copy". This means that we have two phases to our algorithm. First we "copy" the closure into the specialized function and balance out all of the relevant reference counts for the original closure and the closure's captured arguments. 2. Then we attempt to eliminate the original closure if it is dead. For more information see the large comment at the top of ClosureSpecialization. I also consolidated some tests as well. rdar://19723829 Swift SVN r25052