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

Fix bad caching of ~const Drop bounds #92149

Merged
merged 1 commit into from
Dec 21, 2021

Conversation

fee1-dead
Copy link
Member

Fixes #92111.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 21, 2021
@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 21, 2021
@fee1-dead
Copy link
Member Author

r? @oli-obk

@fee1-dead
Copy link
Member Author

This is potentially perf-sensitive:

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

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

bors commented Dec 21, 2021

⌛ Trying commit aaaad5b with merge 5557e81be8ea74c8d6a3785b02976c3c96ec2e4f...

@bors
Copy link
Contributor

bors commented Dec 21, 2021

☀️ Try build successful - checks-actions
Build commit: 5557e81be8ea74c8d6a3785b02976c3c96ec2e4f (5557e81be8ea74c8d6a3785b02976c3c96ec2e4f)

@rust-timer
Copy link
Collaborator

Queued 5557e81be8ea74c8d6a3785b02976c3c96ec2e4f with parent 99b0799, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5557e81be8ea74c8d6a3785b02976c3c96ec2e4f): comparison url.

Summary: This change led to moderate relevant regressions 😿 in compiler performance.

  • Moderate regression in instruction counts (up to 2.9% on incr-patched: println builds of regression-31157)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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 led 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-review -S-waiting-on-perf +perf-regression

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 21, 2021
@fee1-dead
Copy link
Member Author

fee1-dead commented Dec 21, 2021

Just some thoughts: perf suggests that always checking if a trait is the Drop lang item in trait system is a bad idea. I wonder if, at some stage, we could remap T: ~const Drop bound to T: ConstDrop and kept ConstDrop private to libstd and librustc.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 21, 2021

The big regression is in llvm, which can't be a result of this PR. The 0.3% regressions look legit (typeck), but considering this pretty bad regression, let's take the hit.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 21, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Dec 21, 2021

📌 Commit aaaad5b has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 21, 2021
@fee1-dead fee1-dead added the const-hack This PR introduced a hack to make things valid in `const fn`. label Dec 21, 2021
@bors
Copy link
Contributor

bors commented Dec 21, 2021

⌛ Testing commit aaaad5b with merge 8ad3c1d...

// Regression test for #92111.
//
// The issue was that we normalize trait bounds before caching
// results of selection. Checking that `impl NoDrop for S` requires

Choose a reason for hiding this comment

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

Suggested change
// results of selection. Checking that `impl NoDrop for S` requires
// results of selection. Checking that `impl Tr for S` requires

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! Though bors has already begun testing this PR. The fix would probably have to be separated to another PR.

@bors
Copy link
Contributor

bors commented Dec 21, 2021

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 8ad3c1d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 21, 2021
@bors bors merged commit 8ad3c1d into rust-lang:master Dec 21, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 21, 2021
@@ -734,6 +734,15 @@ pub struct TraitPredicate<'tcx> {
pub type PolyTraitPredicate<'tcx> = ty::Binder<'tcx, TraitPredicate<'tcx>>;

impl<'tcx> TraitPredicate<'tcx> {
pub fn remap_constness(&mut self, tcx: TyCtxt<'tcx>, param_env: &mut ParamEnv<'tcx>) {
if unlikely!(Some(self.trait_ref.def_id) == tcx.lang_items().drop_trait()) {
Copy link
Member

Choose a reason for hiding this comment

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

It seems kind of weird to be special-casing Drop here. Are there any other traits that need this kind of special handling? Are you sure that this method is called in all of the places where it needs to be?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. No because we only need to special case ~const Drop bounds.
  2. Yes because I have audited all usages of a method I added made for exactly this purpose. Remapping T: ~const SomeTrait to T: SomeTrait when not in a const context.

See also https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/~const.20Drop which would be a better solution

@fee1-dead fee1-dead deleted the cache-fix branch December 21, 2021 16:21
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8ad3c1d): comparison url.

Summary: This change led to moderate relevant regressions 😿 in compiler performance.

  • Moderate regression in instruction counts (up to 2.6% on incr-patched: println builds of regression-31157)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 23, 2022
Rename `~const Drop` to `~const Destruct`

r? `@oli-obk`

Completely switching to `~const Destructible` would be rather complicated, so it seems best to add it for now and wait for it to be backported to beta in the next release.

The rationale is to prevent complications such as rust-lang#92149 and rust-lang#94803 by introducing an entirely new trait. And `~const Destructible` reads a bit better than `~const Drop`. Name Bikesheddable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
const-hack This PR introduced a hack to make things valid in `const fn`. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

T: Drop bound not satisfied from Option::unwrap_or (et. al) when Drop anti-bound is present
9 participants