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

Make processing of entrypoints more efficient #4513

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
508959c
Make processing of entrypoints more efficient
udoprog Feb 17, 2022
b520907
Abide by minimum Rust requirement
udoprog Feb 17, 2022
b593c90
Fix clippy lints
udoprog Feb 17, 2022
61ea5f9
Make sure to test for missing runtime
udoprog Feb 17, 2022
59e648f
Skip over angle brackets and treat last braced block seen as body
udoprog Feb 18, 2022
5369043
rustfmt
udoprog Feb 18, 2022
6122d6d
fix trybuild output
udoprog Feb 18, 2022
ce27bec
Trim more stuff from patterns
udoprog Feb 18, 2022
439841d
Bump async-stream dependency to 0.3.2 to avoid minimal-versions issue
udoprog Feb 18, 2022
dcc8a7a
Perform return type heuristics to determine when to return and not
udoprog Feb 18, 2022
04e95aa
Actually implement heuristics
udoprog Feb 19, 2022
5824c57
Update tokio-macros/src/select.rs
udoprog Feb 19, 2022
b78862f
Improve return heuristics by checking for `where`
udoprog Feb 19, 2022
5c97ae4
Only do find_last_stmt_range for last block found
udoprog Feb 19, 2022
9d83d83
Ensure that skip_angle_brackets skips over composite tokens that cont…
udoprog Feb 19, 2022
27ea4b8
rustfmt
udoprog Feb 19, 2022
7d74def
Fix logic for determining continutations in skip_angle_brackets
udoprog Feb 19, 2022
3de31aa
Ensure we're always reporting some error about failing to process
udoprog Feb 19, 2022
d924545
Ensure we always print some error when failing to expand
udoprog Feb 19, 2022
fd293b7
Add groups_in_return_position test
udoprog Feb 20, 2022
4e3c5b6
Merge remote-tracking branch 'upstream/master' into entrypoints
udoprog Feb 25, 2022
c71a888
Regenerate trybuild with -Dwarnings
udoprog Feb 25, 2022
df3cbb6
deny duplicate_macro_attributes
udoprog Feb 26, 2022
d48f452
Merge remote-tracking branch 'upstream/master' into entrypoints
udoprog Mar 24, 2022
e314165
bump tracing dependency to abide by minimal-versions
udoprog Mar 24, 2022
59d49ff
bump tracing in tokio-util
udoprog Mar 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests-build/tests/fail/macros_core_no_default.stderr
@@ -1,5 +1,5 @@
error: The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled.
--> $DIR/macros_core_no_default.rs:3:1
error: the default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled
--> tests/fail/macros_core_no_default.rs:3:1
|
3 | #[tokio::main]
| ^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests-build/tests/fail/macros_invalid_input.rs
@@ -1,3 +1,5 @@
#![deny(duplicate_macro_attributes)]

use tests_build::tokio;

#[tokio::main]
Expand Down
88 changes: 37 additions & 51 deletions tests-build/tests/fail/macros_invalid_input.stderr
@@ -1,79 +1,65 @@
error: the `async` keyword is missing from the function declaration
--> $DIR/macros_invalid_input.rs:4:1
error: functions marked with `#[tokio::main]` must be `async`
--> tests/fail/macros_invalid_input.rs:6:1
|
4 | fn main_is_not_async() {}
6 | fn main_is_not_async() {}
| ^^

error: Unknown attribute foo is specified; expected one of: `flavor`, `worker_threads`, `start_paused`
--> $DIR/macros_invalid_input.rs:6:15
error: unknown option `foo`, expected one of: `flavor`, `worker_threads`, `start_paused`
--> tests/fail/macros_invalid_input.rs:8:15
|
6 | #[tokio::main(foo)]
8 | #[tokio::main(foo)]
| ^^^

error: Must have specified ident
--> $DIR/macros_invalid_input.rs:9:15
|
9 | #[tokio::main(threadpool::bar)]
| ^^^^^^^^^^^^^^^
error: unknown option `threadpool`, expected one of: `flavor`, `worker_threads`, `start_paused`
--> tests/fail/macros_invalid_input.rs:11:15
|
11 | #[tokio::main(threadpool::bar)]
| ^^^^^^^^^^

error: the `async` keyword is missing from the function declaration
--> $DIR/macros_invalid_input.rs:13:1
error: functions marked with `#[tokio::test]` must be `async`
--> tests/fail/macros_invalid_input.rs:15:1
|
13 | fn test_is_not_async() {}
15 | fn test_is_not_async() {}
| ^^

error: Unknown attribute foo is specified; expected one of: `flavor`, `worker_threads`, `start_paused`
--> $DIR/macros_invalid_input.rs:15:15
error: unknown option `foo`, expected one of: `flavor`, `worker_threads`, `start_paused`
--> tests/fail/macros_invalid_input.rs:17:15
|
15 | #[tokio::test(foo)]
17 | #[tokio::test(foo)]
| ^^^

