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

Stabilize RFC 2451, re-rebalance coherence #63599

Closed
1 of 3 tasks
nikomatsakis opened this issue Aug 15, 2019 · 13 comments · Fixed by #65879
Closed
1 of 3 tasks

Stabilize RFC 2451, re-rebalance coherence #63599

nikomatsakis opened this issue Aug 15, 2019 · 13 comments · Fixed by #65879
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. F-re_rebalance_coherence `#![feature(re_rebalance_coherence)]` finished-final-comment-period The final comment period is finished for this PR / Issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Aug 15, 2019

Stabilization Proposal

I am writing to propose we stabilize the implementation of RFC 2451, "re-rebalancing coherence" (tracking issue).

Brief Summary

The RFC modifies the coherence rules. It used to be that, when implementing a non-local trait, if Ti was the first "local type", then all type parameters were forbidden before that point. In practice, that meant that this impl was illegal:

struct Local;

impl<T> Foreign<Local> for Vec<T> { }
//              ^^^^^          ^
//              |              type parameter
//              first local type

The RFC lightly generalizes these rules. In particular, type parameters are now allowed before Ti, but only if they are covered, defined in the RFC as:

Covered Type: A type which appears as a parameter to another type. For example, T is uncovered, but the T in Vec<T> is covered. This is only relevant for type parameters.

This means that the impl above is now legal, because the typeT is covered by Vec. Note that an impl like the following would still be illegal:

struct Local;

impl<T> Foreign<Local> for T { }
//              ^^^^^      ^
//              |          type parameter (uncovered)
//              first local type

It is considered a (semver) breaking change for parent crates to add impls with uncovered type parameters (this was already the case even with the old rules, I believe). Therefore, this generalization of the rules cannot permit a conflict between the parent crate and a child crate. (See RFC for a more detailed argument.)

(NB: I've elided details of #[fundamental] in this summary, see the RFC for full details.)

Changes since the RFC was approved

None

Test cases

This section describes the patterns covered by new tests added for this RFC, or tests that seemed relevant to this RFC, with links to the test files.

Missing items

@nikomatsakis nikomatsakis added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Aug 15, 2019
@nikomatsakis
Copy link
Contributor Author

@rfcbot fcp merge

Dear @rust-lang/lang, I propose that we stabilize the re-rebalancing coherence changes. This issue opens with a description of the changes and some examination of test cases. Please review and feel free to note any missing patterns, I'm opening a PR shortly adding and adjusting tests as needed.

Also, I don't think we've updated the reference, so I've included a checklist item to do that.

@rfcbot
Copy link

rfcbot commented Aug 15, 2019

Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Aug 15, 2019
@Centril Centril added this to the 1.39 milestone Aug 15, 2019
@Centril
Copy link
Contributor

Centril commented Aug 15, 2019

I will open a PR shortly covering one missing pattern, where the Ti with the local type is T2:

* `impl<T> Foreign<Foreign<T>, Local> for Foreign<T>`

* XXX tests involving fundamental

@rfcbot concern make-sure-we-add-these-tests

:)

@scottmcm
Copy link
Member

Curiosity: is T covered by [T; N] and (T,)?

@nikomatsakis
Copy link
Contributor Author

nikomatsakis commented Aug 16, 2019

Hmm, writing up some new tests, I am finding that the current implementation is not working as expected! In particular, the behavior around fundamental types seems wrong, or else I am misreading the RFC.

For example, this impl is allowed:

impl<T> Remote1<Local> for Box<T> { }

This is despite the text in the RFC which says:

Once again, it is important to note that for the purposes of coherence, #[fundamental] types are special. Box<T> is not considered covered, and Box<LocalType> is considered local.

I presume here that "Box<T> is not considered covered" meant that the T is not considered covered (correct, @sgrif?).

That said, I'm not sure if this is a problem. The RFC states (correctly) that adding any blanket impl must be considered a breaking change, where a breaking impl is any impl that contains an uncovered type parameter. This implies that if some parent crate were to add something like this:

impl<T> Remote1<T> for Box<_> { } // where _ represents any type at all

that would be a major breaking change. But such an impl would be needed to match the type above, since there is no way for the parent crate to name the local type.

UPDATE: I think @arielb1's comment here indicates why we do wish to reject the impl above. The problem is that some sibling crate could write impl<T> Remote1<T> for Box<SiblingType>. So this will have to be fixed. (In my text above, I hadn't considered conflicts between siblings.)

