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

Handle projections as uncovered types during coherence check #100555

Closed
wants to merge 11 commits into from

Conversation

atsuzaki
Copy link
Contributor

Fixes #99554. Update code to handle projections as uncovered types during coherence check/orphan check & update error messages accordingly.

@rust-highfive
Copy link
Collaborator

r? @oli-obk

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

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 14, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 14, 2022
@atsuzaki
Copy link
Contributor Author

r? @lcnr

@rust-highfive rust-highfive assigned lcnr and unassigned oli-obk Aug 14, 2022
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

there are still 2 tests where the error messages aren't quite right

please fix the error messages for them and add them as additional tests

going to start a crater run for this

@lcnr
Copy link
Contributor

lcnr commented Aug 15, 2022

@bors try

@bors
Copy link
Contributor

bors commented Aug 15, 2022

⌛ Trying commit ba88709461a684be5ef433e2da892492ebde60b0 with merge df0acfe6d8f079d1fdd8e6b7447569d81b00f126...

@bors
Copy link
Contributor

bors commented Aug 15, 2022

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

@lcnr
Copy link
Contributor

lcnr commented Aug 15, 2022

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-100555 created and queued.
🤖 Automatically detected try build df0acfe6d8f079d1fdd8e6b7447569d81b00f126
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2022
@craterbot
Copy link
Collaborator

🚧 Experiment pr-100555 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-100555 is completed!
📊 208 regressed and 4 fixed (241311 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 16, 2022
@lcnr
Copy link
Contributor

lcnr commented Aug 17, 2022

ok, we have more regressions than I would like. Most of them look like they use fully concrete projections though, and these are fine.

I see two ways forward here:

  • simply check whether the projection contains any generic parameters and fail in that case, or
    - actually recursively orphan check each projection using InCrate::Remote and consider them as non-local type if the orphan check fails and as uncovered projection/param if that orphan check succeeds.

I think recursively orphan checking projections seems like a better solution to me, so I would go with that. When encountering a projection in the type visitor, call orphan_check_trait_ref for that projection, if that fails, treat the projection as a non-local type, if it succeeds, treat it as an uncovered type.

edit: The second approach sadly does not work, as even a local impl can use a type parameter as an associated type if it's used as in input.

@rust-log-analyzer

This comment has been minimized.

|
LL | impl<T> Remote1<Box<T>> for u32 {
| ^ type parameter `T` must be used as the type parameter for some local type
| ^^^^^^ type parameter `T` must be used as the type parameter for some local type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lcnr This is one of the last (visual) kinks... I was able to detect the fundamental type for cases like impl<T> Remote for Box<T> where the T is at idx=0, and I can look at self_ty which is a rustc_middle::Ty.

But in this case, I only have a hir::Ty and can't figure out how it's a fundamental type from that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@atsuzaki atsuzaki requested a review from lcnr August 25, 2022 01:54
@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 Sep 14, 2022
@lcnr lcnr 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 Sep 21, 2022
@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 3, 2022
@rfcbot
Copy link

rfcbot commented Oct 3, 2022

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

@nikomatsakis
Copy link
Contributor

@lcnr can you give a bit more details about the wasmer crate? I feel like we ought to reach out to them to discuss possible solutions, as that is a pretty broadly used crate.

@nikomatsakis
Copy link
Contributor

cc @matklad @nagisa -- two owners of the wasmer-types crate

@lcnr
Copy link
Contributor

lcnr commented Oct 4, 2022

The root cause seems to be the Deserialize derive from https://github.com/rkyv/rkyv.

This derive emits the following impl:

#[derive(Deserialize, Archive)]
struct Foo<T>(T);
impl<T, D> Deserialize<Foo<T>, D> for <Foo<T> as Archive>::Archived {
    // ...
}

impl<T> Archive for Foo<T> {
   type Assoc = LocalType;
}

See https://gist.github.com/lcnr/75d99bd2900f9dd2eaa558b3c68c42e2 for the full (cleaned up) output.

This could be adapted to pass the new orphan rules by switching the argument ordering of Deserialize: instead of ARCHIVE: Deserialize<TYPE, DESERIALIZER> it could be TYPE: Deserialize<ARCHIVE, DESERIALIZER>. This would be probably be the easiest fix (even if it is a breaking change for rkyv).

There are hacks which would only require a minor update of rkyv while still allowing us to error on unsound impls, e.g. by adding some #[no_uncovered_param] attribute to associated types (in the trait definition) which causes us to consider that associated type to always only be a non-local type and requires all impls to not directly use T or Fundamental<T> for it. I don't think that idea is worth it and can't think of one which is.

@matklad
Copy link
Member

matklad commented Oct 4, 2022

cc @djkoloski

@djkoloski
Copy link
Contributor

If I'm understanding this problem correctly, this could also be addressed by emitting a concrete ARCHIVE type instead of referring to it indirectly through the Archive trait's associated type. Is that accurate? I'd have to check and make sure, but that seems more achievable for rkyv.

@lcnr
Copy link
Contributor

lcnr commented Oct 4, 2022

yes, using the concrete type for the archive instead of an associated type works as well

@djkoloski
Copy link
Contributor

Great, I'll take action on rkyv/rkyv#289 and cut a new release as soon as possible.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 13, 2022
@rfcbot
Copy link

rfcbot commented Oct 13, 2022

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.

This will be merged soon.

@jackh726 jackh726 added the relnotes Marks issues that should be documented in the release notes of the next release. label Oct 13, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Oct 20, 2022

@atsuzaki could you rebase the PR and fix the conflict? I think we're ready to merge

@lcnr
Copy link
Contributor

lcnr commented Oct 20, 2022

we still have to convert this to a future-compat lint before merging this, intend to meet with @atsuzaki to figure out how exactly this should be done

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Dec 8, 2022
@apiraino
Copy link
Contributor

Hi, how is this progressing? Any updates to report cc @lcnr @atsuzaki ? Thanks!

@atsuzaki
Copy link
Contributor Author

@apiraino hi, I sadly no longer have time to work on this. I've spoken to @lcnr about them/someone possibly taking over this?

@JohnCSimon
Copy link
Member

@atsuzaki

Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this.
Note: if you are going to continue please open the PR BEFORE you push to it, else you won't be able to reopen - this is a quirk of github.
Thanks for your contribution.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this May 28, 2023
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label May 28, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2024
Normalize trait ref before orphan check & consider ty params in alias types to be uncovered

Fixes rust-lang#99554, fixes rust-lang/types-team#104.

Supersedes rust-lang#100555.

r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 30, 2024
Lazily normalize inside trait ref during orphan check & consider ty params in rigid alias types to be uncovered

Fixes rust-lang#99554, fixes rust-lang/types-team#104.
Fixes rust-lang#114061.

Supersedes rust-lang#100555.

Tracking issue for the future compatibility lint: rust-lang#124559.

r? lcnr
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. finished-final-comment-period The final comment period is finished for this PR / Issue. relnotes Marks issues that should be documented in the release notes of the next release. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

orphan check incorrectly handles projections