Skip to content
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

Rollup of 8 pull requests #66417

Closed
wants to merge 28 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7b9d50d
rename Error::iter_chain() and remove Error::iter_sources()
haraldh Oct 15, 2019
b941034
qualify-const remove cannot mutate statics in initializer of another …
spastorino Nov 11, 2019
695e91a
check-consts remove cannot mutate statics in initializer of another s…
spastorino Nov 12, 2019
139477d
Update mdbook.
ehuss Nov 12, 2019
32d1f47
Fix mdbook-linkcheck license checks.
ehuss Nov 12, 2019
37de933
Fix spurious CI filures due to OOM
wesleywiser Nov 14, 2019
f37f423
Make a test compatible across python versions.
smmalis37 Nov 14, 2019
3fe7cfc
Remove some stack frames from `.async` calls
sfackler Nov 14, 2019
92154d0
[ConstProp] Avoid OOM crashes by not evaluating large Places
wesleywiser Nov 14, 2019
6c9ba97
miri: helper methods for max values of machine's usize/isize
RalfJung Nov 14, 2019
0c52c3e
Respond to review feedback
wesleywiser Nov 14, 2019
6a49b52
TAIT: remove `OpaqueTy` in AST.
Centril Nov 7, 2019
6d8e300
TAIT: feature gate recursive locations
Centril Nov 7, 2019
0e8e176
TAIT: parse recursively instead of hack.
Centril Nov 7, 2019
aa6a72f
TAIT: use hack in ->HIR to avoid more changes
Centril Nov 7, 2019
e31d75c
TAIT: remove redundant check from ast_validation
Centril Nov 7, 2019
89b5907
TAIT: adjust save-analysis
Centril Nov 7, 2019
75aaa85
TAIT: adjust resolve
Centril Nov 7, 2019
8b663ec
TAIT: --bless some span changes for the better
Centril Nov 7, 2019
03cf0d7
TAIT: adjust tests
Centril Nov 7, 2019
5b93d4d
Rollup merge of #65557 - haraldh:error_iter_rename, r=sfackler
tmandry Nov 14, 2019
9876ced
Rollup merge of #66197 - Centril:transparent-ast, r=varkor
tmandry Nov 14, 2019
8b8f7ee
Rollup merge of #66306 - spastorino:remove-error-handled-by-miri, r=o…
tmandry Nov 14, 2019
b375256
Rollup merge of #66338 - ehuss:update-mdbook, r=alexcrichton
tmandry Nov 14, 2019
407968d
Rollup merge of #66394 - wesleywiser:fix_oom, r=oli-obk
tmandry Nov 14, 2019
ab8e0df
Rollup merge of #66396 - smmalis37:pythontest, r=alexcrichton
tmandry Nov 14, 2019
853af77
Rollup merge of #66398 - sfackler:no-async-nesting, r=Centril
tmandry Nov 14, 2019
e3bbc0d
Rollup merge of #66410 - RalfJung:miri-machine-max, r=oli-obk
tmandry Nov 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 12 additions & 33 deletions src/libstd/future.rs
Original file line number Diff line number Diff line change
@@ -40,10 +40,11 @@ impl<T: Generator<Yield = ()>> Future for GenFuture<T> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// Safe because we're !Unpin + !Drop mapping to a ?Unpin value
let gen = unsafe { Pin::map_unchecked_mut(self, |s| &mut s.0) };
set_task_context(cx, || match gen.resume() {
let _guard = unsafe { set_task_context(cx) };
match gen.resume() {
GeneratorState::Yielded(()) => Poll::Pending,
GeneratorState::Complete(x) => Poll::Ready(x),
})
}
}
}

@@ -61,35 +62,23 @@ impl Drop for SetOnDrop {
}
}

#[doc(hidden)]
#[unstable(feature = "gen_future", issue = "50547")]
/// Sets the thread-local task context used by async/await futures.
pub fn set_task_context<F, R>(cx: &mut Context<'_>, f: F) -> R
where
F: FnOnce() -> R
{
// Safety: the returned guard must drop before `cx` is dropped and before
// any previous guard is dropped.
unsafe fn set_task_context(cx: &mut Context<'_>) -> SetOnDrop {
// transmute the context's lifetime to 'static so we can store it.
let cx = unsafe {
core::mem::transmute::<&mut Context<'_>, &mut Context<'static>>(cx)
};
let cx = core::mem::transmute::<&mut Context<'_>, &mut Context<'static>>(cx);
let old_cx = TLS_CX.with(|tls_cx| {
tls_cx.replace(Some(NonNull::from(cx)))
});
let _reset = SetOnDrop(old_cx);
f()
SetOnDrop(old_cx)
}

#[doc(hidden)]
#[unstable(feature = "gen_future", issue = "50547")]
/// Retrieves the thread-local task context used by async/await futures.
///
/// This function acquires exclusive access to the task context.
///
/// Panics if no context has been set or if the context has already been
/// retrieved by a surrounding call to get_task_context.
pub fn get_task_context<F, R>(f: F) -> R
/// Polls a future in the current thread-local task waker.
pub fn poll_with_tls_context<F>(f: Pin<&mut F>) -> Poll<F::Output>
where
F: FnOnce(&mut Context<'_>) -> R
F: Future
{
let cx_ptr = TLS_CX.with(|tls_cx| {
// Clear the entry so that nested `get_task_waker` calls
@@ -108,15 +97,5 @@ where
//
// The pointer that was inserted came from an `&mut Context<'_>`,
// so it is safe to treat as mutable.
unsafe { f(cx_ptr.as_mut()) }
}

#[doc(hidden)]
#[unstable(feature = "gen_future", issue = "50547")]
/// Polls a future in the current thread-local task waker.
pub fn poll_with_tls_context<F>(f: Pin<&mut F>) -> Poll<F::Output>
where
F: Future
{
get_task_context(|cx| F::poll(f, cx))
unsafe { F::poll(f, cx_ptr.as_mut()) }
}