Jump to page: 1 214  
Page
Thread overview
dip1000 and preview in combine to cause extra safety errors
Jun 08, 2022
Dukc
Jun 08, 2022
John Colvin
Jun 08, 2022
John Colvin
Jun 08, 2022
deadalnix
Jun 08, 2022
Tejas
Jun 08, 2022
John Colvin
Jun 08, 2022
deadalnix
Jun 08, 2022
John Colvin
Jun 08, 2022
deadalnix
Jun 08, 2022
claptrap
Jun 08, 2022
rikki cattermole
Jun 09, 2022
claptrap
Jun 08, 2022
deadalnix
Jun 08, 2022
Walter Bright
Jun 08, 2022
H. S. Teoh
Jun 08, 2022
rikki cattermole
Jun 09, 2022
Ali Çehreli
Jun 09, 2022
Timon Gehr
Jun 09, 2022
Timon Gehr
Jun 09, 2022
Ali Çehreli
Jun 09, 2022
Timon Gehr
Jun 09, 2022
Ali Çehreli
Jun 09, 2022
Timon Gehr
Jun 09, 2022
forkit
Jun 09, 2022
zjh
Jun 09, 2022
zjh
Jun 09, 2022
Paul Backus
Jun 09, 2022
Ali Çehreli
Jun 09, 2022
Walter Bright
Jun 09, 2022
Adrian Matoga
Jun 09, 2022
Paolo Invernizzi
Jun 09, 2022
John Colvin
Jun 13, 2022
Walter Bright
Jun 14, 2022
Timon Gehr
Jun 14, 2022
John Colvin
Jun 09, 2022
Timon Gehr
Jun 10, 2022
Walter Bright
Jun 10, 2022
Walter Bright
Jun 13, 2022
Walter Bright
The future of @safe by default [was Re: dip1000 ...]
Jun 13, 2022
Paul Backus
Jun 14, 2022
Mike Parker
Jun 14, 2022
forkit
Jun 14, 2022
Mike Parker
Jun 14, 2022
Martin B
Jun 13, 2022
rikki cattermole
Nov 13, 2022
Timon Gehr
Nov 13, 2022
Timon Gehr
Jun 10, 2022
mee6
Jun 10, 2022
Timon Gehr
Jun 13, 2022
Walter Bright
Jun 14, 2022
Timon Gehr
Jun 08, 2022
Walter Bright
Jun 09, 2022
Timon Gehr
Jun 09, 2022
Walter Bright
Jun 09, 2022
Timon Gehr
Jun 10, 2022
Walter Bright
Jun 11, 2022
Timon Gehr
Jun 09, 2022
Dennis
Jun 09, 2022
Timon Gehr
Jun 09, 2022
Dennis
Jun 13, 2022
deadalnix
Jun 13, 2022
John Colvin
Jun 13, 2022
deadalnix
Jun 13, 2022
Nick Treleaven
Jun 13, 2022
Walter Bright
Jun 14, 2022
Adam D Ruppe
Jun 14, 2022
Walter Bright
Jun 14, 2022
Adam Ruppe
Jun 15, 2022
Dukc
Jun 15, 2022
Arafel
Jun 15, 2022
Adam D Ruppe
Jun 08, 2022
rikki cattermole
Jun 08, 2022
Walter Bright
Jun 09, 2022
Paulo Pinto
Jun 08, 2022
Dukc
Jun 08, 2022
Mathias LANG
Jun 08, 2022
deadalnix
Jun 08, 2022
Timon Gehr
Jun 08, 2022
12345swordy
Jun 08, 2022
Timon Gehr
Jun 08, 2022
Meta
Jun 08, 2022
12345swordy
Jun 08, 2022
Walter Bright
Jun 09, 2022
John Colvin
Jun 08, 2022
Walter Bright
Jun 08, 2022
Mathias LANG
Jun 08, 2022
Walter Bright
Jun 09, 2022
Mathias LANG
Jun 09, 2022
forkit
Jun 09, 2022
Paulo Pinto
Jun 09, 2022
Paulo Pinto
Jun 14, 2022
Walter Bright
Jun 14, 2022
Walter Bright
Jun 08, 2022
Dukc
Jun 08, 2022
Dukc
Jun 08, 2022
Walter Bright
Jun 08, 2022
Walter Bright
Jun 08, 2022
Walter Bright
Jun 09, 2022
Mathias LANG
Jun 09, 2022
Dennis
Jun 09, 2022
Timon Gehr
Jun 09, 2022
jmh530
Jun 09, 2022
jmh530
Jun 09, 2022
Dennis
Jun 09, 2022
Timon Gehr
Jun 09, 2022
Nick Treleaven
Jun 13, 2022
Walter Bright
Jun 14, 2022
forkit
Jun 14, 2022
rikki cattermole
Jun 14, 2022
forkit
Jun 14, 2022
rikki cattermole
Jun 14, 2022
zjh
Jun 14, 2022
forkit
Jun 14, 2022
rikki cattermole
Jun 14, 2022
forkit
Jun 14, 2022
Paulo Pinto
Jun 14, 2022
forkit
Jun 14, 2022
Paulo Pinto
Jun 14, 2022
rikki cattermole
Jun 13, 2022
Walter Bright
Jun 14, 2022
Dennis
Nov 12, 2022
Dukc
Nov 13, 2022
Dukc
June 08, 2022
string foo(in string s)
{
    return s;
}

void main()
{
    import std.stdio;
    string[] result;
    foreach(c; "hello")
    {
        result ~= foo([c]);
    }
    writeln(result);
}

With no previews, preview=dip1000, or preview=in, this outputs: ["h", "e", "l", "l", "o"]

With both preview=dip1000 and preview=in, this outputs: ["o", "o", "o", "o", "o"]

What is happening is the compiler is somehow convinced that it can allocate the array literal on the stack (and overwrites that literal each loop).

I know this isn't @safe code, but @system code shouldn't be made less safe by the preview switches!

I know people write in instead of const all the time simply because it's shorter.

Thoughts?

-Steve

June 08, 2022

On Wednesday, 8 June 2022 at 14:52:53 UTC, Steven Schveighoffer wrote:

>
string foo(in string s)
{
    return s;
}

void main()
{
    import std.stdio;
    string[] result;
    foreach(c; "hello")
    {
        result ~= foo([c]);
    }
    writeln(result);
}

Thoughts?

This is simply the result of using in wrong. in means const scope. scope (without preceeding return) means you won't return a reference to the address to the argument (unless the function can reach it via some other channel). Result: undefined behaviour.

June 08, 2022

On 6/8/22 11:10 AM, Dukc wrote:

>

On Wednesday, 8 June 2022 at 14:52:53 UTC, Steven Schveighoffer wrote:

>
string foo(in string s)
{
    return s;
}

void main()
{
    import std.stdio;
    string[] result;
    foreach(c; "hello")
    {
        result ~= foo([c]);
    }
    writeln(result);
}

Thoughts?

This is simply the result of using in wrong. in means const scope. scope (without preceeding return) means you won't return a reference to the address to the argument (unless the function can reach it via some other channel). Result: undefined behaviour.

So silently changing behavior to create new dangling pointers with a preview switch is ok?

Remember, there is already code that does this. It's not trying to be clever via scope, it's not trying to be @safe, it's expecting that an array literal is allocated on the GC (as has always been the case).

-Steve

June 08, 2022

On Wednesday, 8 June 2022 at 15:35:56 UTC, Steven Schveighoffer wrote:

>

On 6/8/22 11:10 AM, Dukc wrote:

>

On Wednesday, 8 June 2022 at 14:52:53 UTC, Steven Schveighoffer wrote:

>
string foo(in string s)
{
    return s;
}

void main()
{
    import std.stdio;
    string[] result;
    foreach(c; "hello")
    {
        result ~= foo([c]);
    }
    writeln(result);
}

Thoughts?

This is simply the result of using in wrong. in means const scope. scope (without preceeding return) means you won't return a reference to the address to the argument (unless the function can reach it via some other channel). Result: undefined behaviour.