error: Unknown attribute foo is specified; expected one of: `flavor`, `worker_threads`, `start_paused`
--> $DIR/macros_invalid_input.rs:18:15
error: unknown option `foo`, expected one of: `flavor`, `worker_threads`, `start_paused`
--> tests/fail/macros_invalid_input.rs:20:15
|
18 | #[tokio::test(foo = 123)]
| ^^^^^^^^^
20 | #[tokio::test(foo = 123)]
| ^^^

error: Failed to parse value of `flavor` as string.
--> $DIR/macros_invalid_input.rs:21:24
error: no such runtime flavor, the runtime flavors are: "current_thread", "multi_thread"
--> tests/fail/macros_invalid_input.rs:23:24
|
21 | #[tokio::test(flavor = 123)]
23 | #[tokio::test(flavor = 123)]
| ^^^

error: No such runtime flavor `foo`. The runtime flavors are `current_thread` and `multi_thread`.
--> $DIR/macros_invalid_input.rs:24:24
error: no such runtime flavor, the runtime flavors are: "current_thread", "multi_thread"
--> tests/fail/macros_invalid_input.rs:26:24
|
24 | #[tokio::test(flavor = "foo")]
26 | #[tokio::test(flavor = "foo")]
| ^^^^^

error: The `start_paused` option requires the `current_thread` runtime flavor. Use `#[tokio::test(flavor = "current_thread")]`
--> $DIR/macros_invalid_input.rs:27:55
error: the `worker_threads` option requires the "multi_thread" runtime flavor. Use `#[tokio::test(flavor = "multi_thread")]`
--> tests/fail/macros_invalid_input.rs:35:59
|
27 | #[tokio::test(flavor = "multi_thread", start_paused = false)]
| ^^^^^

error: Failed to parse value of `worker_threads` as integer.
--> $DIR/macros_invalid_input.rs:30:57
|
30 | #[tokio::test(flavor = "multi_thread", worker_threads = "foo")]
| ^^^^^

error: The `worker_threads` option requires the `multi_thread` runtime flavor. Use `#[tokio::test(flavor = "multi_thread")]`
--> $DIR/macros_invalid_input.rs:33:59
|
33 | #[tokio::test(flavor = "current_thread", worker_threads = 4)]
35 | #[tokio::test(flavor = "current_thread", worker_threads = 4)]
| ^

error: second test attribute is supplied
--> $DIR/macros_invalid_input.rs:37:1
|
37 | #[test]
| ^^^^^^^

error: duplicated attribute
udoprog marked this conversation as resolved.
Show resolved Hide resolved
--> $DIR/macros_invalid_input.rs:37:1
--> tests/fail/macros_invalid_input.rs:39:1
|
37 | #[test]
39 | #[test]
| ^^^^^^^
|
= note: `-D duplicate-macro-attributes` implied by `-D warnings`
note: the lint level is defined here
--> tests/fail/macros_invalid_input.rs:1:9
|
1 | #![deny(duplicate_macro_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
11 changes: 11 additions & 0 deletions tests-build/tests/fail/macros_main_generics.rs
@@ -0,0 +1,11 @@
use tests_build::tokio;

// This should parse but fail since default values for const generic parameters
// are experimental.
//
// TODO(udoprog): might want to version constrain this check with `rustversion`
// since this won't always be experimental moving forward (!).
#[tokio::main]
async fn where_clause_const_generics<const T: usize = { 1 + 1 }>() {}
udoprog marked this conversation as resolved.
Show resolved Hide resolved

fn main() {}
5 changes: 5 additions & 0 deletions tests-build/tests/fail/macros_main_generics.stderr
@@ -0,0 +1,5 @@
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> tests/fail/macros_main_generics.rs:9:44
|
9 | async fn where_clause_const_generics<const T: usize = { 1 + 1 }>() {}
| ^
6 changes: 6 additions & 0 deletions tests-build/tests/fail/macros_main_missing_async.rs
@@ -0,0 +1,6 @@
use tests_build::tokio;

#[tokio::main]
fn test_missing_async() {}

fn main() {}
5 changes: 5 additions & 0 deletions tests-build/tests/fail/macros_main_missing_async.stderr
@@ -0,0 +1,5 @@
error: functions marked with `#[tokio::main]` must be `async`
--> tests/fail/macros_main_missing_async.rs:4:1
|
4 | fn test_missing_async() {}
| ^^
9 changes: 9 additions & 0 deletions tests-build/tests/fail/macros_type_mismatch.rs
Expand Up @@ -23,4 +23,13 @@ async fn extra_semicolon() -> Result<(), ()> {
Ok(());
}

