-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Implement DIP36 - 'scope ref' and 'in ref' for proper rvalue reference #1903
Conversation
|
Good work Kenji, as always. Hope it will be merged soon. :) |
|
Oh... my... god...! |
|
The simplicity of this patch gives me confidence that it is good language design. |
|
It helps that the feature makes perfect sense. When I learned that scope existed, I presumed this is what it was for. It seems like it was destined for this purpose from the start. |
|
Let us hope that Walter and Andrei think the same about it. |
|
Him, it does not really implement "prohibit escaping of scope" right now, does it? |
No. But I think it should be done near the future. |
|
Sure. It is just important to not forget this is rather unsafe and dangerous feature until compiler control comes. |
|
@Dicebot People already do this by force of habit: void func(ref const matrix m);
func(x.getMatrix()); // error: @#%^&
matrix temp = x.getMatrix();
func(temp);Even if scope doesn't 'work' in the mean time, it at least gives the programmer the guide, so they know they can/should pass a temp if they want to. Right now, they can't possibly know if it's safely able to receive a temp or not, and just do it anyway because it usually is safe. |
|
@TurkeyMan I know. Right now it is never reliably safe which is a big hole in the type system. Introducing solution that pretends to give guarantees but actually does not may make it even worse. I'd prefer to see it together with scope implemented. |
|
I just can't agree with that. This is a better situation whether scope is fully implemented or not. It will change the probability of someone passing a temp to a function where it's not safe to do so. |
|
You can close this pull. It was so far rejected by Andrei. |
|
@9rnsr it would be great if you participated in the discussion, in particular how big the impact would be if we made |
|
@andralex I replied in the forum thread (http://forum.dlang.org/post/mailman.907.1366764128.4724.digitalmars-d@puremagic.com). I think that removing "parameterized-ref" (== current |
|
I'd love to see something like this get merged soon. I'd like to cut down on my extra "just for rvalue support" overloads. |
|
|
|
@9rnsr: Since your pull might sit here for a long while, would it be ok if I made a fix for Issue 8121. It seems all I have to do is remove the parser limitation for |
|
@AndrejMitrovic I'd say fixing anything related to |
|
The code that would break is code which does what scope is technically already supposed to prevent, e.g.: int* p;
void foo(scope int* x) { p = x; }
void bar(scope ref int x) { p = &x; }This code would break once scope is properly implemented, but that's a good thing. I think this is about the only definition of |
|
@AndrejMitrovic |
|
@Dicebot: |
|
We have already tried it... :D |
|
@Dgame there are no DIP's on |
|
@Dicebot It was meant as a joke, because we also had conceived functionality for scope with our scope/in ref proposal. |
http://wiki.dlang.org/DIP36
scope refandin refparameters can bind both lvalues and rvalues.