Skip to content

Consider bounds on inherent impl in method resolution #13074

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

Merged

Conversation

lowr
Copy link
Contributor

@lowr lowr commented Aug 21, 2022

There are three type-related things we should consider in method resolution: Self type, receiver type, and impl bounds. While we check the first two and impl bounds on trait impls, we've been ignoring the impl bounds on inherent impls. With this patch rust-analyzer now takes them into account and is able to select the appropriate inherent method.

Resolves #5441
Resolves #12308

@lowr
Copy link
Contributor Author

lowr commented Aug 21, 2022

Note that this doesn't resolve #11759, which seem to have another issue involving chalk even after this patch. I'll post its detail there.

@flodiebold
Copy link
Member

LGTM and thanks for addressing this, did you / can you check rust-analyzer analysis-stats at least on the RA repo itself though?

@bors delegate+

@bors
Copy link
Contributor

bors commented Aug 21, 2022

✌️ @lowr can now approve this pull request

@lowr
Copy link
Contributor Author

lowr commented Aug 21, 2022

I've run analysis-stats and here's the result: exprs: 416013, ??ty: 907 (0%), ?ty: 114 (0%), !ty: 1, the same number as master. Would it be better to run it for other 3 crates as well so as to make sure we don't regress much?

@lowr
Copy link
Contributor Author

lowr commented Aug 21, 2022

Hm, I've run it for the three crates and while the numbers for webrender and ripgrep didn't change, there's minor increase in the number of unknown types for diesel (+8 compared to master). I'll look into this.

@lnicola
Copy link
Member

lnicola commented Aug 21, 2022

Heads-up, in case you didn't know: if you run it with rust-analyzer -v -v analysis-stats, you'll get a list of those.

@flodiebold
Copy link
Member

flodiebold commented Aug 21, 2022

Since we in general have some problems with the traits in Diesel, it's very possible that we're not able to resolve some trait bounds that are actually true. We should have some fallback in those situations (i.e. use a method with a bound that can't be proven, if it's unique, and report an error message), but that will complicate things quite a bit (and we also want to e.g. fall back to private methods if no public methods are found). So I would do that in a separate PR.

@lowr
Copy link
Contributor Author

lowr commented Aug 21, 2022

Right, I'll merge this now and will open an issue (or a PR, if it's easy to fix) once I find out what went wrong.

By the way, it'd be nice if we could have something like rust-timer that runs analysis-stats and whatnot and compares the result on request.

@bors r+

@bors
Copy link
Contributor

bors commented Aug 21, 2022

📌 Commit dd22aa4 has been approved by lowr

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 21, 2022

⌛ Testing commit dd22aa4 with merge a670ff8...

@bors
Copy link
Contributor

bors commented Aug 21, 2022

☀️ Test successful - checks-actions
Approved by: lowr
Pushing a670ff8 to master...

@bors bors merged commit a670ff8 into rust-lang:master Aug 21, 2022
bors added a commit that referenced this pull request Feb 19, 2024
Setup infra for handling auto trait bounds disabled due to perf problems

This patch updates some of the partially-implemented functions of `ChalkContext as RustIrDatabase`, namely `adt_datum()` and `impl_provided_for()`. With those, we can now correctly work with auto trait bounds and distinguish methods based on them.

Resolves #7856 (the second code; the first one is resolved by #13074)

**IMPORTANT**: I don't think we want to merge this until #7637 is resolved. Currently this patch introduces A LOT of unknown types and type mismtaches as shown below. This is because we cannot resolve items like `hashbrown::HashMap` in `std` modules, leading to auto trait bounds on them and their dependents unprovable.

|crate (from `rustc-perf@c52ee6` except for r-a)|e3dc5a588f07d6f1d3a0f33051d4af26190abe9e|HEAD of this branch|
|---|---|---|
|rust-analyzer @ e3dc5a5 |exprs: 417528, ??ty: 907 (0%), ?ty: 114 (0%), !ty: 1|exprs: 417528, ??ty: 1704 (0%), ?ty: 403 (0%), !ty: 20|
|ripgrep|exprs: 62120, ??ty: 2 (0%), ?ty: 0 (0%), !ty: 0|exprs: 62120, ??ty: 132 (0%), ?ty: 58 (0%), !ty: 11|
|webrender/webrender|exprs: 94355, ??ty: 49 (0%), ?ty: 16 (0%), !ty: 2|exprs: 94355, ??ty: 429 (0%), ?ty: 130 (0%), !ty: 7|
|diesel|exprs: 132591, ??ty: 401 (0%), ?ty: 5129 (3%), !ty: 31|exprs: 132591, ??ty: 401 (0%), ?ty: 5129 (3%), !ty: 31|
bors added a commit that referenced this pull request Feb 19, 2024
Setup infra for handling auto trait bounds disabled due to perf problems

This patch updates some of the partially-implemented functions of `ChalkContext as RustIrDatabase`, namely `adt_datum()` and `impl_provided_for()`. With those, we can now correctly work with auto trait bounds and distinguish methods based on them.

Resolves #7856 (the second code; the first one is resolved by #13074)

**IMPORTANT**: I don't think we want to merge this until #7637 is resolved. Currently this patch introduces A LOT of unknown types and type mismtaches as shown below. This is because we cannot resolve items like `hashbrown::HashMap` in `std` modules, leading to auto trait bounds on them and their dependents unprovable.

|crate (from `rustc-perf@c52ee6` except for r-a)|e3dc5a588f07d6f1d3a0f33051d4af26190abe9e|HEAD of this branch|
|---|---|---|
|rust-analyzer @ e3dc5a5 |exprs: 417528, ??ty: 907 (0%), ?ty: 114 (0%), !ty: 1|exprs: 417528, ??ty: 1704 (0%), ?ty: 403 (0%), !ty: 20|
|ripgrep|exprs: 62120, ??ty: 2 (0%), ?ty: 0 (0%), !ty: 0|exprs: 62120, ??ty: 132 (0%), ?ty: 58 (0%), !ty: 11|
|webrender/webrender|exprs: 94355, ??ty: 49 (0%), ?ty: 16 (0%), !ty: 2|exprs: 94355, ??ty: 429 (0%), ?ty: 130 (0%), !ty: 7|
|diesel|exprs: 132591, ??ty: 401 (0%), ?ty: 5129 (3%), !ty: 31|exprs: 132591, ??ty: 401 (0%), ?ty: 5129 (3%), !ty: 31|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mismatched-arg-count lint on macro that impl same name methods Error on DMatrix::zeros(rows, cols)
4 participants