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

A rustc-internal compile error on future and task API #61482

Closed
luojia65 opened this issue Jun 3, 2019 · 7 comments
Closed

A rustc-internal compile error on future and task API #61482

luojia65 opened this issue Jun 3, 2019 · 7 comments
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@luojia65
Copy link
Contributor

luojia65 commented Jun 3, 2019

Today when I tried this piece of code:

#![feature(async_await, gen_future)]

use core::task::Context;
use core::task::Poll;
use core::pin::Pin;
use core::future::Future;
use std::future::poll_with_tls_context;

struct CountdownFuture(u32);

impl Future for CountdownFuture {
    type Output = ();

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
        if self.0 == 0 {
            Poll::Ready(())
        } else {
            self.0 -= 1;
            Poll::Pending
        }
    }
}

fn main() {
    let mut fut = CountdownFuture(3);
    let pin = Pin::new(&mut fut);
    let res = poll_with_tls_context(pin);
    println!("{:?}", res);
}

I expected to see a line of debug formatted output representing a Poll::Pending state is set for variable res. However, when I execute this piece of code, a compile error occurred:

   Finished dev [unoptimized + debuginfo] target(s) in 0.32s
     Running `target\debug\test-futures.exe`
thread 'main' panicked at 'TLS Context not set. This is a rustc bug. Please file an issue on https://github.com/rust-lang/rust.', src\libcore\option.rs:1036:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: process didn't exit successfully: `target\debug\test-futures.exe` (exit code: 101)

And with RUST_BACKTRACE=1:

    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target\debug\test-futures.exe`
thread 'main' panicked at 'TLS Context not set. This is a rustc bug. Please file an issue on https://github.com/rust-lang/rust.', src\libcore\option.rs:1036:5
stack backtrace:
   0: backtrace::backtrace::trace_unsynchronized
             at C:\Users\appveyor\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.25\src\backtrace\mod.rs:66
   1: std::sys_common::backtrace::_print
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\sys_common\backtrace.rs:47
   2: std::sys_common::backtrace::print
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\sys_common\backtrace.rs:36
   3: std::panicking::default_hook::{{closure}}
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\panicking.rs:197
   4: std::panicking::default_hook
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\panicking.rs:211
   5: std::panicking::rust_panic_with_hook
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\panicking.rs:474
   6: std::panicking::continue_panic_fmt
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\panicking.rs:381
   7: std::panicking::rust_begin_panic
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\panicking.rs:308
   8: core::panicking::panic_fmt
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libcore\panicking.rs:85
   9: core::option::expect_failed
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libcore\option.rs:1036
  10: core::option::Option<core::ptr::non_null::NonNull<core::task::wake::Context>>::expect<core::ptr::non_null::NonNull<core::task::wake::Context>>
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\src\libcore\option.rs:314
  11: std::future::get_task_context<closure,core::task::poll::Poll<()>>
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\src\libstd\future.rs:95
  12: std::future::poll_with_tls_context<test_futures::CountdownFuture>
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\src\libstd\future.rs:114
  13: test_futures::main
             at .\src\main.rs:27
  14: std::rt::lang_start::{{closure}}<()>
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\src\libstd\rt.rs:64
  15: std::rt::lang_start_internal::{{closure}}
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\rt.rs:49
  16: std::panicking::try::do_call<closure,i32>
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\panicking.rs:293
  17: panic_unwind::__rust_maybe_catch_panic
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libpanic_unwind\lib.rs:85
  18: std::panicking::try
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\panicking.rs:272
  19: std::panic::catch_unwind
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\panic.rs:388
  20: std::rt::lang_start_internal
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\/src\libstd\rt.rs:48
  21: std::rt::lang_start<()>
             at /rustc/627486af15d222bcba336b12ea92a05237cc9ab1\src\libstd\rt.rs:64
  22: main
  23: invoke_main
             at d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  24: __scrt_common_main_seh
             at d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  25: BaseThreadInitThunk
  26: RtlUserThreadStart
error: process didn't exit successfully: `target\debug\test-futures.exe` (exit code: 101)

It seems that there is an internal issue with rustc itself. Does anyone met the same problem or similar issues as me? Or is there something wrong with my code? BTW, I doubt that I may need to change a executor function other than poll_with_tls_context.
Here's my rustc version:

PS D:\RustProjects\test-futures> rustc -V
rustc 1.37.0-nightly (627486af1 2019-06-02)

I'm using rustc target nightly-x86_64-pc-windows-msvc on Windows 10.

@luojia65 luojia65 changed the title A compile error on async/await and core future API A rustc-internal compile error on async/await and core future API Jun 3, 2019
@luojia65 luojia65 changed the title A rustc-internal compile error on async/await and core future API A rustc-internal compile error on future and task API Jun 3, 2019
@sfackler
Copy link
Member

sfackler commented Jun 3, 2019

That's just a bad panic message. You need to set the thread local context with https://doc.rust-lang.org/std/future/fn.set_task_context.html before you can use poll_with_tls_context.

@jonas-schievink jonas-schievink added A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 3, 2019
@luojia65
Copy link
Contributor Author

luojia65 commented Jun 3, 2019

@sfackler Thank you! I'd try by creating a Context and set it using that function.

@nikomatsakis nikomatsakis added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Jun 4, 2019
@nikomatsakis
Copy link
Contributor

Discussed in the async-await-foundations meeting -- doesn't block stabilization, but would be a good thing to have clearer documentation.

@withoutboats
Copy link
Contributor

poll_with_tls_context should be made doc(hidden) - its a part of how await is currently implemented and not intended to ever be stabilized or to be used by end users

pietroalbini added a commit to pietroalbini/rust that referenced this issue Jun 4, 2019
Hide gen_future API from documentation

This is internal rustc only API which should never be used outside code created by the current `async` transform, if it is used then the panic messages don't make sense as they're written from the perspective of that meaning there is a bug in the `async` transform (e.g. rust-lang#61482).
@Arnavion
Copy link

#61523 marked it doc(hidden). Is there anything else to do here?

@estebank estebank added the requires-nightly This issue requires a nightly compiler in some way. label Aug 28, 2019
@estebank
Copy link
Contributor

Given that poll_with_tls_context is gated behind gen_future which is not stabilized in 1.39, I think the only thing left is improving the panic message.

@csmoe
Copy link
Member

csmoe commented May 10, 2020

tls prerequisite was removed from future.

@csmoe csmoe closed this as completed May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants