-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 TraitDef::find_map_relevant_impl #77754
Conversation
Some changes occurred in intra-doc-links. cc @jyn514 |
(rust_highfive has picked a reviewer for you, use r? to override) |
if let Some(item) = self.associated_items(impl_did).in_definition_order().next() { | ||
if validate(self, impl_did).is_ok() { | ||
dtor_did = Some(item.def_id); | ||
return Some(item.def_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically I'm changing the semantics here. The old code returned the last def_id
, while the new one returns the first. Let me know if this is a problem.
I think you could write |
I'm not sure because |
All FnMut closures also implement Fn. |
@jyn514 Do you have something like this in mind? pub fn for_each_relevant_impl<F: FnMut(DefId)>(
self,
def_id: DefId,
self_ty: Ty<'tcx>,
mut f: F,
) {
let _: Option<()> = self.find_map_relevant_impl(def_id, self_ty, |did| {
f(did);
None
});
} The problem is, that the inner closure can't borrow f as mutable.
|
Hmm, could you change |
I can, but none of the current usages need FnMut so I wanted to avoid that. |
I don't think there's any reason to avoid FnMut. APIs should be flexible unless there's a specific reason not to make them so. And indeed there is a usage that requires it: the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but someone who works in this part of the compiler should make sure it has the same behavior
@bors try @rust-timer queue Let's see if this actually helps compile times. |
Awaiting bors try build completion |
⌛ Trying commit 217d6f9 with merge 98ba3259700b5141f095cde6e8255e29402bf5cd... |
☀️ Try build successful - checks-actions, checks-azure |
Queued 98ba3259700b5141f095cde6e8255e29402bf5cd with parent 53a4c3b, future comparison URL. |
Finished benchmarking try commit (98ba3259700b5141f095cde6e8255e29402bf5cd): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
Small improvement on |
@bors r+ rollup=maybe |
📌 Commit 217d6f9 has been approved by |
Rollup of 10 pull requests Successful merges: - rust-lang#77195 (Link to documentation-specific guidelines.) - rust-lang#77629 (Cleanup of `eat_while()` in lexer) - rust-lang#77709 (Link Vec leak doc to Box) - rust-lang#77738 (fix __rust_alloc_error_handler comment) - rust-lang#77748 (Dead code cleanup in windows-gnu std) - rust-lang#77754 (Add TraitDef::find_map_relevant_impl) - rust-lang#77766 (Clarify the debug-related values should take boolean) - rust-lang#77777 (doc: disambiguate stat in MetadataExt::as_raw_stat) - rust-lang#77782 (Fix typo in error code description) - rust-lang#77787 (Update `changelog-seen` in config.toml.example) Failed merges: r? `@ghost`
…-morse Monomorphize `calculate_dtor` instead of using function pointers Change `calculate_dtor` to avoid dynamic dispatching. This change allows the empty functions to be optimized away. Based on the discussion in rust-lang#77754 (comment), the performance impact of this change was measured. Perf run results: https://perf.rust-lang.org/compare.html?start=7bc5839e99411aad9061a632b62075d1346cbb3b&end=ffec759ae9bbc4d6d2235ff40ade6723a85bc7cc
…orse Monomorphize `calculate_dtor` instead of using function pointers Change `calculate_dtor` to avoid dynamic dispatching. This change allows the empty functions to be optimized away. Based on the discussion in rust-lang#77754 (comment), the performance impact of this change was measured. Perf run results: https://perf.rust-lang.org/compare.html?start=7bc5839e99411aad9061a632b62075d1346cbb3b&end=ffec759ae9bbc4d6d2235ff40ade6723a85bc7cc
This PR adds a method to
TraitDef
. Whilefor_each_relevant_impl
covers the general use case, sometimes it's not necessary to scan through all the relevant implementations, so this PR introduces a new method,find_map_relevant_impl
. I've also replaced thefor_each_relevant_impl
calls where possible.I'm hoping for a tiny bit of efficiency gain here and there.