5.9: [ClosureSpecializer] Don't release trivial noescape try_apply argument twice. #66274
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description: ClosureSpecializer creates releases for the closure passed as an parameter to a
try_apply
that is specialized. These releases are created in (1)ClosureSpecCloner::populateCloned
and (2)rewriteApplyInst
, depending on the effective ownership of the closure: in (1) they are inserted for closures passed without an increment of the retain count (done e.g. for closures passed as an@guaranteed
parameter); in (2) they are inserted for closures passed with an increment of the retain count (done e.g. for closures passed as an@owned
parameter).Among the closures that are passed without an increment of the retain count are those which are noescape (
SILFunctionType::isTrivialNoEscape
). That is true even when the closure is passed as an@owned
parameter. The condition of (1) under which releases are added for the closure correctly included consideration of theisTrivialNoEscape
predicate of the closure's type; consequently that code inserts releases in both of thetry_apply
's destination blocks. The condition of (2) under which releases were added for the closure incorrectly failed to consider theisTrivialNoEscape
predicate; consequently, that code also inserted releases in both of the destination blocks. The result was adding two releases in each destination block, one of each of which was an overrelease.The fix is just to consider the
isTrivialNoEscape
predicate in (2).Risk: Low. The patch adds a predicate to the bailout condition of (2) that complements an existing use of the same predicate in the condition of (1).
Scope: Narrow. This only affects releases for noescape closures passed as owned arguments to
try_apply
s which are specialized.Original PR: #66263
Reviewed By: Erik Eckstein ( @eeckstein ), Arnold Schwaigofer ( @aschwaighofer )
Testing: Added test case that previously inserted double release.
Resolves: rdar://110058964