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

add large future lint #10414

Merged
merged 3 commits into from
Mar 30, 2023
Merged

add large future lint #10414

merged 3 commits into from
Mar 30, 2023

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented Feb 27, 2023

Closes #5263


changelog: new lint: [large_futures]
#10414

@rustbot
Copy link
Collaborator

rustbot commented Feb 27, 2023

r? @xFrednet

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 27, 2023
@xFrednet
Copy link
Member

Hey @csmoe, thank you for the PR. I'll review it over the week. The CI is currently still red, could you maybe take a look at it? :)

@csmoe
Copy link
Member Author

csmoe commented Mar 1, 2023

@xFrednet Error fixed, may I have your review? thanks :)

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

Hey thank you for the PR. This is already an excellent start. I've added some comments. You're welcome to reach out if you need further assistance :)

clippy_lints/src/utils/conf.rs Outdated Show resolved Hide resolved
clippy_lints/src/utils/conf.rs Outdated Show resolved Hide resolved
clippy_lints/src/large_future.rs Outdated Show resolved Hide resolved
clippy_lints/src/large_future.rs Outdated Show resolved Hide resolved
clippy_lints/src/large_future.rs Outdated Show resolved Hide resolved
@csmoe csmoe force-pushed the large-future branch 7 times, most recently from 3061ad7 to e7e84ed Compare March 6, 2023 11:58
Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

Looks good to me overall, two small nits and then it should be ready for merge :)

tests/ui-toml/large_futures/clippy.toml Outdated Show resolved Hide resolved
clippy_lints/src/large_futures.rs Outdated Show resolved Hide resolved
@csmoe
Copy link
Member Author

csmoe commented Mar 17, 2023

rustc is trying to address this problem, let's wait for that :)

@xFrednet
Copy link
Member

Do you have an estimate for the timeframe? If that'll take a few releases/months we could still add the lint and deprecate it later. :)

@csmoe csmoe force-pushed the large-future branch 2 times, most recently from 9b7e7a2 to dc1d61c Compare March 20, 2023 10:41
@csmoe
Copy link
Member Author

csmoe commented Mar 20, 2023

@xFrednet Done~ :)

@csmoe csmoe force-pushed the large-future branch 3 times, most recently from 44d7138 to b9a239d Compare March 20, 2023 12:36
@csmoe
Copy link
Member Author

csmoe commented Mar 27, 2023

@xFrednet ping :)

@xFrednet
Copy link
Member

Hey @csmoe, thank you for your patience, the last two weeks have been very chaotic. You'll have a review by the end of the week! :)

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

Looks good to me overall. A few small nits which should hopefully be simple to fix and then we can merge this :)

clippy_lints/src/large_futures.rs Outdated Show resolved Hide resolved

impl<'tcx> LateLintPass<'tcx> for LargeFuture {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if let ExprKind::Match(expr, _, MatchSource::AwaitDesugar) = expr.kind {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a check that the future doesn't originate from a macro? I believe it would look like this:

if expr.span.from_expansion() {
    return;
}

I'm hoping that from_expansion is not true for desugared code, but it shouldn't :)

Copy link
Member Author

@csmoe csmoe Mar 29, 2023

Choose a reason for hiding this comment

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

if will not works here since we are checking the lowered expr.await by lower_expr_await, which marks the span of expr.await as Desugred as a whole, thus check_if_expand_from_macro always returns false.

clippy_lints/src/large_futures.rs Outdated Show resolved Hide resolved
tests/ui/large_futures.fixed Outdated Show resolved Hide resolved
Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>
@xFrednet
Copy link
Member

This version looks good to me, thank you very much for the implementation :)

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 30, 2023

📌 Commit 4f5a019 has been approved by xFrednet

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Mar 30, 2023

⌛ Testing commit 4f5a019 with merge 7499cd6...

bors added a commit that referenced this pull request Mar 30, 2023
add large future lint

Closes #5263

---

changelog: new lint: [`large_futures`]
[#10414](#10414)
<!-- changelog_checked -->
@bors
Copy link
Collaborator

bors commented Mar 30, 2023

💔 Test failed - checks-action_test

@xFrednet
Copy link
Member

Let's try this again :)

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 30, 2023

📌 Commit 6e87ae0 has been approved by xFrednet

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Mar 30, 2023

⌛ Testing commit 6e87ae0 with merge 799732c...

@bors
Copy link
Collaborator

bors commented Mar 30, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet
Pushing 799732c to master...

1 similar comment
@bors
Copy link
Collaborator

bors commented Mar 30, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet
Pushing 799732c to master...

@bors bors merged commit 799732c into rust-lang:master Mar 30, 2023
/// ```rust
/// async fn wait(f: impl std::future::Future<Output = ()>) {}
///
/// async fn big_fut(arg: [u8; 1024]) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

@csmoe Given the default threshold of 16*1024 bytes, I don't think the example code in the lint documentation will actually trigger the lint.

Besides this, can you maybe shed some light on why:

async fn fut() {
    let _x = [0; 16*1024];
    async {}.await;
}

async fn main() {
    fut().await; // <- expect to trigger here
}

Does not trigger the lint? In my mind the future returned by fut needs to keep around _x until after the await point. Is this somehow optimized out or am I just not thinking about this correctly?

Copy link
Member Author

@csmoe csmoe Sep 22, 2023

Choose a reason for hiding this comment

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

yes, _x is optimized out as it does not live across await point(see my test cases, I made it by a printf). You can check fut()'s size with std::mem::size_of_val, it should be very small.

Copy link
Contributor

@mickvangelderen mickvangelderen Sep 22, 2023

Choose a reason for hiding this comment

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

Interesting that it can optimize a local but not an argument.

I have opened #11553 to address what I believe to be a broken example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn about large Future sizes
5 participants