@sgrif
Copy link
Contributor

sgrif commented Aug 17, 2019 via email

@nikomatsakis nikomatsakis added the F-re_rebalance_coherence `#![feature(re_rebalance_coherence)]` label Sep 12, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 20, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
tmandry added a commit to tmandry/rust that referenced this issue Sep 20, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
tmandry added a commit to tmandry/rust that referenced this issue Sep 20, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
tmandry added a commit to tmandry/rust that referenced this issue Sep 20, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
tmandry added a commit to tmandry/rust that referenced this issue Sep 20, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
tmandry added a commit to tmandry/rust that referenced this issue Sep 21, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
Centril added a commit to Centril/rust that referenced this issue Sep 22, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
Centril added a commit to Centril/rust that referenced this issue Sep 24, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
@Centril Centril modified the milestones: 1.39, 1.40 Sep 26, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 27, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
Centril added a commit to Centril/rust that referenced this issue Sep 28, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
Centril added a commit to Centril/rust that referenced this issue Sep 28, 2019
…e-tests, r=nikomatsakis

Bugfix/rfc 2451 rerebalance tests

r? @nikomatsakis

Fixes rust-lang#64412
Depends/Contains on rust-lang#64414

cc rust-lang#55437 and rust-lang#63599
@nikomatsakis
Copy link
Contributor Author

@weiznich if you don't mind doing so, that'd be awesome! The other thing that might be useful is to rename the existing tests so they all fit the new naming scheme we were using.

@Centril
Copy link
Contributor

Centril commented Oct 14, 2019

@rfcbot resolve make-sure-we-add-these-tests
@rfcbot reviewed

Let's handle the tests with the stabilization PR. :)
@weiznich Perhaps you'd like to author the stabilization PR?

@rfcbot
Copy link

rfcbot commented Oct 14, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 14, 2019
@weiznich
Copy link
Contributor

@Centril stabilization PR means just a PR that moves this feature for active.rs to accepted.rs, change the state from active to accepted and the version number to 1.40.0. Additionally change the tests in src/test/ui/coherence to remove the feature because it's stable then.

Centril added a commit to Centril/rust that referenced this issue Oct 17, 2019
…komatsakis

Add more coherence tests

I've wrote the missing test cases listed in [this google doc](https://docs.google.com/spreadsheets/d/1WlroTEXE6qxxGvEOhICkUpqguYZP9YOZEvnmEtSNtM0/edit#gid=0)

> The other thing that might be useful is to rename the existing tests so they all fit the new naming scheme we were using.

I'm not entirely sure how to do this. If everything from the google sheet is covered could I just remove the remaining tests in `src/test/ui/coherence` or is there something in there that should remain?

cc rust-lang#63599

r? @nikomatsakis
Centril added a commit to Centril/rust that referenced this issue Oct 18, 2019
…komatsakis

Add more coherence tests

I've wrote the missing test cases listed in [this google doc](https://docs.google.com/spreadsheets/d/1WlroTEXE6qxxGvEOhICkUpqguYZP9YOZEvnmEtSNtM0/edit#gid=0)

> The other thing that might be useful is to rename the existing tests so they all fit the new naming scheme we were using.

I'm not entirely sure how to do this. If everything from the google sheet is covered could I just remove the remaining tests in `src/test/ui/coherence` or is there something in there that should remain?

cc rust-lang#63599

r? @nikomatsakis
tmandry added a commit to tmandry/rust that referenced this issue Oct 18, 2019
…komatsakis

Add more coherence tests

I've wrote the missing test cases listed in [this google doc](https://docs.google.com/spreadsheets/d/1WlroTEXE6qxxGvEOhICkUpqguYZP9YOZEvnmEtSNtM0/edit#gid=0)

> The other thing that might be useful is to rename the existing tests so they all fit the new naming scheme we were using.

I'm not entirely sure how to do this. If everything from the google sheet is covered could I just remove the remaining tests in `src/test/ui/coherence` or is there something in there that should remain?

cc rust-lang#63599

r? @nikomatsakis
tmandry added a commit to tmandry/rust that referenced this issue Oct 18, 2019
…komatsakis

Add more coherence tests

I've wrote the missing test cases listed in [this google doc](https://docs.google.com/spreadsheets/d/1WlroTEXE6qxxGvEOhICkUpqguYZP9YOZEvnmEtSNtM0/edit#gid=0)

> The other thing that might be useful is to rename the existing tests so they all fit the new naming scheme we were using.

