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

Make find_similar_impl_candidates a little fuzzier. #92223

Closed
wants to merge 3 commits into from

Conversation

BGR360
Copy link
Contributor

@BGR360 BGR360 commented Dec 23, 2021

Resolves #92113

This is the initial draft, I'm curious for your thoughts. Still need to write ui tests for the arrays/slices case.

Let me know if anything is unclear; I stayed up far too late and am far too tired to document my decisions in more detail at this very moment 😁

r? @lcnr

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 23, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 23, 2021
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.

it might be meaningful to also sort by whether the non-self parameters of the impls also match the searched ones.

would be nice to try this here if you're interested, otherwise we can also merge this as is.

i might not be available over the holidays, so you may have to wait a week until i can come back to you

@@ -56,7 +57,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
trait_ref.substs.types().skip(1),
impl_trait_ref.substs.types().skip(1),
)
.all(|(u, v)| self.fuzzy_match_tys(u, v))
.all(|(u, v)| self.fuzzy_match_tys(u, v, StripReferences::No))
Copy link
Contributor

Choose a reason for hiding this comment

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

are there unwanted changes when using StripReferences::Yes here?

Comment on lines 1527 to 1529
// Pass `StripReferences::Yes` because although we do want to
// be fuzzier than `simplify_type`, we don't want to be
// *too* fuzzy.
Copy link
Contributor

Choose a reason for hiding this comment

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

that reasoning seems unclear to me 🤔 how does passing StripReferences::Yes prevent ourselves from being "too fuzzy"?

Comment on lines 1510 to 1524
// Check for match between simplified types.
let imp_simp = fast_reject::simplify_type(
self.tcx,
imp.self_ty(),
SimplifyParams::Yes,
StripReferences::Yes,
);
if let Some(imp_simp) = imp_simp {
if simp == imp_simp {
return Some(ImplCandidate {
trait_ref: imp,
similarity: CandidateSimilarity::Simplified,
});
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't believe that this special case has a meaningful advantage over only using exact matches and fuzzy matches.
I would prefer removing this and removing the StripReferences function parameter from simplify_type. This should be the only place where it is currently used.

@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 Jan 10, 2022
@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 23, 2022
@JohnCSimon
Copy link
Member

Ping from triage:
@BGR360 can you post your status on this PR? Thanks.

@BGR360
Copy link
Contributor Author

BGR360 commented Jan 24, 2022

Sorry, been a lot of other stuff on my mind recently. I don't have immediate plans to continue on this, unless someone really wants this to get in.

@lcnr
Copy link
Contributor

lcnr commented Jan 25, 2022

@BGR360 went and continued this PR in #93298, hope I understood your comment correctly and you don't mind '^^

@BGR360
Copy link
Contributor Author

BGR360 commented Jan 25, 2022

@lcnr I don't mind at all, thank you for carrying the torch for me!

@lcnr
Copy link
Contributor

lcnr commented Jan 28, 2022

closing it as i expect us to merge #93298, again thank you @BGR360

@lcnr lcnr closed this Jan 28, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2022
make `find_similar_impl_candidates` even fuzzier

continues the good work of `@BGR360` in rust-lang#92223. I might have overshot a bit and we're now slightly too fuzzy 😅

with this we can now also simplify `simplify_type`, which is nice :3
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.

Regression in diagnostic quality for unimplemented traits on arrays.
5 participants