-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
chore: removing unnecessary arc in scoped threads implementation #125731
Conversation
The Arc isn't needed because the scoped threads are allowed to borrow from the outer 'scope, which the lifetime of scopedata should already satisfy.
Why was an |
I have no idea. I was reading the code, and went to discord to ask why was an Arc being used here for no reason. Someone told me "if you think its unnecessary, remove it and make a PR", so I did. The tests pass so it must be fine. |
Not necessarily. I would do a git blame on the code (there's also a "blame" button in the github UI) and look for the commit that added it. |
#98503 introduced the Arc to fix a data race. |
@@ -136,14 +136,12 @@ pub fn scope<'env, F, T>(f: F) -> T | |||
where | |||
F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> T, | |||
{ | |||
// We put the `ScopeData` into an `Arc` so that other threads can finish their |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that justification seems fairly clear, so you'd need to show why it's incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idk, it wasn't clear to me when I read it. The way I saw it, the scoped data outlives the place where it is joined, so it seemed reasonable a reference should outlive it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improving the comment would be a nice improvement then :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for an example of how the lifetimes involved can be very complex and counterintuitive even in the scoped thread case, see:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improving the comment would be a nice improvement then :)
Yeah, definitely.
I'm not sure that such a test that fails outside Miri would be possible. I wonder if Miri catches this, how exactly do you test std under Miri locally? |
The reproducer in the original issue (#98498) is an std doctest. rustc CI runs these std doctests in Miri. So CI should catch when this breaks again -- but PR CI doesn't, and also this is a concurrency issue so it may be somewhat random whether it gets detected or not. |
|
Oh in fact that's exactly a regression test for #98498 that triggered the UB. :) |
@tvallotton Would you be so kind as to make sure the test in question lands in miri's test suite in this PR? |
The test runs 100 iterations... I think I made it std-only to avoid unduly slowing down the Miri test suite. The point of that test suite, after all, is to test Miri, not std. :)
|
I could but if I don't think I can do it today. |
@rust-lang/miri how do we feel about having this test in our test suite? Personally I think we should not add this test to our test suite. It takes close to 10s to run on my laptop, making it one of the slowest tests we have. I don't think that's something I want to wait for every time I do |
Oh that's slower than I was expecting, I was hoping it was something it could be feasible to run only a few iterations of but 10s for 100 means that's still 100millis for that test, just for 1 iteration. |
I don't think it's useful to have it in the miri test suite. As long as it exists elsewhere, so it will eventually fail under miri, and the documentation references the test, we have all the coverage we need |
Ah, making sure references exist then sounds like a good idea. We can make sure the comments here reference that test at least. |
I agree that adding this slow test to Miri's test suite is not a net benefit here. |
r? libs I don't really have the context here, and it seems as if others know what's necessary. Feel free to claim directly. |
I don't think there's much gained from adding this specific test to the Miri test suite to make it run in PR CI. If the problem is that std Miri tests aren't running in PR CI, they should be made to run in PR CI. I don't know if we can afford that, that would be a question for infra. As for this PR, let's improve the comment to be clearer and link the test in it, to make sure someone in the future knows exactly what's going on. |
Running Miri on core, alloc, std currently takes about 50-60min I think. So that's not something we can easily add to PR CI. std is run on multiple targets, but that will only save 10-20 minutes I think. |
@rustbot author |
Should I just go on and close it? |
you're welcome to improve the comment such that you won't be confused next time, but you can also just close it if you don't want to |
The Arc shouldn't needed because the scoped threads are allowed to borrow from the outer 'scope, which the lifetime of ScopeData should already satisfy.