So silently changing behavior to create new dangling pointers with a preview switch is ok?

Remember, there is already code that does this. It's not trying to be clever via scope, it's not trying to be @safe, it's expecting that an array literal is allocated on the GC (as has always been the case).

-Steve

The preview switch is changing the meaning of in which changes the signature of foo (which is then inconsistent with the implementation), which in turn will affect the call sites. This seems roughly as expected, no?

June 08, 2022

On Wednesday, 8 June 2022 at 15:58:10 UTC, John Colvin wrote:

>

The preview switch is changing the meaning of in which changes the signature of foo (which is then inconsistent with the implementation), which in turn will affect the call sites. This seems roughly as expected, no?

E.g. this prints ["o", "o", "o", "o", "o"] regardless of compiler flags

string foo(scope string s)
{
    return s;
}

void main()
{
    import std.stdio;
    string[] result;
    foreach(c; "hello")
    {
        result ~= foo([c]);
    }
    writeln(result);
}
June 08, 2022

On Wednesday, 8 June 2022 at 16:01:55 UTC, John Colvin wrote:

>

On Wednesday, 8 June 2022 at 15:58:10 UTC, John Colvin wrote:

>

The preview switch is changing the meaning of in which changes the signature of foo (which is then inconsistent with the implementation), which in turn will affect the call sites. This seems roughly as expected, no?

E.g. this prints ["o", "o", "o", "o", "o"] regardless of compiler flags

string foo(scope string s)
{
    return s;
}

void main()
{
    import std.stdio;
    string[] result;
    foreach(c; "hello")
    {
        result ~= foo([c]);
    }
    writeln(result);
}

There is no frame of reference in which this result is in any way reasonable.

June 08, 2022

On 6/8/22 11:58 AM, John Colvin wrote:

>

The preview switch is changing the meaning of in which changes the signature of foo (which is then inconsistent with the implementation), which in turn will affect the call sites. This seems roughly as expected, no?

I guess it is! I always thought in meant const scope, but apparently it no longer does unless you add -preview=in. However, I will note that just using -preview=in does not cause it to print the o strings, only when paired with dip1000 does it do that.

Still, I would think a warning, even for @system code is warranted. Especially since the compiler is already able to figure this out for @safe code.

The reality is that people are (mostly) only dealing with the existing implementation, until it stops working. But to silently break it, and silently break it with memory corruption does not seem an appropriate penalty.

-Steve

June 08, 2022

On Wednesday, 8 June 2022 at 16:16:37 UTC, deadalnix wrote:

>

On Wednesday, 8 June 2022 at 16:01:55 UTC, John Colvin wrote:

>

On Wednesday, 8 June 2022 at 15:58:10 UTC, John Colvin wrote:

>

[...]

E.g. this prints ["o", "o", "o", "o", "o"] regardless of compiler flags

string foo(scope string s)
{
    return s;
}

void main()
{
    import std.stdio;
    string[] result;
    foreach(c; "hello")
    {
        result ~= foo([c]);
    }
    writeln(result);
}

There is no frame of reference in which this result is in any way reasonable.

Yeah, shouldn't the compiler complain that s is trying to escape the scope of foo?

June 08, 2022

On Wednesday, 8 June 2022 at 16:16:37 UTC, deadalnix wrote:

>

On Wednesday, 8 June 2022 at 16:01:55 UTC, John Colvin wrote:

>

E.g. this prints ["o", "o", "o", "o", "o"] regardless of compiler flags

string foo(scope string s)
{
    return s;
}

void main()
{
    import std.stdio;
    string[] result;
    foreach(c; "hello")
    {
        result ~= foo([c]);
    }
    writeln(result);
}

There is no frame of reference in which this result is in any way reasonable.

My guess is that technically foo has undefined behaviour.

June 09, 2022
This compiles and prints hello.

```d
string foo(return in string s) @safe
{
    return s;
}
```

So the problem here is something to do with -preview=in and return detection of DIP1000.
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11