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

Don't require intercrate mode for negative coherence #117992

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

compiler-errors
Copy link
Member

Negative coherence needs to be sound, but does not need to be complete, since it's looking for the existence of a negative goal, not the non-existence of a positive goal.

This removes some trivial and annoying ambiguities when a negative impl has region constraints.

r? lcnr idk if this needs an fcp but if it does, pls kick it off

@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 Nov 16, 2023
@compiler-errors compiler-errors added T-types Relevant to the types 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 Nov 16, 2023
@lcnr
Copy link
Contributor

lcnr commented Nov 17, 2023

don't believe this to require an FCP

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 17, 2023

📌 Commit ae62ebe has been approved by lcnr

It is now in the queue for this repository.

@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 Nov 17, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 17, 2023
…lete, r=lcnr

Don't require intercrate mode for negative coherence

Negative coherence needs to be *sound*, but does not need to be *complete*, since it's looking for the *existence* of a negative goal, not the non-existence of a positive goal.

This removes some trivial and annoying ambiguities when a negative impl has region constraints.

r? lcnr idk if this needs an fcp but if it does, pls kick it off
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this pull request Nov 18, 2023
…lete, r=lcnr

Don't require intercrate mode for negative coherence

Negative coherence needs to be *sound*, but does not need to be *complete*, since it's looking for the *existence* of a negative goal, not the non-existence of a positive goal.

This removes some trivial and annoying ambiguities when a negative impl has region constraints.

r? lcnr idk if this needs an fcp but if it does, pls kick it off
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Nov 18, 2023
…lete, r=lcnr

Don't require intercrate mode for negative coherence

Negative coherence needs to be *sound*, but does not need to be *complete*, since it's looking for the *existence* of a negative goal, not the non-existence of a positive goal.

This removes some trivial and annoying ambiguities when a negative impl has region constraints.

r? lcnr idk if this needs an fcp but if it does, pls kick it off
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Nov 18, 2023

This pull request may have caused this error.

#118041 (comment)

@compiler-errors
Copy link
Member Author

@TaKO8Ki: Also, in the future, please use @bors r- so it doesn't end up in another rollup.

@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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 18, 2023
@compiler-errors
Copy link
Member Author

Gonna re-approve this one first

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Nov 18, 2023

📌 Commit ae62ebe has been approved by lcnr

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 18, 2023
Comment on lines 400 to 404
// N.B. We don't need to use intercrate mode here because we're trying to prove
// the *existence* of a negative goal, not the non-existence of a positive goal.
// Without this, we over-eagerly register coherence ambiguity candidates when
// impl candidates do exist.
let ref infcx = tcx.infer_ctxt().with_next_trait_solver(true).build();
Copy link
Member

Choose a reason for hiding this comment

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

I believe the intercrate mode must be enabled when equating impl headers in order to not over constrain the common type (e.g. disallow equating alias substs). It can then, and only then, be safely disabled in try_prove_negated_where_clause.

I think this is only a theoretical unsoundness for now because we currently ignore the obligations of equate_impl_headers and because infcx.eq does not have intercrate-specfic behavior (in the new solver mode that is. for the old solver, there is this).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that makes sense. I can leave a comment clarifying that next to the line where we currently throw away these obligations.

Copy link
Member

Choose a reason for hiding this comment

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

can't we just disable it in try_prove_negated_where_clause? the fact that we rely on infcx.eq to not have intercrate-specific behavior is a bit scary.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we have facilities to set the intercrate mode currently, but I guess I could add it to fork, probably the best way to do it.

@compiler-errors
Copy link
Member Author

@bors r- so i dont forget to leave this comment

@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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 19, 2023
Copy link
Member

@aliemjay aliemjay 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 now. You can r=me unless you want lcnr to review.

@compiler-errors
Copy link
Member Author

compiler-errors commented Nov 20, 2023

Yeah, I'll r=lcnr,aliemjay once #117994 lands. Just fixed up some comments.

@compiler-errors
Copy link
Member Author

19a5e1d is necessary for soundness. We emit region requirements when plugging region inference vars with placeholders, which are necessary to keep around, otherwise code like this passes:

#![feature(negative_impls)]
#![feature(with_negative_coherence)]

trait Foo {}
impl<T> !Foo for &'static T {}

trait Bar {}
impl<T> Bar for T where T: Foo {}
impl<T> Bar for &T {}

@bors r=lcnr,aliemjay

@bors
Copy link
Contributor

bors commented Nov 20, 2023

📌 Commit 253f502 has been approved by lcnr,aliemjay

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 20, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 20, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#117327 (Add documentation for some queries)
 - rust-lang#117835 (Note about object lifetime defaults in does not live long enough error)
 - rust-lang#117851 (Uplift `InferConst` to `rustc_type_ir`)
 - rust-lang#117973 (test: Add test for async-move in 2015 Rust proc macro)
 - rust-lang#117992 (Don't require intercrate mode for negative coherence)
 - rust-lang#118010 (Typeck break expr even if break is illegal)
 - rust-lang#118026 (Don't consider regions in `deref_into_dyn_supertrait` lint)
 - rust-lang#118089 (intercrate_ambiguity_causes: handle self ty infer + reservation impls)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 20, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#117327 (Add documentation for some queries)
 - rust-lang#117835 (Note about object lifetime defaults in does not live long enough error)
 - rust-lang#117851 (Uplift `InferConst` to `rustc_type_ir`)
 - rust-lang#117973 (test: Add test for async-move in 2015 Rust proc macro)
 - rust-lang#117992 (Don't require intercrate mode for negative coherence)
 - rust-lang#118010 (Typeck break expr even if break is illegal)
 - rust-lang#118026 (Don't consider regions in `deref_into_dyn_supertrait` lint)
 - rust-lang#118089 (intercrate_ambiguity_causes: handle self ty infer + reservation impls)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#117327 (Add documentation for some queries)
 - rust-lang#117835 (Note about object lifetime defaults in does not live long enough error)
 - rust-lang#117851 (Uplift `InferConst` to `rustc_type_ir`)
 - rust-lang#117973 (test: Add test for async-move in 2015 Rust proc macro)
 - rust-lang#117992 (Don't require intercrate mode for negative coherence)
 - rust-lang#118010 (Typeck break expr even if break is illegal)
 - rust-lang#118026 (Don't consider regions in `deref_into_dyn_supertrait` lint)
 - rust-lang#118089 (intercrate_ambiguity_causes: handle self ty infer + reservation impls)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0270afe into rust-lang:master Nov 21, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 21, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2023
Rollup merge of rust-lang#117992 - compiler-errors:sound-but-not-complete, r=lcnr,aliemjay

Don't require intercrate mode for negative coherence

Negative coherence needs to be *sound*, but does not need to be *complete*, since it's looking for the *existence* of a negative goal, not the non-existence of a positive goal.

This removes some trivial and annoying ambiguities when a negative impl has region constraints.

r? lcnr idk if this needs an fcp but if it does, pls kick it off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants