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

Add a query for resolving an impl item from the trait item #90639

Merged
merged 6 commits into from
Jan 8, 2022

Conversation

matthewjasper
Copy link
Contributor

@matthewjasper matthewjasper commented Nov 5, 2021

This makes finding the item in an impl that implements a given trait item a query. This is for a few reasons:

  • To slightly improve performance
  • To avoid having to do name resolution during monomorphisation
  • To make it easier to implement potential future features that create anonymous associated items

@rust-highfive
Copy link
Collaborator

Some changes occured to rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in intra-doc-links.

cc @jyn514

@rust-highfive
Copy link
Collaborator

r? @oli-obk

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 5, 2021
@rust-log-analyzer

This comment has been minimized.

@matthewjasper
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 6, 2021
@bors
Copy link
Contributor

bors commented Nov 6, 2021

⌛ Trying commit 96121514f93fd7bcf6507d9f04503656387680bf with merge 43062b0944a88c99e00100158c147d67e34081c0...

@bors
Copy link
Contributor

bors commented Nov 6, 2021

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

@rust-timer
Copy link
Collaborator

Queued 43062b0944a88c99e00100158c147d67e34081c0 with parent 0d1754e, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (43062b0944a88c99e00100158c147d67e34081c0): comparison url.

Summary: This change led to large relevant mixed results 🤷 in compiler performance.

  • Large improvement in instruction counts (up to -2.1% on full builds of deeply-nested)
  • Large regression in instruction counts (up to 2.6% on incr-patched: compile one builds of regex)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 6, 2021
@cjgillot cjgillot self-assigned this Nov 6, 2021
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

This seems like there is an unfortunate recomputation of typeck. Do you have an idea where it comes from?
The three first commits look good. Can they be merged independently?
I have the impression this PR introduces queries for two separate things:

  • first a query to translate impl item <-> trait item;
  • second a query for associated_item_lookup.

Should their effect be assessed independently?

compiler/rustc_middle/src/query/mod.rs Show resolved Hide resolved
compiler/rustc_typeck/src/check/mod.rs Outdated Show resolved Hide resolved
@matthewjasper
Copy link
Contributor Author

The recomputation probably comes from the Span of the Ident in NamedAssocItem being included in the stable hash. That said I agree that this PR should be split up to make it easier to experiment on each change individually.

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 11, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 11, 2021
…jgillot

Assoc item cleanup

This removes some fields from ObligationCauseCode

Split out of rust-lang#90639
@matthewjasper matthewjasper 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 Nov 12, 2021
@cjgillot
Copy link
Contributor

cjgillot commented Jan 7, 2022

Just in case:
@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 7, 2022
@bors
Copy link
Contributor

bors commented Jan 7, 2022

⌛ Trying commit 9d625bc with merge b4a612688e5135afb476f64bbe2508f028fe9268...

@bors
Copy link
Contributor

bors commented Jan 8, 2022

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

@rust-timer
Copy link
Collaborator

Queued b4a612688e5135afb476f64bbe2508f028fe9268 with parent e012a19, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b4a612688e5135afb476f64bbe2508f028fe9268): comparison url.

Summary: This change led to small relevant improvements 🎉 in compiler performance.

  • Small improvement in instruction counts (up to -0.9% on full builds of deeply-nested-closures)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 8, 2022
@camelid
Copy link
Member

camelid commented Jan 8, 2022

Perf looks good.

@cjgillot
Copy link
Contributor

cjgillot commented Jan 8, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jan 8, 2022

📌 Commit 9d625bc has been approved by cjgillot

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 8, 2022
@bors
Copy link
Contributor

bors commented Jan 8, 2022

⌛ Testing commit 9d625bc with merge 488acf8...

@bors
Copy link
Contributor

bors commented Jan 8, 2022

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 488acf8 to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (488acf8): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@camelid
Copy link
Member

camelid commented Jan 8, 2022

Hmm, not sure why the summary included the doc improvements before but not now. The doc improvements are still there though.

Comment on lines 983 to +985
let is_implemented = ancestors
.leaf_def(tcx, trait_item.ident, trait_item.kind)
.map(|node_item| !node_item.defining_node.is_from_trait())
.unwrap_or(false);
.leaf_def(tcx, trait_item_id)
.map_or(false, |node_item| node_item.item.defaultness.has_value());
Copy link
Member

Choose a reason for hiding this comment

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

I think this changed values of is_implemented. Previously it was true only if it's implemented in this implementation (and was false when there were a default impl in the trait). Is this intended? (this broke #92164 and not I'm figuring out how to fix it)

2022-01-09_20-21
2022-01-09_17-27

(the first screenshot from e012a19 commit, just before these changes, the second is after these changes; I've added a debug! in this loop)

Copy link
Member

Choose a reason for hiding this comment

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

And if this was intended, how can I specifically check that this item is implemented manually in a given impl (ie it doesn't use default implementation from the trait)?

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2022
…atthewjasper

Link impl items to corresponding trait items in late resolver.

Hygienically linking trait impl items to declarations in the trait can be done directly by the late resolver. In fact, it is already done to diagnose unknown items.

This PR uses this resolution work and stores the `DefId` of the trait item in the HIR. This avoids having to do this resolution manually later.

r? `@matthewjasper`
Related to rust-lang#90639. The added `trait_item_id` field can be moved to `ImplItemRef` to be used directly by your PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.