Skip to content

[Test] Make implicit_weak_capture.swift more robust. #81957

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

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Jun 3, 2025

This test creates an object then checks a weak reference to that object on a background thread. It was doing this check after 10ms, and any small hiccup could potentially delay the object's destruction enough to spuriously fail.

Rearrange the test to check the weak reference in a loop for several seconds before giving up. This makes it very fast on success (it's done the moment it sees nil) while being robust against up to several seconds of delay in destroying the object if that happens.

rdar://149868181

This test creates an object then checks a weak reference to that object on a background thread. It was doing this check after 10ms, and any small hiccup could potentially delay the object's destruction enough to spuriously fail.

Rearrange the test to check the weak reference in a loop for several seconds before giving up. This makes it very fast on success (it's done the moment it sees nil) while being robust against up to several seconds of delay in destroying the object if that happens.

rdar://149868181
@mikeash
Copy link
Contributor Author

mikeash commented Jun 3, 2025

@swift-ci please test

fatalError("Self was unexpectedly captured strongly")

runIn10ms { [self] in
// Use implicit self -- this should not result in a strong capture
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies for the drive-by commentary, but i find this comment (and surrounding logic) a bit confusing – if execution were to get to this point, wouldn't self already be strongly captured (by the earlier strong binding and capture list item)? what is this trying to test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just adjusting the test to be more reliable, I'm not super familiar with it, but I believe the idea is to make sure the compiler generates code such that the nested closure doesn't capture self strongly. The execution path at runtime isn't too important, other than the fact that we want to detect that unwanted strong capture by getting to this point.

@mikeash
Copy link
Contributor Author

mikeash commented Jun 4, 2025

@swift-ci please test macos platform

@mikeash
Copy link
Contributor Author

mikeash commented Jun 4, 2025

Looks like the macOS build just sort of stopped doing anything and eventually timed out. Weird.

@mikeash
Copy link
Contributor Author

mikeash commented Jun 4, 2025

@swift-ci please test macos platform

@mikeash
Copy link
Contributor Author

mikeash commented Jun 5, 2025

And again! It's not getting anywhere near running this test so it's not caused by my changes. Very strange. Retrying once more....

@mikeash
Copy link
Contributor Author

mikeash commented Jun 5, 2025

@swift-ci please test macos platform

@mikeash
Copy link
Contributor Author

mikeash commented Jun 6, 2025

@swift-ci please test macOS platform

@mikeash mikeash merged commit 53aa827 into swiftlang:main Jun 10, 2025
5 checks passed
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.

2 participants