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

Sort "the following types implement the trait" suggestion #120012

Closed
wants to merge 1 commit into from

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Jan 16, 2024

This should help external UI tests using trybuild by being less non-deterministic.

This is somewhat hard to reproduce, as it basically requires two different machines, but I've been consistently running into this for the past few months with the output from my CI differing from my local setup (example of a failed workflow in here).

This should help external UI tests using `trybuild` by being less non-deterministic.
@rustbot
Copy link
Collaborator

rustbot commented Jan 16, 2024

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@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 Jan 16, 2024
@madsmtm
Copy link
Contributor Author

madsmtm commented Jan 16, 2024

Actually, thinking about it, this can be reproduced on macOS by using Rosetta. I don't have a smaller test-case at hand, but in https://github.com/madsmtm/objc2, running the following commands generate different .stderr files.

TRYBUILD=overwrite cargo run --features=run --bin test-ui --target=aarch64-apple-darwin
TRYBUILD=overwrite cargo run --features=run --bin test-ui --target=x86_64-apple-darwin

@petrochenkov
Copy link
Contributor

If non_blanket_impls() or blanket_impls() return a non-deterministic result, then maybe there's a deeper issue here that would be better to track to its root cause and resolve properly instead of hiding it with sorting in this specific diagnostic.

The diff from CI:

             (dyn NSObjectProtocol + 'static)
             (dyn NSObjectProtocol + Sync + 'static)
-            (dyn NSObjectProtocol + Send + 'static)
             (dyn NSObjectProtocol + Send + Sync + 'static)
+            (dyn NSObjectProtocol + Send + 'static)
             (dyn NSCopying + 'static)
             (dyn NSMutableCopying + 'static)
             (dyn NSCacheDelegate + 'static)

cc @rust-lang/types
@rustbot author

@rustbot rustbot 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 Jan 16, 2024
@lcnr
Copy link
Contributor

lcnr commented Jan 16, 2024

I can't test this myself, but collecting impls should be deterministic

pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> TraitImpls {

HOWEVER: impls in extern crates are iterated using tcx.crates(()).iter() and local impls via tcx.hir().trait_impls which relies on rustc_resolve which iirc walks the ast. Both of these can change the order of impls due to optional dependencies and cfgs.

@petrochenkov
Copy link
Contributor

petrochenkov commented Jan 16, 2024

Both of these can change the order of impls due to optional dependencies and cfgs.

That's true, but CI failure example doesn't look like something originating from that?
Looks more like an issue with sorting of dyn Trait + AutoTraits + 'lifetimes types.

It would be good if @madsmtm made a minimized reproduction for this issue.

@madsmtm
Copy link
Contributor Author

madsmtm commented Jan 16, 2024

maybe there's a deeper issue here that would be better to track to its root cause and resolve properly instead of hiding it with sorting in this specific diagnostic.

Fair enough. I went with the sorting here because it was a simple fix, and is done elsewhere to make errors stable across invocations.

@madsmtm
Copy link
Contributor Author

madsmtm commented Jan 17, 2024

It would be good if @madsmtm made a minimized reproduction for this issue.

Sorry, I didn't see your comment before now. I'll try to narrow down a reproduction, can't guarantee any timeline on that though ;).

@lcnr
Copy link
Contributor

lcnr commented Jan 26, 2024

https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/codegen-units.20impacts.20order.20of.20impls

i encountered the underlying issue separately, it can be triggered using the following extern crate

pub trait Trait {}

impl Trait for &u32 {}
impl Trait for &u16 {}

the order of these two impls is different depending on the number of codegen-units (probably depends on the crate hash somehow)

@lcnr
Copy link
Contributor

lcnr commented Jan 26, 2024

opened #120371 for the underlying bug here

@bors
Copy link
Contributor

bors commented Feb 5, 2024

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

@JohnCSimon
Copy link
Member

@madsmtm

ping from triage - can you post your status on this PR? This PR has not received an update in a few months.

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

Or if you're not going to continue, please close it. Thank you!

@madsmtm
Copy link
Contributor Author

madsmtm commented Apr 14, 2024

I think the problem I was having will be resolved by #120812, so am going to close this, thanks for the ping!

@madsmtm madsmtm closed this Apr 14, 2024
@madsmtm madsmtm deleted the sort-suggestion branch April 14, 2024 18:09
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. 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.

6 participants