Skip to content

Cleanup: Eliminate ConstnessAnd #90274

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

Closed
wants to merge 12 commits into from
Closed

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Oct 25, 2021

This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable ~const feature. I am looking into that, but not sure if I'll get to it this week.

We most definitely need to review all without_const and at some point should probably get rid of many of them by using TraitPredicate instead of TraitRef.

This pull request is best reviewed commit by commit, as it works on each commit (modulo some ui changes that will go away once I squash 764aac2 into 8e84aa9

r? @fee1-dead

cc @spastorino @ecstatic-morse

This now causes a lot of queries to be executed twice, as reveal_all forces NotConst
…ension for it

This breaks a ~const test that will be fixed in a follow up commit of this PR
Nothing else makes sense, and there is no "danger" in doing so, as it only does something if there are const bounds, which are unstable. This used to happen implicitly via the inferctxt before, which was much more fragile.
@rust-highfive
Copy link
Contributor

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 25, 2021
@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 25, 2021

@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 Oct 25, 2021
@bors
Copy link
Collaborator

bors commented Oct 25, 2021

⌛ Trying commit 764aac2 with merge 5149eb5f1733b5aeadfdd0a2e8a18c34cc023b71...

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking tracing-tree v0.1.9
    Checking rustdoc-json-types v0.1.0 (/checkout/src/rustdoc-json-types)
    Checking tera v1.10.0
    Checking rustdoc v0.0.0 (/checkout/src/librustdoc)
error[E0432]: unresolved import `rustc_middle::ty::WithConstness`
 --> src/librustdoc/clean/blanket_impl.rs:6:37
  |
6 | use rustc_middle::ty::{ToPredicate, WithConstness};
  |                                     ^^^^^^^^^^^^^ no `WithConstness` in `ty`
For more information about this error, try `rustc --explain E0432`.
error: could not compile `rustdoc` due to previous error
Build completed unsuccessfully in 0:02:33

@bors
Copy link
Collaborator

bors commented Oct 25, 2021

💔 Test failed - checks-actions

@bors bors 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 Oct 25, 2021
@rust-log-analyzer
Copy link
Collaborator

The job dist-x86_64-apple failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Updating files:  98% (30537/31041)
Updating files:  99% (30731/31041)
Updating files: 100% (31041/31041)
Updating files: 100% (31041/31041), done.
Switched to a new branch 'try'
Branch 'try' set up to track remote branch 'try' from 'origin'.
[command]/usr/local/bin/git log -1 --format='%H'
'5149eb5f1733b5aeadfdd0a2e8a18c34cc023b71'
##[group]Run src/ci/scripts/setup-environment.sh
src/ci/scripts/setup-environment.sh
---
   Compiling tera v1.10.0
[RUSTC-TIMING] rustdoc_json_types test:false 4.575
[RUSTC-TIMING] tracing_subscriber test:false 15.049
   Compiling rustdoc v0.0.0 (/Users/runner/work/rust/rust/src/librustdoc)
error[E0432]: unresolved import `rustc_middle::ty::WithConstness`
 --> src/librustdoc/clean/blanket_impl.rs:6:37
  |
6 | use rustc_middle::ty::{ToPredicate, WithConstness};
  |                                     ^^^^^^^^^^^^^ no `WithConstness` in `ty`
For more information about this error, try `rustc --explain E0432`.
[RUSTC-TIMING] rustdoc test:false 6.018
error: could not compile `rustdoc` due to previous error
warning: build failed, waiting for other jobs to finish...

@bors
Copy link
Collaborator

bors commented Oct 26, 2021

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

Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

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

Some queries do not care about if we are in a const context. Maybe we could always change the ParamEnv to be NonConst before caching?

I also think that we need a test for reproducing the error caused by the bad caching system.

Comment on lines +72 to +81
impl TraitObligation<'tcx> {
/// Returns `true` if the trait predicate is considered `const` in its ParamEnv.
pub fn is_const(&self) -> bool {
match (self.predicate.skip_binder().constness, self.param_env.constness()) {
(ty::BoundConstness::ConstIfConst, hir::Constness::Const) => true,
_ => false,
}
}
}

Copy link
Member

Choose a reason for hiding this comment

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

I think this can hurt performance by making cache misses more common. Before it is just the trait and the constness, now it is the predicate's constness AND the ParamEnv's constness.

NonConst predicate inside a NonConst context is very common.

But what about a NonConst predicate inside a Const context? For example associated consts in traits. These don't use the same cache.

Perhaps we need a function BoundConstness.and(hir::Constness) -> hir::Constness and use this to change the ParamEnv's constness to the result, not storing the BoundConstness in the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could make ParamEnv::and go through its anded value and check whether it needs constness, and remove said constness from itself if not

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 26, 2021

Maybe we could always change the ParamEnv to be NonConst before caching?

How would we handle the queries that do require constness? We could add a new query modifier stating whether constness is relevant and if not, automatically adjust the paramenv in its arguments

@fee1-dead
Copy link
Member

We could add a new query modifier stating whether constness is relevant and if not, automatically adjust the paramenv in its arguments

Yes, that is what I meant. I used "always" changing, but I forgot to say to change those "that do not require constness"

@fee1-dead fee1-dead removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 26, 2021
@spastorino
Copy link
Member

spastorino commented Oct 26, 2021

librustdoc is failing to compile, it has references to WithConstness

@fee1-dead
Copy link
Member

fee1-dead commented Nov 28, 2021

@oli-obk: do you mind if I take this PR and update it? You seem quite busy with other stuff and I really want this to land. I tried rebasing the PR a while back and I couldn't push to your repository.

@oli-obk
Copy link
Contributor Author

oli-obk commented Nov 28, 2021

Yea, feel free to take over. I recommend splitting it into parts though, as the non-param-env parts should be perf and behaviour neutral

@spastorino
Copy link
Member

@fee1-dead ohh great. I've promised @oli-obk that I was going to take this over but had some stuff on my plate and couldn't yet. If you're going ahead please do, otherwise I'd take it over probably this week.

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 2, 2021
Cleanup: Eliminate ConstnessAnd

This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature.

We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`.

This is a continuation of rust-lang#90274.

r? `@oli-obk`

cc `@spastorino` `@ecstatic-morse`
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Dec 17, 2021
Cleanup: Eliminate ConstnessAnd

This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature.

We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`.

This is a continuation of rust-lang/rust#90274.

r? `@oli-obk`

cc `@spastorino` `@ecstatic-morse`
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 12, 2022

Thanks @fee1-dead for carrying this over the finish line

@oli-obk oli-obk closed this Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants