-
Notifications
You must be signed in to change notification settings - Fork 13k
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
generalize "incoherent impls" impl for user defined types #96520
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
9204375
to
03113b4
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 03113b4344ffb6d8525f324973b749e1c8de50a9 with merge 6dd2f7a9b86fcbc5879bd666c301ed939021bc4f... |
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.
Is there a reason (other than maybe perf) to not just always assemble potentially incoherent impls, instead of adding a new rustc_has_incoherent_inherent_impls
? I guess it allows us to "lock down" the types a bit more too - but these are unstable attributes anyways.
Three other thoughts:
Should rustc_allow_incoherent_impl
be on the impl itself? Seems better than writing on every function.
In your previous PR, you added rustc_coherence_is_core
. Why not just use the same mechanism of rustc_allow_incoherent_impl
?
This somewhat reminds me of some of the discussions around arbitrary self types (#44874) and whether those methods get registered on the "Self" type, even if that type isn't a type you control (like Box<Foo>
).
☀️ Try build successful - checks-actions |
Queued 6dd2f7a9b86fcbc5879bd666c301ed939021bc4f with parent 3bfeffd, future comparison URL. |
Finished benchmarking commit (6dd2f7a9b86fcbc5879bd666c301ed939021bc4f): comparison url. Summary:
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 may lead to changes in compiler perf. @bors rollup=never Footnotes |
Yeah, I want to "lock down" which types can have incoherent impls. It doesn't matter too much as the impls also have to be explicitly mention that they are incoherent, but 🤷 considering that adding this attribute is pretty trivial it seems worth it to me.
I mentioned that in #94963 (comment). The idea is that adding incoherent impls should only be a last resort and avoided if possible. Having the attribute on assoc items instead of whole impls prevents people from accidentally adding functions to existing impls. E.g. the
don't fully get what you mean here? Why we don't use |
I also think It may be potentially useful for performance though, due to skipping |
This comment has been minimized.
This comment has been minimized.
2769b74
to
4592de0
Compare
hmm, I considered removing it after your comment, but it feels pretty valuable to me to immediately know which types have incoherent inherent impls, because these types are somewhat special from my pov. I don't expect there to be a perf difference depending on our approach here, considering that @rust-lang/libs-api given that you have some type/trait object which needs incoherent inherent impls what's your preferred solution here: Solution 1do not mark the types in any way, mark all incoherent impls with Looking at the library changes in this PR, this would amount to removing the Solution 2Add an attribute to types and traits which may have incoherent impls,mark all incoherent impls with This is currently implemented in this PR and is pretty verbose. |
@lcnr the most important property is that it be hard / impossible to accidentally add any new incoherent impls. I can't really think of any realistic situations where the attribute on the type would help prevent a mistake. The best I can come up with is someone mistakenly believing that a type already allows incoherent impls, and so allowing a new incoherent impl on the basis of that, but not actually checking the original type. That said, I think I'd prefer the verbosity still, if only because it is just one more barrier making it more annoying to add incoherent impls, which we already are fairly grumpy about needing in the first place. |
@lcnr I brought this up with the libs-api team during our meeting today and they agreed with my conclusion, we'd prefer the more verbose option, if we later have a good justification for simplify it we can do so then, but for now we want to default to a higher barrier to entry for using this feature, with the side benefit of improved search-ability being appreciated. |
This comment has been minimized.
This comment has been minimized.
ccf4763
to
ba0ecbd
Compare
src/test/ui/incoherent-inherent-impls/needs-has-incoherent-impls.rs
Outdated
Show resolved
Hide resolved
I still want to change the help messages depending on whether Think that the current state is pretty good, don't think there's a much better way to write this which keeps the different error messages depending on @rustbot ready |
That's exactly what I wanted to avoid though. |
@bors r+ |
📌 Commit 321162b has been approved by |
⌛ Testing commit 321162b with merge 3a79d200fc88150033665314bfa213e641dd989b... |
@petrochenkov I understand your reasoning here, but there are already a number of features that don't follow these. Off the top of my head, I can name |
☀️ Test successful - checks-actions |
Finished benchmarking commit (74cea9f): comparison url. Summary:
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
To allow the move of
trait Error
into core.continues the work from #94963, finishes rust-lang/compiler-team#487
r? @petrochenkov cc @yaahc