-
-
Notifications
You must be signed in to change notification settings - Fork 746
Add @nogc attribute to Socket receive methods #6730
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
Conversation
|
Thanks for your pull request and interest in making D better, @pinver! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#6730" |
|
In the future the commit message should refer to an issue number in the bug tracker. I've added it for this one. |
|
You are right, sorry. I'll open an issue the next time. |
CyberShadow
left a comment
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.
Unfortunately, because Socket is not a final class, this change will break code like this:
import std.socket;
class MySocket : Socket
{
override ptrdiff_t receive(void[] buf)
{
new int[1000];
return 0;
}
}There is a test to check against wrong attributes lower, but it looks like it hasn't triggered because the compiler is inferring @nogc from the method body.
Also, as a whole, std.socket is very much non-@nogc, so this change seems rather moot.
|
Understood: Is it acceptable to add to Socket something like I understand that as a whole, As a precedent, something similar is present in |
Not sure I can give a good answer to that. Generally,
What's special about |
Yes, I know that, but I would prefer to stick with plain old Phobos, for a series of reasons...
What have you in mind as
Well, nothing.... actually the use case that triggered the problems was in a receiver process.
I just want to keep the pull request small... it started as a small |
Before we lock ourselves into a local maximum by extending the public API while trying to fix this one particular problem, we should consider previous similar problems encountered in the past:
Perhaps one approach would be a |
Ok, I've read the references, it seems that for the foreseeable future we are pretty stuck to the actual situation.
Casting in the descendant to use the base methods, do you mean? What about adding a new final method with a different name to the actual socket, with the strictest possible attributes of its implementation, and forward and deprecate the old one to that? |
Yep.
No good. It would make a type system hole - non- |
If we cast, we must tag every new final method as That would turn code that can be mechanically checked as
The other way round: the old non- Derived classes can only override the old non- |
|
@pinver : In your use case, you might be able to just define a |
A private trusted wrapper would work too, but I agree it's better to have the compiler infer the attributes from the implementation raher than ensure by hand it matches up.
Ah, yes, that would work. It would be annoying to have to define/use alternate names for all the methods, though. Maybe put the final implementations into a new superclass that In any case, new additions would have to be reviewed by @andralex, maybe he will have a better idea. |
Thanks Mathias, if I'm not wrong, you still need to cast: That leads to the introduction of |
|
If you call the base method, yes. It's not a general solution by any means. But in this case I would just copy the code and call it a day. |
You are right, but on the other side, that pattern was already used in the past, for example in
My humble opinion is just to stick with minimal changes: the hot path in socket usage is bound to Adding a stricter method to the actual socket class seems to me the best way to proceed, with the minimum impact, also taking in account that we have the perspective of a better global refectory of IO with Martin Let's wait for Andrei. |
If I'm following your reasoning correctly, I can't do that, at least in an external module, as the needed data member |
|
|
@atilaneves , what is the best way to move forward on that? It would be great if we can define a 'generic' policy for other similar PR against Phobos. |
|
I'm not sure a generic policy would work, but in this case I'd say that given the potential breakage of child classes that we shouldn't merge. A Phobos v2 would then have |
|
Thank you Atila, The new old receive would simply forward to the old one, so that should not be a maintenance burden either. |
|
I'm not a fan of |
|
Thank you for your advice, we did something similar for our customer code: but I think the point here is on Phobos. Feel free to correct me if I'm speculating wrongly, but I've understood that your opinion is that the module should be rewritten / reorganised deeply (struct vs class for ex), potentially in Phobos V2, and that's fine. At the same time, while waiting, we are unable to write @nogc code in a hot IO path without recurring to @trusted. Reviewers simply asked us why, and why we needed to use custom code for something that simple, and not the consolidated, audited, standard library code. What are the drawback in adding a single, better method to a codebase that's should be rewritten? Can you elaborate further? In the discussion is pretty clear that the burden added to maintenance is really low. I don't want to press you too much on this, so this is my last attempt, then I will conform to your judgement as gatekeeper. |
|
@pinver I see. I guess the least bad option is a separate member function then. |
|
So, how should we move further here? |
|
|
|
ping @pinver |
|
Thank you all for your feedback, that's great! Actually I'm all-in in time-constrained mode ... |
|
@pinver is this still on your radar? |
|
@pinver I will close this for now, but please feel free to reopen and ping me whenever you have made some changes. |
ditto