August 16, 2016
On 08/16/2016 07:26 PM, Patrick Schluter wrote:
> What happens in that case ?
> 
> void test() {
> scope rnd  = new Rnd; // reference semantic and stack allocated
> Rnd rnd2;
>  rnd2 = rnd;
>          some_sneaky_function_that_saves_global_state(rnd);
> }
> 
> or is that not even possible ? (sorry I'm still a noob in D).

If `Rnd` is supposed to be a class, it won't compile because it would
mean escaping scope reference to non-scope variable (with DIP1000). If
it is a struct, it won't compile because you are trying to assign `Rnd*`
(pointer) to `Rnd` (value) :)



August 16, 2016
On Tuesday, 16 August 2016 at 16:34:05 UTC, Dicebot wrote:
> On 08/16/2016 07:26 PM, Patrick Schluter wrote:
>> What happens in that case ?
>> 
>> void test() {
>> scope rnd  = new Rnd; // reference semantic and stack allocated
>> Rnd rnd2;
>>  rnd2 = rnd;
>>          some_sneaky_function_that_saves_global_state(rnd);
>> }
>> 
>> or is that not even possible ? (sorry I'm still a noob in D).
>
> If `Rnd` is supposed to be a class, it won't compile because it would
> mean escaping scope reference to non-scope variable (with DIP1000). If
> it is a struct, it won't compile because you are trying to assign `Rnd*`
> (pointer) to `Rnd` (value) :)

What about this?

struct Rnd
{
    int* state;
}

void test()
{
    scope rnd = new Rnd();
    Rnd rnd2 = *rnd;

    saveGlobalState(rnd2);
}
August 16, 2016
On Tuesday, 16 August 2016 at 18:25:42 UTC, Meta wrote:
> What about this?
>
> struct Rnd
> {
>     int* state;
> }
>
> void test()
> {
>     scope rnd = new Rnd();
>     Rnd rnd2 = *rnd;
>
>     saveGlobalState(rnd2);
> }

Same as far as I understand, because "from a lifetime analysis viewpoint, a struct is considered a juxtaposition of its direct members" (https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md#aggregates). You need to add one more level of indirection for things to start going complicated.
August 16, 2016
On Tuesday, 16 August 2016 at 18:55:40 UTC, Dicebot wrote:
> On Tuesday, 16 August 2016 at 18:25:42 UTC, Meta wrote:
>> What about this?
>>
>> struct Rnd
>> {
>>     int* state;
>> }
>>
>> void test()
>> {
>>     scope rnd = new Rnd();
>>     Rnd rnd2 = *rnd;
>>
>>     saveGlobalState(rnd2);
>> }
>
> Same as far as I understand, because "from a lifetime analysis viewpoint, a struct is considered a juxtaposition of its direct members" (https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md#aggregates). You need to add one more level of indirection for things to start going complicated.

Ah no, sorry, I have missed that you allocate struct on heap. Yes, this is simplified problem case indeed. Intention is that such struct can be made @safe by making all pointer fields private and adding scope semantics in getter methods but it is hard to reason about details at this point.
August 16, 2016
On 16 Aug 2016 21:01, "Dicebot via Digitalmars-d-announce" < digitalmars-d-announce@puremagic.com> wrote:
>
> On Tuesday, 16 August 2016 at 18:55:40 UTC, Dicebot wrote:
>>
>> On Tuesday, 16 August 2016 at 18:25:42 UTC, Meta wrote:
>>>
>>> What about this?
>>>
>>> struct Rnd
>>> {
>>>     int* state;
>>> }
>>>
>>> void test()
>>> {
>>>     scope rnd = new Rnd();
>>>     Rnd rnd2 = *rnd;
>>>
>>>     saveGlobalState(rnd2);
>>> }
>>
>>
>> Same as far as I understand, because "from a lifetime analysis
viewpoint, a struct is considered a juxtaposition of its direct members" ( https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md#aggregates). You need to add one more level of indirection for things to start going complicated.
>
>
> Ah no, sorry, I have missed that you allocate struct on heap. Yes, this
is simplified problem case indeed. Intention is that such struct can be made @safe by making all pointer fields private and adding scope semantics in getter methods but it is hard to reason about details at this point.

It will be nice to see a set of tests that are expected to pass, a set that are expected to fail, and a set that segfault.

In my questions I was trying to make small examples, that could become tests.

The examples in the DIP are quite simple actually. The pointer escaping example is what I was missing.


August 16, 2016
On 8/16/2016 11:25 AM, Meta wrote:
> What about this?
>
> struct Rnd
> {
>     int* state;
> }
>
> void test()
> {
>     scope rnd = new Rnd();
>     Rnd rnd2 = *rnd;
>
>     saveGlobalState(rnd2);
> }

'state' is set to null by 'new Rnd()', and so no pointers escape.
August 17, 2016
On Monday, 15 August 2016 at 04:58:06 UTC, Walter Bright wrote:
> On 8/14/2016 9:56 PM, Joseph Rushton Wakeling wrote:
>> Does that actually work in D2?
>
> Yes.

Can you please clarify the current implementation `scope`, and what DIP1000 proposes to change with respect to the current implementation?

According to this [http://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack] it was deprecated in favor of std.typecons.scoped.  But your previous statement say's scoped variables is still a thing.

What exactly is being deprecated with regard to `scope`, if anything?  Does the deprecated features page need an update?

Will DIP1000 render `std.typecons.scoped` obsolete?  In other words, does DIP1000 deprecate the deprecation?

Is `scope` being repurposed for DIP1000, or simply expanded?  In other words does DIP1000 change the current implementation of scope in any way, or just add to it?

Thanks,
Mike
August 17, 2016
On Tue, 16 Aug 2016 18:55:40 +0000, Dicebot wrote:
> You need to add one more level of indirection for things to start going complicated.

Presumably scope is transitive, so things shouldn't get horribly complex.
August 16, 2016
On Wed, Aug 17, 2016 at 01:01:05AM +0000, Chris Wright via Digitalmars-d-announce wrote:
> On Tue, 16 Aug 2016 18:55:40 +0000, Dicebot wrote:
> > You need to add one more level of indirection for things to start going complicated.
> 
> Presumably scope is transitive, so things shouldn't get horribly complex.

I thought the DIP states the scope is *not* transitive?


T

-- 
The right half of the brain controls the left half of the body. This means that only left-handed people are in their right mind. -- Manoj Srivastava
August 16, 2016
On 8/16/2016 5:31 PM, Mike wrote:
> On Monday, 15 August 2016 at 04:58:06 UTC, Walter Bright wrote:
>> On 8/14/2016 9:56 PM, Joseph Rushton Wakeling wrote:
>>> Does that actually work in D2?
>>
>> Yes.
>
> Can you please clarify the current implementation `scope`, and what DIP1000
> proposes to change with respect to the current implementation?

It just adds to the existing compiler implementation of 'scope'. It has nothing to do with std.typecons.scoped.