/// Intentionally try and make return heuristics misfire by introducing a generic return.
#[tokio::main]
async fn extra_semicolon_generic<T>() -> Result<(), ()>
where
T: Fn() -> (),
{
Ok(());
}

fn main() {}
23 changes: 20 additions & 3 deletions tests-build/tests/fail/macros_type_mismatch.stderr
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/macros_type_mismatch.rs:5:5
--> tests/fail/macros_type_mismatch.rs:5:5
|
4 | async fn missing_semicolon_or_return_type() {
| - possibly return type missing here?
Expand All @@ -12,7 +12,7 @@ error[E0308]: mismatched types
found enum `Result<(), _>`

error[E0308]: mismatched types
--> $DIR/macros_type_mismatch.rs:10:5
--> tests/fail/macros_type_mismatch.rs:10:5
|
9 | async fn missing_return_type() {
| - possibly return type missing here?
Expand All @@ -23,7 +23,7 @@ error[E0308]: mismatched types
found enum `Result<(), _>`

error[E0308]: mismatched types
--> $DIR/macros_type_mismatch.rs:23:5
--> tests/fail/macros_type_mismatch.rs:23:5
|
14 | async fn extra_semicolon() -> Result<(), ()> {
| -------------- expected `Result<(), ()>` because of return type
Expand All @@ -38,3 +38,20 @@ help: try adding an expression at the end of the block
23 ~ Ok(());;
24 + Ok(())
|

error[E0308]: mismatched types
--> tests/fail/macros_type_mismatch.rs:32:5
|
28 | async fn extra_semicolon_generic<T>() -> Result<(), ()>
| -------------- expected `Result<(), ()>` because of return type
...
32 | Ok(());
| ^^^^^^^ expected enum `Result`, found `()`
|
= note: expected enum `Result<(), ()>`
found unit type `()`
help: try adding an expression at the end of the block
|
32 ~ Ok(());;
33 + Ok(())
|
12 changes: 12 additions & 0 deletions tests-build/tests/macros.rs
Expand Up @@ -5,12 +5,18 @@ fn compile_fail_full() {
#[cfg(feature = "full")]
t.pass("tests/pass/forward_args_and_output.rs");

#[cfg(feature = "full")]
t.pass("tests/pass/macros_main.rs");

#[cfg(feature = "full")]
t.pass("tests/pass/macros_main_return.rs");

#[cfg(feature = "full")]
t.pass("tests/pass/macros_main_loop.rs");

#[cfg(feature = "full")]
t.pass("tests/pass/macros_main_generics.rs");

#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_invalid_input.rs");

Expand All @@ -20,6 +26,12 @@ fn compile_fail_full() {
#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_type_mismatch.rs");

#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_main_generics.rs");

#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_main_missing_async.rs");

#[cfg(all(feature = "rt", not(feature = "full")))]
t.compile_fail("tests/fail/macros_core_no_default.rs");

Expand Down
10 changes: 10 additions & 0 deletions tests-build/tests/pass/macros_main.rs
@@ -0,0 +1,10 @@
use tests_build::tokio;

// This ensures that `'static>>` is not being incorrectly consumed as one
// sequence of joint tokens while parsing the angle bracket group.
#[tokio::main]
async fn ensure_proper_continuation() -> Result<(), Box<dyn std::error::Error + 'static>> {
todo!()
}

fn main() {}
36 changes: 36 additions & 0 deletions tests-build/tests/pass/macros_main_generics.rs
@@ -0,0 +1,36 @@
use tests_build::tokio;

use std::fmt::Debug;

#[tokio::main]
async fn single_parameter<T>() {}

// This should parse since we treat angle brackets as groups during parsing and
// simply skip over them.
#[tokio::main]
async fn where_clause<T>()
where
T: Iterator,
<T as Iterator>::Item: Debug,
{
}

#[tokio::main]
async fn join_bracket_in_return() -> Option<fn() -> ()> {
todo!()
}

#[tokio::main]
async fn joint_bracket_in_generic<T: Iterator<Item = Option<fn() -> ()>>>(_: T) {}

struct GroupsInReturnPosition<const N: usize, const U: usize>;

// Tests both bracket groups `<{inner}>` and braces `{<inner>}` in the return
// position. The latter which should already be skipped over as part of the
// angle bracket processing.
#[tokio::main]
async fn groups_in_return_position() -> GroupsInReturnPosition<1, { 2 + 1 }> {
todo!()
}

fn main() {}
7 changes: 0 additions & 7 deletions tokio-macros/Cargo.toml
Expand Up @@ -19,13 +19,6 @@ categories = ["asynchronous"]
[lib]
proc-macro = true

[features]

[dependencies]
proc-macro2 = "1.0.7"
quote = "1"
syn = { version = "1.0.56", features = ["full"] }

[dev-dependencies]
tokio = { version = "1.0.0", path = "../tokio", features = ["full"] }

Expand Down