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

Run const_prop_lint in check builds, too #120687

Closed
wants to merge 1 commit into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Feb 5, 2024

implements #108730 (comment)

addresses a large part of #49292

Turns the const_prop_lint pass into a query that is run alongside borrowck.

@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2024

r? @fmease

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 5, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 5, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 5, 2024
@bors
Copy link
Contributor

bors commented Feb 5, 2024

⌛ Trying commit 74cde5f with merge 63a199c...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2024
Run const_prop_lint in check builds, too

implements rust-lang#108730 (comment)

Turns the const_prop_lint pass into a query that is run alongside borrowck.
Comment on lines 429 to 433
_ => assert!(
start == Bound::Unbounded && end == Bound::Unbounded,
"nonscalar layout for layout_scalar_valid_range type: {st:#?}",
),
_ => {
if start != Bound::Unbounded || end != Bound::Unbounded {
return None;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can be reverted, this is hit when rustc_scalar_layout_start is used on structs with a non-scalar field. We can just stop testing that. It's all unstable anyway.

Comment on lines 404 to 415
// If there are impossible bounds on the body being const prop linted,
// the const eval logic used in const prop may ICE unexpectedly.
let predicates = tcx
.predicates_of(body.source.def_id())
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
if !traits::impossible_predicates(tcx, traits::elaborate(tcx, predicates).collect())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This duplication is somewhat unfortunate. We could make const_prop_lint return whether there were impossible predicates and then bail out.

Or we perform this in borrowck and store the information in borrowck results.

If perf doesn't find this problematic, we could just deduplicate by moving the logic into a function

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be interesting to look at error taint before trying to check for impossible predicates, as that's faster.
IIUC, this impossible predicates check is more of a heuristic to avoid diagnostic spam, as it does not try to prove satisfiability, does it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be interesting to look at error taint before trying to check for impossible predicates, as that's faster.

there are no errors usually. With trivial_bounds you may have a broken function that will only error if called, never out of another reason.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@@ -394,6 +395,27 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
body
}

fn const_prop_lint(tcx: TyCtxt<'_>, def: LocalDefId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use this as an opportunity to use a better name? lint_arithmetic_overflow ?

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 6, 2024

@rust-timer build 63a199c

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (63a199c): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.5% [0.2%, 9.4%] 109
Regressions ❌
(secondary)
2.1% [0.3%, 18.0%] 43
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.5% [-0.2%, 9.4%] 111

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.1% [0.9%, 15.9%] 25
Regressions ❌
(secondary)
5.3% [1.0%, 12.5%] 10
Improvements ✅
(primary)
-1.9% [-2.5%, -1.4%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [-2.5%, 15.9%] 28

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.0% [0.9%, 10.4%] 62
Regressions ❌
(secondary)
4.2% [1.4%, 20.5%] 23
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.0% [0.9%, 10.4%] 62

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 660.166s -> 662.022s (0.28%)
Artifact size: 308.14 MiB -> 308.18 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 6, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 6, 2024

Lower mean and max regression in primary benchmarks than #108730 (comment) But all that extra work is going to cost us some perf in check builds, no matter what.

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 6, 2024

most of the cost is in eval_to_allocation_raw. So one thing that we could do is avoid evaluating constants from other crates during const prop in check builds. We should already be evaluating all local constants anyway. This will reduce const prop coverage somewhat in check builds, but only if the errors rely on constants from other crates.

@cjgillot
Copy link
Contributor

cjgillot commented Feb 7, 2024

Any idea why we call eval_to_allocation_raw more? The PR does not strike me as adding much work, but moves the existing.
Are we evaluating some constant multiple times? For instance, once in const_prop_lint, once in mir_for_ctfe and once in optimized_mir?

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 7, 2024

The difference is that we didn't (reliably) run const prop lints in check builds at all before this PR. Now we do. So a regression due to extra work is expected.

@bors
Copy link
Contributor

bors commented Feb 8, 2024

☔ The latest upstream changes (presumably #120558) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 8, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 8, 2024
@bors
Copy link
Contributor

bors commented Feb 8, 2024

⌛ Trying commit f271893 with merge 460bf3d...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 8, 2024
Run const_prop_lint in check builds, too

implements rust-lang#108730 (comment)

Turns the const_prop_lint pass into a query that is run alongside borrowck.
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 8, 2024

☀️ Try build successful - checks-actions
Build commit: 460bf3d (460bf3de149d238b1df24c63883e2612eae5c529)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (460bf3d): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.5% [0.2%, 9.3%] 106
Regressions ❌
(secondary)
2.1% [0.2%, 17.9%] 38
Improvements ✅
(primary)
-0.3% [-0.3%, -0.2%] 7
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) 1.4% [-0.3%, 9.3%] 113

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.8% [1.1%, 7.7%] 12
Regressions ❌
(secondary)
6.9% [2.4%, 11.8%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.1% [-5.5%, -2.2%] 4
All ❌✅ (primary) 2.8% [1.1%, 7.7%] 12

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.0% [1.4%, 10.1%] 56
Regressions ❌
(secondary)
5.1% [2.0%, 19.7%] 14
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.8% [-4.8%, -3.3%] 4
All ❌✅ (primary) 3.0% [1.4%, 10.1%] 56

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 662.662s -> 663.487s (0.12%)
Artifact size: 308.26 MiB -> 308.23 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 8, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 8, 2024

Looks like all the regressions are legit. Check builds now actually running the lints or non-check-builds in incremental doing some incremental cache loading that they didn't do before

@fmease
Copy link
Member

fmease commented Mar 1, 2024

I haven't reviewed this yet since I'm assuming this is effectively S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and I don't have enough knowledge of the query system to know how to combat the perf regressions. However if this is actually S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. , I can gladly try to review it to the best of my ability.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 1, 2024
@oli-obk oli-obk added T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 1, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 1, 2024

Oh I basically think the regression cannot be avoided 😆 Either we emit those lints in check builds, and thus take a perf hit on check builds, or we decide to take the check vs build difference in lints.

cc @nnethercote because you expressed concerns about perf regressions due to such changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants