Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upUpdate the future/task API #57992
Conversation
rust-highfive
assigned
joshtriplett
Jan 30, 2019
This comment was marked as outdated.
This comment was marked as outdated.
(rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
label
Jan 30, 2019
This comment has been minimized.
This comment has been minimized.
r? @cramertj |
rust-highfive
assigned
cramertj
and unassigned
joshtriplett
Jan 30, 2019
This comment has been minimized.
This comment has been minimized.
@cramertj I also started updating future-rs. However I currently had some build problems there, and it's a lot of stuff to change. Will look again tomorrow evening. |
Matthias247
referenced this pull request
Jan 30, 2019
Merged
Implements the waker changes for task API stabilization. #1445
Centril
reviewed
Jan 30, 2019
@@ -42,16 +42,16 @@ pub trait Future { | |||
/// Once a future has finished, clients should not `poll` it again. |
This comment has been minimized.
This comment has been minimized.
Centril
Jan 30, 2019
Contributor
As discussed in https://github.com/rust-lang/rfcs/pull/2592/files#r232498609, clarify that it isn't guaranteed that clients won't poll again, that it isn't guaranteed that panics will occur if they do, and that this assumption shouldn't be used for memory safety.
This comment has been minimized.
This comment has been minimized.
Nemo157
Jan 30, 2019
•
Contributor
This has identical behaviour/requirements to Iterator::next
, which has even less docs around behaviour after completion. Should this clarity be required there as well?
(EDIT: lol, looking back I was the one saying this should have more clarity. I guess I'm on the side that the iterator docs should probably be improved as well.)
This comment has been minimized.
This comment has been minimized.
Centril
Jan 30, 2019
Contributor
Returns None when iteration is finished. Individual iterator implementations may choose to resume iteration, and so calling next() again may or may not eventually start returning Some(Item) again at some point.
The difference here is that Iterator::next
doesn't imply in any way (in fact, the opposite) that None
+ None
isn't a valid sequence. Meanwhile, "should not poll
it again" is emphatic about what should not happen, so a reader may assume this is always true.
This comment has been minimized.
This comment has been minimized.
Centril
Jan 30, 2019
Contributor
A non-intrusive change to the language here would just be to weaken "should not poll again" to something like "is recommended to not poll again".
This comment has been minimized.
This comment has been minimized.
Matthias247
Feb 3, 2019
Author
Contributor
I'm torn on this one. In the section that @Centril commented about lower, I think no guarantees are made at all for clients polling again after Ready
was returned. Incl. memory safety guarantees.
As far as I remember some future implementations might have exploited this for performance reasons.
We can obviously change and enforce this, but I wouldn't like to change the semantics inside this CR.
This comment has been minimized.
This comment has been minimized.
Nemo157
Feb 4, 2019
Contributor
It must be memory safe since this function isn't unsafe
. Other than that, there are no guarantees, most futures will panic, but some may just implicitly reset and run again, or get stuck returning Poll::Pending
without scheduling a wakeup, or anything else that doesn't break memory safety. So, an executor or wrapping future calling poll
again after Ready
is returned is a very bad logic bug that has a high chance of causing subsequent errors elsewhere in the system (so panicking is the best option to minimise those subsequent errors), but can't be allowed to compromise memory safety.
This comment has been minimized.
This comment has been minimized.
Nemo157
Feb 4, 2019
Contributor
I think part of the difference from Iterator
is what implementations are likely to do. With Iterator
you have an easy option of just returning None
again, so while polling it again is a bug you have less chance of bringing your system down. With Future
you can't easily return Ready
again (unless the value is trivial), so it's mostly guaranteed that polling again will either panic or do something unexpected which will cause later issues.
This comment has been minimized.
This comment has been minimized.
Matthias247
Feb 5, 2019
Author
Contributor
I added the comment about memory safety to the other section (which refers to polling after Ready).
/// Once a task has been woken up, it should attempt to `poll` the future | ||
/// again, which may or may not produce a final value. | ||
/// | ||
/// Note that on multiple calls to `poll`, only the most recent | ||
/// [`LocalWaker`] passed to `poll` should be scheduled to receive a | ||
/// [`Waker`] passed to `poll` should be scheduled to receive a | ||
/// wakeup. | ||
/// | ||
/// # Runtime characteristics |
This comment has been minimized.
This comment has been minimized.
Centril
Jan 30, 2019
Contributor
Below it reads:
An implementation of
poll
should strive to return quickly, and must never block.
Per https://github.com/rust-lang/rfcs/pull/2592/files#r250460257, clarify that callers of poll
for an arbitrary F: Future
may not assume this to be true for memory safety purposes.
This comment has been minimized.
This comment has been minimized.
Matthias247
Feb 3, 2019
Author
Contributor
I think that information is provided implicitly. I think this together with the next sentences clarifies to the reader that this is purely about performance. I'm having a hard time to interpret anything about memory safety into it. We don't document for other methods either that they need to be memory safe, even if they are slow.
This comment has been minimized.
This comment has been minimized.
Centril
Feb 5, 2019
Contributor
I would again make the language weaker here and say "is recommended to never block" instead of framing it in a way that suggests a guarantee. It is true that the function is not unsafe
, but reinforcing the non-guarantee seems helpfully non-misleading to me.
This comment has been minimized.
This comment has been minimized.
/// [`LocalWaker::wake`] implementations have the ability to be more | ||
/// efficient, however, so when thread safety is not necessary, | ||
/// [`LocalWaker`] should be preferred. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Once a future has completed (returned `Ready` from `poll`), |
This comment has been minimized.
This comment has been minimized.
Centril
Jan 30, 2019
Contributor
Per https://github.com/rust-lang/rfcs/pull/2592/files#r250460358, clarify that "bad behavior" isn't violating soundness / memory unsafety.
This comment has been minimized.
This comment has been minimized.
src/libcore/task/wake.rs Outdated
src/libcore/task/wake.rs Outdated
src/libcore/task/wake.rs Outdated
} | ||
|
||
impl fmt::Debug for LocalWaker { | ||
impl fmt::Debug for Waker { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Matthias247
Feb 3, 2019
Author
Contributor
I thought about it, but it fear this will end up super noisy. I think lots of user-structs will store Waker
in them and #[derive(Debug)]
. Those would then all the show 5 different pointers that have no meaning for the average user.
The main reason why I think it might be useful is that users don't have access to RawWaker
, so they can't get the inner information.
Maybe we should then only print the data
and vtable
pointer for RawWaker
, and not the inner function pointers. I think if I would need to ever debug those things, the main thing I would be if if Waker
s refer to the same task or not, and with a lower probability of they use the same vtable. The function pointers are are mostly worthless without names.
In general those things might also be more ones that one would investigate with a real in-memory-debugger than with print debugging.
This comment has been minimized.
This comment has been minimized.
Nemo157
Feb 4, 2019
•
Contributor
I assume adding something like debug_fmt: Option<unsafe fn(*const (), f: &mut fmt::Formatter) -> fmt::Result>
to RawWakerVTable
wouldn't be worth it? (and if RawWakerVTable
is made non_exhaustive
could be added later anyway).
This comment has been minimized.
This comment has been minimized.
cramertj
Feb 5, 2019
Member
IMO printing the address of the data and vtable pointers seems helpful, but I would leave the substructure out.
This comment has been minimized.
This comment has been minimized.
Centril
Feb 5, 2019
Contributor
@cramertj's suggestion seems like a good have-your-
This comment has been minimized.
This comment has been minimized.
Matthias247
Feb 5, 2019
Author
Contributor
I added pointer printing for Waker
. And yes, I don't think the fmt method is worth it.
src/libcore/task/wake.rs Outdated
This comment has been minimized.
This comment has been minimized.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
Matthias247
and others
added some commits
Jan 30, 2019
Matthias247
force-pushed the
Matthias247:waker4
branch
from
4f7e602
to
9e6bc3c
Feb 3, 2019
This comment has been minimized.
This comment has been minimized.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
cramertj
reviewed
Feb 5, 2019
unsafe fn increase_refcount<T: ArcWake>(data: *const()) { | ||
// Retain Arc by creating a copy | ||
let arc: Arc<T> = Arc::from_raw(data as *const T); | ||
let arc_clone = arc.clone(); |
This comment has been minimized.
This comment has been minimized.
cramertj
Feb 5, 2019
Member
nit: if cloning the arc panics, the arc will be dropped, decreasing the refcount.
cramertj
reviewed
Feb 5, 2019
struct Counter { | ||
local_wakes: AtomicUsize, | ||
nonlocal_wakes: AtomicUsize, | ||
macro_rules! waker_vtable { |
This comment has been minimized.
This comment has been minimized.
cramertj
Feb 5, 2019
Member
Rather than redefining Wake
and this waker_vtable
macro in every separate test, i'd have one file define it and path-include that file.
This comment has been minimized.
This comment has been minimized.
Matthias247
Feb 5, 2019
Author
Contributor
I know, not happy with it either. However I only have no idea how the build and the conventions in this folder work. And since it takes 2 hours to get here, I couldn't really the spend time investigating it.
If anyone wants to push a commit which changes that part it would be great.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Matthias247
Feb 6, 2019
Author
Contributor
I moved it to the auxilary directory which seems to be used by other tests. But maybe that's wrong. If noone can tell where exactly it should go I will revert that.
This comment has been minimized.
This comment has been minimized.
This looks great! left a few small nits, but I'm excited to get this in :) |
Matthias247
added some commits
Feb 5, 2019
This comment has been minimized.
This comment has been minimized.
After talking to @Centril I realized we could also keep the |
This comment has been minimized.
This comment has been minimized.
@cramertj , @Centril I like that idea, since it means we could extend |
This comment has been minimized.
This comment has been minimized.
@Matthias247 sounds good to me! |
This comment has been minimized.
This comment has been minimized.
Then remove the test and please add an issue about checking substrings in rustdoc search (and assign it to me). |
This comment has been minimized.
This comment has been minimized.
@cramertj Can you try running it again. I tried to fix it by using another function |
This comment has been minimized.
This comment has been minimized.
@Matthias247 removing the tests and opening the issue so I could prevent further errors would have been better but whatever... |
This comment has been minimized.
This comment has been minimized.
@GuillaumeGomez Sorry, I just it might save some work, and felt bad about removing tests. Let me know briefly if you still prefer the removal, then I will go for it. |
This comment has been minimized.
This comment has been minimized.
I'd prefer that you removed the test (and please open an issue). I just opened #58330 so that we can test it without depending on the std. |
Matthias247
force-pushed the
Matthias247:waker4
branch
from
b5c2660
to
1ef34a5
Feb 9, 2019
Matthias247
referenced this pull request
Feb 9, 2019
Open
Fix rustdoc-js unit-test for substring after removal of unstable API #58331
This comment has been minimized.
This comment has been minimized.
@cramertj , @Centril Please retry the merge @GuillaumeGomez Alright, done. I opened the issue at #58331 |
This comment has been minimized.
This comment has been minimized.
@Matthias247 Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-author
labels
Feb 12, 2019
This comment has been minimized.
This comment has been minimized.
|
bors
added
S-waiting-on-author
and removed
S-waiting-on-bors
labels
Feb 12, 2019
This comment has been minimized.
This comment has been minimized.
@cramertj: can you please try again? |
This comment has been minimized.
This comment has been minimized.
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
Matthias247 commentedJan 30, 2019
This change updates the future and task API as discussed in the stabilization RFC at rust-lang/rfcs#2592.
Changes: