<div dir="ltr">On 24 April 2013 04:29, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 4/23/13 2:00 PM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 24 April 2013 03:15, Andrei Alexandrescu<br></blockquote>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
    Many details are missing. This is not a simple problem.<br>
<br>
<br></div><div class="im">
So what are some others?<br>
</div></blockquote>
<br>
Returning a reference is an important topic.<br></blockquote><div><br></div><div style>I think that's easily solved. We've already touched on this.</div><div style>It just extends this same rule to the return value, only 'scope ref' may return a 'scope ref'.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
        An r-value passed this way produces a<br>
        temp, which is a stack variable. It's life is identical to any other<br>
<br>
        stack variable, ie, it lives for the life of the function where<br>
        it appears.<br>
<br>
<br>
    That's a possibility, but it's a departure from current semantics<br>
    and is not mentioned in the DIP.<br>
<br>
<br></div><div class="im">
I think it's presumed in the DIP, and it's certainly how Kenji<br>
implemented it.<br>
What 'current' semantic is it a departure from? The one where passing a<br>
literal produces a compile error? Certainly, that's the point.<br>
</div></blockquote>
<br>
Currently, rvalues exist until they have been consumed by a call. By DIP 36, some rvalues exist through the end of the function.<br></blockquote><div><br></div><div style>I don't think this is quite right. r-values never 'exist' at all, and they're not 'consumed'. They only come into existence when being copied to the callee's argument list, this makes them local to, and gives them the life of the callee.</div>
<div style>ref args must receive an existing object however, so in the ref case, a local temp must be created in the caller, which logically has the life of any other local.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
        auto-ref on the other hand IS a new feature (in this context),<br>
        and it<br>
        also makes no sense if you ask me. It's a template concept which<br>
        is not<br>
        applicable here.<br>
<br>
<br>
    It is a feature that has been implemented and works, just not in all<br>
    cases.<br>
<br>
<br></div><div class="im">
This isn't a 'case'. It's a separate issue.<br>
Safely passing a temp to a ref function arg, and whether a template<br>
argument is automatically determined to be ref or not are barely related<br>
problems.<br>
I still can't see how auto-ref has any business in this context.<br>
</div></blockquote>
<br>
They are related inasmuch they solve the same problem (define a function that accepts both lvalues and rvalues). They are distinct because currently in a template you could at least in theory figure out whether the function has been called with an lvalue on rvalue. The code below does not currently work but could be made to work:<br>

<br>
void fun(T)(auto ref T t)<br>
{<br>
    static if (is(t == ref)) {}<br>
}<br>
<br>
If we decide this feature is unnecessary (as I suspect is the case), we should change the implementation of auto ref to only use one body for both ref and non-ref versions.<br></blockquote><div><br></div><div style>I think you're conflating 2 problems to make them appear related.<br>
</div><div style>auto-ref is well defined as is when used with templates, if you change that, it'll break the purpose it was designed for.</div><div style>And again, it's not about accepting 'both lvalues and rvalues', it's got nothing to do with r-values.</div>
<div style>r-values can NEVER be accepted by a ref argument, they don't 'exist', we're talking about implicitly generated temporaries (which also addresses the issues with receiving _explicit_ temp's).</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
             In particular we are much more inclined to impart real,<br>
        demonstrable<br>
             safety to "ref"<br>
<br>
<br>
        ref is unsafe by definition.<br>
<br>
<br>
    We want to aim at making ref safe, thus making it useful as<br>
    restricted pass-down pointers. For full possibilities, one should<br>
    use pointers.<br>
<br>
<br></div><div class="im">
Okay, I'm good with that too, but how is that intended to work?<br>
If the intent is to make ref escaping disallowed by default, that is a<br>
major breaking change...<br>
</div></blockquote>
<br>
Walter and I are inclined to take the hit because we believe the upside is worth it.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Can we start talking about virtual-by-default again while we're at it?<br>
</blockquote>
<br></div>
There are no plans to change that.<br></blockquote><div><br></div><div style>Well we need to start discussing it then.</div><div style>The magnitude of the breakage is less than making ref safe, and if that's on the table, then this surely deserves some attention.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
        I don't believe this is possible without<br>
        some further justification.<br>
<br>
<br>
    The justification is that unsafe uses of ref are few and<br>
    uninteresting (they can be replaced with pointers). It would be very<br>
    powerful to be able to guarantee that safe code can use ref.<br>
<br>
<br></div><div class="im">
Again, this sounds like a major breaking change.<br>
Why is scope-ref inferior? It's more informative, and offers more<br>
flexibility (ie, the option of ref with or without scope)<br>
</div></blockquote>
<br>
Whether scope ref is inferior to the ref/auto ref combo is a judgment call. On the face of it, any new feature has to prove its utility so it starts from a somewhat disadvantaged position.</blockquote><div><br></div><div style>
Your proposal is an equally new feature, and surely stands on even ground.</div><div style>I still see that auto-ref is completely irrelevant if you make ref safe. I'm not sure why auto-ref keeps coming up under your proposal. It's fine applied to templates, and it's no longer required when applied to functions in the event ref can safely receive a temp.</div>
<div style><br></div><div style>I'm worried that your proposal significantly changes the meaning of multiple existing features (both ref, and auto-ref), at the cost of major breaking changes, while the DIP36 approach requires no changes to existing features, and makes perfect sense  logically. It also keeps control in the programmers hands, which I would never consider a problem.</div>
<div style><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
        DIP36 however creates a situation where it's known that passing<br>
        a temp<br>
        is actually safe.<br>
<br>
             and to make "auto ref" work as a reference that can bind to<br>
        rvalues<br>
             as well as lvalues.<br>
<br>
<br>
        What does it mean to make a reference bind to r-values aswell as<br>
        l-values? Lots of people keep saying this too, but it doesn't really<br>
        make sense to me either.<br>
<br>
<br>
    I don't understand the question as the answer is in it.<br>
<br>
<br>
        No reference can bind to r-values, r-values can not be addressed.<br>
</blockquote>
<br></div>
This is a matter of language definition. Rvalues can be bound to references today, and the bound references can be addressed.<br>
<br>
struct S { void fun() { writeln(&this); } }<br>
unittest { S().fun(); }<br></blockquote><div><br></div><div style>S() must just be an implicit local (just like every other instance of passing an rvalue-by-ref should be).</div><div style>If this code is possible, then a serious non-uniformity exists where this is not applied to all r-values, and that should be fixed on this basis alone.</div>
<div style><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
    But auto ref and scope ref do bind to r-values.<br>
<br>
<br>
        It's<br>
        really a temp copy of said r-value that we're dealing with,<br>
        which is an<br>
        l-value, ie, a local with a lifetime that's unsuitable for<br>
        passing by<br>
        non-scope-ref.<br>
        scope-ref would promise that it won't escape the callee, and thus is<br>
        safe to pass a temp.<br>
<br>
<br>
    Our aim is to have ref make that promise.<br>
<br>
<br>
        ref is fundamentally broken in D right now. DIP36 creates a<br>
        situation<br>
        where it could be fixed.<br>
<br>
<br>
    A new feature is not a fix.<br>
<br>
<br></div><div class="im">
If scope is a new feature, then the keyword shouldn't compile and<br>
pretend that it does stuff.<br>
</div></blockquote>
<br>
You are confusing a feature with a keyword. A given keyword may support many features, e.g. static, final etc.<br></blockquote><div><br></div><div style>Okay, so what does this add to scope that it doesn't already allege to promise?</div>
<div style>You're saying that "scope doesn't work now, therefore it's not a feature, only a plan, with reserved syntax"?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
It's an incomplete/unimplemented feature, not a new one.<br>
People are aware of it, they can write code that presumes it's present<br>
and working. It compiles successfully.<br>
<br></div><div class="im">
        I would personally take DIP36 one step further,<br>
        and ban all local's from being passed to non-scope ref.<br>
        Yes, a breaking change, but you could argue that any code that<br>
        passes a<br>
        stack variable to any ref arg is already broken. But this can be<br>
        addressed in a future DIP.<br>
<br>
<br>
        ...perhaps I'm missing something fundamental in DIP36, or about<br>
        'auto ref'?<br>
        I can't understand why there seem to be 2 polarised parties on this<br>
        issue, which appear to see the problem completely differently,<br>
        and can't<br>
        visualise the counter perspective at all.<br>
<br>
<br>
    DIP36 should be closed. We must focus on making ref safe and on<br>
    making auto ref work with non-templates.<br>
<br>
<br></div><div class="im">
I'm fine with that, but it sounds like a massive breaking change.<br>
However upon the presumption of this new goal, I don't see the relevance<br>
of auto-ref anymore? Why continue to bring it up?<br>
If ref is safe, nothing else is needed.<br>
</div></blockquote>
<br>
auto ref is needed to accept rvalues.</blockquote><div><br></div><div style>If I were to start arguing upon the basis of your proposal, I would then start arguing that auto-ref in this context is pointless, and automatic creation of a temp to hold any r-value should be the universal/default behaviour.</div>
<div style>You assert that requiring explicit use of 'scope' is a burden. I assert that requiring a completely meaningless instance of 'auto' is a greater burden, when it could easily be made the default behaviour.</div>
<div style>If you're gonna go about making ref safe, then abandon thoughts of auto-ref on non-templates; they can now receive a temporary safely without any justification.</div></div></div></div>