I'm not entirely sure how to do this. If everything from the google sheet is covered could I just remove the remaining tests in `src/test/ui/coherence` or is there something in there that should remain?

cc rust-lang#63599

r? @nikomatsakis
tmandry added a commit to tmandry/rust that referenced this issue Oct 18, 2019
…komatsakis

Add more coherence tests

I've wrote the missing test cases listed in [this google doc](https://docs.google.com/spreadsheets/d/1WlroTEXE6qxxGvEOhICkUpqguYZP9YOZEvnmEtSNtM0/edit#gid=0)

> The other thing that might be useful is to rename the existing tests so they all fit the new naming scheme we were using.

I'm not entirely sure how to do this. If everything from the google sheet is covered could I just remove the remaining tests in `src/test/ui/coherence` or is there something in there that should remain?

cc rust-lang#63599

r? @nikomatsakis
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 23, 2019
…komatsakis

Add more coherence tests

I've wrote the missing test cases listed in [this google doc](https://docs.google.com/spreadsheets/d/1WlroTEXE6qxxGvEOhICkUpqguYZP9YOZEvnmEtSNtM0/edit#gid=0)

> The other thing that might be useful is to rename the existing tests so they all fit the new naming scheme we were using.

I'm not entirely sure how to do this. If everything from the google sheet is covered could I just remove the remaining tests in `src/test/ui/coherence` or is there something in there that should remain?

cc rust-lang#63599

r? @nikomatsakis
@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Oct 24, 2019
@rfcbot
Copy link

rfcbot commented Oct 24, 2019

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbot rfcbot removed the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Oct 24, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 26, 2019
…low-fundamental-local, r=nikomatsakis

Coherence should allow fundamental types to impl traits when they are local

After rust-lang#64414, `impl<T> Remote for Box<T> { }` is disallowed, but it is also disallowed in liballoc, where `Box` is a local type!

Enabling `#![feature(re_rebalance_coherence)]` in `liballoc` results in:
```
error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct<F>`)
    --> src\liballoc\boxed.rs:1098:1
     |
1098 | impl<F: ?Sized + Future + Unpin> Future for Box<F> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `F` must be used as the type parameter for some local type
```

This PR relaxes `uncover_fundamental_ty` to skip local fundamental types.
I didn't add a test since `liballoc` already fails to compile, but I can add one if needed.

r? @nikomatsakis

cc rust-lang#63599
Centril added a commit to Centril/rust that referenced this issue Oct 26, 2019
…low-fundamental-local, r=nikomatsakis

Coherence should allow fundamental types to impl traits when they are local

After rust-lang#64414, `impl<T> Remote for Box<T> { }` is disallowed, but it is also disallowed in liballoc, where `Box` is a local type!

Enabling `#![feature(re_rebalance_coherence)]` in `liballoc` results in:
```
error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct<F>`)
    --> src\liballoc\boxed.rs:1098:1
     |
1098 | impl<F: ?Sized + Future + Unpin> Future for Box<F> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `F` must be used as the type parameter for some local type
```

This PR relaxes `uncover_fundamental_ty` to skip local fundamental types.
I didn't add a test since `liballoc` already fails to compile, but I can add one if needed.

r? @nikomatsakis

cc rust-lang#63599
Centril added a commit to Centril/rust that referenced this issue Oct 27, 2019
…low-fundamental-local, r=nikomatsakis

Coherence should allow fundamental types to impl traits when they are local

After rust-lang#64414, `impl<T> Remote for Box<T> { }` is disallowed, but it is also disallowed in liballoc, where `Box` is a local type!

Enabling `#![feature(re_rebalance_coherence)]` in `liballoc` results in:
```
error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct<F>`)
    --> src\liballoc\boxed.rs:1098:1
     |
1098 | impl<F: ?Sized + Future + Unpin> Future for Box<F> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `F` must be used as the type parameter for some local type
```

This PR relaxes `uncover_fundamental_ty` to skip local fundamental types.
I didn't add a test since `liballoc` already fails to compile, but I can add one if needed.

r? @nikomatsakis

cc rust-lang#63599
@Centril Centril modified the milestones: 1.40, 1.41 Nov 7, 2019
@bors bors closed this as completed in 98c173a Nov 9, 2019
@Centril Centril removed this from the 1.41 milestone Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. F-re_rebalance_coherence `#![feature(re_rebalance_coherence)]` finished-final-comment-period The final comment period is finished for this PR / Issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants