Skip to content

Fix two problems with withoutActuallyEscaping #78885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Jan 24, 2025

1. let withoutActuallyEscaping also catch an escaping closure in the throwing case.

withoutActuallyEscaping checks that the passed closure has not beed escaped by ensuring that its reference count is exactly 1 at the end of the code block.
So far this was only done in the regular return case. But if the code block throws, the check was not done.

Fixes an undetected undefined behavior.

2. replace the is_escaping_closure instruction with destroy_not_escaped_closure

The problem with is_escaping_closure was that it didn't consume its operand and therefore reference count checks were unreliable.
For example, copy-propagation could break it.
As this instruction was always used together with an immediately following destroy_value of the closure, it makes sense to combine both into a destroy_not_escaped_closure.
It

  1. checks the reference count and returns true if it is 1
  2. consumes and destroys the operand

This is part of rdar://140229560.

… the throwing case

withoutActuallyEscaping checks that the passed closure has not beed escaped by ensuring that its reference count is exactly 1 at the end of the code block.
So far this was only done in the regular return case. But if the code block throws, the check was not done.

Fixes an undetected undefined behavior.
…escaped_closure`

The problem with `is_escaping_closure` was that it didn't consume its operand and therefore reference count checks were unreliable.
For example, copy-propagation could break it.
As this instruction was always used together with an immediately following `destroy_value` of the closure, it makes sense to combine both into a `destroy_not_escaped_closure`.
It
1. checks the reference count and returns true if it is 1
2. consumes and destroys the operand
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit 95f1dfb into swiftlang:main Jan 27, 2025
5 checks passed
@eeckstein eeckstein deleted the fix-without-actually-escaping branch January 27, 2025 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant