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

ExecutorExt, spawn! and spawn_with_handle! #1156

Merged
merged 3 commits into from
Aug 2, 2018

Conversation

MajorBreakfast
Copy link
Contributor

  • Adds ExecutorExt::spawn and ExecutorExt::spawn_with_handle
  • Adds spawn! and spawn_with_handle! macros
  • Removes ContextExt
  • Removes spawn and spawn_with_handle free functions

/// assert_eq!(thread::current().name(), Some("my-pool-0"));
/// # tx.send("ran").unwrap();
/// };
/// spawn!(future).unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cramertj I'd like to do:

spawn!(async {
    assert_eq!(thread::current().name(), Some("my-pool-0"));
    # tx.send("ran").unwrap();
}).unwrap();

But I get this error:

error: no rules expected the token `async`
  --> src/future/mod.rs:658:13
   |
20 |      spawn!(async {
   |             ^^^^^

Copy link
Member

Choose a reason for hiding this comment

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

Did you try spawn!((async { ... }))? Extra parentheses might get it into expression parsing. Probably should be a rust bug ticket as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Then I get this. I think it's an ICE:

---- src/future/mod.rs - future::FutureExt::with_executor (line 640) stdout ----
thread 'src/future/mod.rs - future::FutureExt::with_executor (line 640)' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:345:21
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::continue_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic
  10: syntax::print::pprust::State::print_expr_outer_attr_style
  11: syntax::print::pprust::State::print_expr_outer_attr_style
  12: syntax::print::pprust::to_string
  13: syntax::print::pprust::expr_to_string
  14: rustc_lint::unused::UnusedParens::check_unused_parens_core
  15: <rustc_lint::unused::UnusedParens as rustc::lint::EarlyLintPass>::check_expr
  16: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  17: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  18: syntax::visit::walk_expr
  19: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  20: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_fn
  21: syntax::visit::walk_expr
  22: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  23: syntax::visit::walk_expr
  24: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  25: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_local
  26: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  27: syntax::visit::walk_expr
  28: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  29: syntax::visit::walk_expr
  30: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  31: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  32: syntax::visit::walk_expr
  33: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  34: syntax::visit::walk_expr
  35: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  36: syntax::visit::walk_expr
  37: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  38: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_local
  39: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  40: syntax::visit::walk_expr
  41: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  42: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_local
  43: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  44: syntax::visit::walk_expr
  45: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  46: syntax::visit::walk_expr
  47: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  48: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  49: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_fn
  50: syntax::visit::walk_item
  51: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_item
  52: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_mod
  53: rustc::lint::context::check_ast_crate
  54: rustc::util::common::time
  55: rustc_driver::driver::phase_2_configure_and_expand
  56: rustc_driver::driver::compile_input
  57: std::panicking::try::do_call
  58: __rust_maybe_catch_panic
  59: <scoped_tls::ScopedKey<T>>::set
  60: rustdoc::test::Collector::add_test::{{closure}}::{{closure}}::{{closure}}
  61: <scoped_tls::ScopedKey<T>>::set
  62: syntax::with_globals
  63: std::panicking::try::do_call
  64: __rust_maybe_catch_panic
  65: rustc_driver::in_named_rustc_thread
  66: <F as alloc::boxed::FnBox<A>>::call_box
  67: <F as alloc::boxed::FnBox<A>>::call_box
  68: __rust_maybe_catch_panic
query stack during panic:
end of query stack
thread 'src/future/mod.rs - future::FutureExt::with_executor (line 640)' panicked at 'couldn't compile the test', librustdoc/test.rs:332:13
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustdoc::test::Collector::add_test::{{closure}}::{{closure}}::{{closure}}
   8: <scoped_tls::ScopedKey<T>>::set
   9: syntax::with_globals
  10: std::panicking::try::do_call
  11: __rust_maybe_catch_panic
  12: rustc_driver::in_named_rustc_thread
  13: <F as alloc::boxed::FnBox<A>>::call_box
  14: <F as alloc::boxed::FnBox<A>>::call_box
  15: __rust_maybe_catch_panic
query stack during panic:
end of query stack


failures:
    src/future/mod.rs - future::FutureExt::with_executor (line 640)

Copy link
Member

Choose a reason for hiding this comment

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

Hm, it looks like the macro matcher for expr isn't currently catching async. I'll file an issue and check the parser to see about a fix. Thanks for finding this! playground

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wonderful! I've subscribed to your PR, so that I can make the change once a new nightly with the fix is released. IMO it's not a blocking issue for this PR, though

#[macro_export]
macro_rules! spawn_with_handle {
($future:expr) => {
await!($crate::future::lazy(|cx| {
Copy link
Member

Choose a reason for hiding this comment

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

$crate::core_reexport::await! maybe? (probably not, can just rely on await being in scope).

Copy link
Member

Choose a reason for hiding this comment

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

In fact, it's probably a builtin macro rather than a core defined macro anyway

Copy link
Contributor Author

@MajorBreakfast MajorBreakfast Aug 1, 2018

Choose a reason for hiding this comment

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

The other macros (poll!, pending!) do it this way as well.

I don't know where await! comes from, but I don't think it's from libcore.

Copy link
Member

Choose a reason for hiding this comment

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

It's in libstd right now, but it'll probably be moved into the compiler itself as a builtin and referenced from libcore at some point. I wouldn't worry about scoping it.

@MajorBreakfast MajorBreakfast merged commit 80720aa into rust-lang:master Aug 2, 2018
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.

3 participants