-
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
Delegate Iterator::try_fold for Iterators taken by reference #62483
Delegate Iterator::try_fold for Iterators taken by reference #62483
Conversation
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
If the dang |
^It's required for trait objects to work |
Trying explicitly specializing |
Thanks for the PR @czipperz! It looks like our build failure is because some of the UI tests are producing different errors with this change:
Are you able to run the build locally, or would you like me to take a look at how they've changed? |
Ping from triage, any updates? @czipperz |
Should be fixed now. |
060c290
to
0ecda3d
Compare
Thanks @czipperz! It looks like we do already have a few cases where we use specialization in iterators, and this one seems possible to back out of. I haven't been very closely following specialization though, so I'm on board with this so long as it falls within the currently expected sound implementation of it. cc @rust-lang/libs can anyone see any problems with doing this? |
We've exposed specialization features before for various performance optimizations here and there, but it's intended to currently always be done in such a way that it doesn't expose to users of libstd what's default and what's not. This is changing a critical blanket impl in the standard library and I'm not sure I'd be comfortable leveraging specialization that much. Is there perhaps compelling motivation for why we should land this even if it's somewhat risky from a specialization point of view? |
Thanks for the explanation @alexcrichton! I thought this may be a little risky, but it sounds like it’s quite risky. I guess the motivation here is to correctly delegate to |
Ah ok and to be clear I don't know of where this can go wrong, but it feels risky to be changing such a core implementation to be leveraging specialization for what can be presumably a somewhat critical performance concern. I do agree though that we probably want to wait on this for now in terms of performance, but this could also use the pattern of other specialization traits which is to use an internal trait to specialize rather than using the external one. |
I don't fully understand why specialization is fine using a private trait but not using a public trait, what makes the two different? Is removing specialization from a public trait a breaking change (for stable users) in a way that I haven't thought of? |
Functionally it ends up having the same goal, but it's slightly different from a public API perspective because it continue to now allow external users to override the implementation. (even on nightly) I mostly wanted to point out that's what's been done before. I'm not necessarily sure I'd be willing to commit personally to say it's ok in this case, I still sort of feel like this is such a core impl that it seems weird to have this and only single out |
So, based on the discussion in #60492 and here, it looks like we're not ready to consider this kind of specialization for the cc @rust-lang/libs I'm guessing now we'd try to limit uses of specialization to optimizations, rather then opening up delegations to public consumers? But if there's no current coherent strategy for how we apply it then it might be something worth discussing 🙂 Thanks again @czipperz! |
try_fold
is the most important method to delegate because all the others delegate to it when possible. (ieany
and the like)