June 15, 2022

On Tuesday, 14 June 2022 at 23:51:45 UTC, Adam Ruppe wrote:

>

On Tuesday, 14 June 2022 at 23:41:55 UTC, Walter Bright wrote:

>

Even with a linker error there'd be constant maintenance problem for the user.

What maintenance problem?

When a library changes, it recompiles and generates its new interface file (if it even uses interface files; they're extremely rare in real world D code).

If the library hasn't changed, there's no need to update anything, inference or not.

This is near zero work.

I'm assuming you're arguing for an always-on function attribute inference, at least for scope and return scope. Please no!

This would be outright poison for a stable API or ABI of a library, probably including ARSD. All your public functions have attributes added to them under your nose, and then you cannot change them without breaking client code because it depends on those attributes you did not intend to add.

Even in a top-level application it happens every now and then that I intentionally want to disable some attributes from a function. Maybe to hunt for some bug, maybe for DBI or testing purposes. Now I can do that with void nonScopeArgument(int*){}. With universal inference I'd have to resort to error-prone hacks like

void nonScopeArgument(int* arg)
{ static int* dummy;
  if(false) dummy = arg;
}

. No thanks.

June 15, 2022
On 15.06.22 12:49, Dukc wrote:
> This would be outright poison for a stable API or ABI of a library, probably including ARSD. All your public functions have attributes added to them under your nose, and then you cannot change them without breaking client code because it depends on those attributes you did not intend to add.

This.

For this to work, there would need to be some way of saying that, for instance, you don't want your function inferred @nogc, even it might be in its current implementation (which btw can be just returning "false" or throwing "Not implemented yet").

Why? Because you want the actual interface to leave open the possibility of needing to allocate later, and if your library isn't overall @nogc, why would you want to lock just one function as @nogc?
June 15, 2022
On Wednesday, 15 June 2022 at 10:49:13 UTC, Dukc wrote:
> This would be outright poison for a stable API or ABI of a library, probably including ARSD. All your public functions have attributes added to them under your nose, and then you cannot change them without breaking client code because it depends on those attributes you did not intend to add.

My view of this (which I need to write about in more detail in the blog, but I have 1,000 more lines of code to translate for work..... by tomorrow...... yeah im not gonna make the deadline but still wanna get as close as i can, so blog on hold for a bit) is that the explicit attributes are all that'd count for breakage, and the inferred ones are specifically subject to change at any time and people shouldn't rely on them. The auto-generated .di file might list it, but the documentation absolutely would not.

I suppose some users might want to statically guarantee they are only using the stable published interface instead of the unstable inferred one, and that would be a bit tricky to declare given the attributes are part of the abi too. That's one of the things that needs more consideration.


> Even in a top-level application it happens every now and then that I intentionally want to disable some attributes from a function.

It is obvious to me that everything that can be turned on needs to be able to be turned off.

tbh it is one if the biggest embarrassments of the attribute soup process we have right now that there STILL isn't a `@gc` or `impure` or whatever after all these years. Even the lowest hanging fruit out of this mess is in limbo.
November 12, 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);
}

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

Sorry to wake up an old thread, but I have a request. May I use this as an example of what can go wrong in @system code for the "Memory safety in modern systems programming language" series in the D blog? And if, is a direct link here okay?

November 12, 2022

On 11/12/22 2:35 PM, Dukc wrote:

>

Sorry to wake up an old thread, but I have a request. May I use this as an example of what can go wrong in @system code for the "Memory safety in modern systems programming language" series in the D blog? And if, is a direct link here okay?

Of course! Feel free to link to anything I've said on these forums.

-Steve

November 13, 2022
On 6/14/22 04:39, Steven Schveighoffer wrote:
> 
> They are mostly marked @system, with a smattering of @safe and @trusted.
> 
> I'll tell you what, I'll do a *whole file* at a time `winsock32.d` ...
> 
> OK, I did it in less than 10 minutes.
> 
> https://github.com/dlang/druntime/pull/3839

There is a post-merge review of that pull request that points out that two of the functions cannot be `@trusted`. It seems in the current version of druntime in DMD master [1], they are still `@trusted`. (I would have commented on the pull request, but it is now archived.)

[1] https://github.com/dlang/dmd/blob/master/druntime/src/core/sys/windows/winsock2.d

I don't know much about windows sockets, so I am not sure what is the best way to fix this. I guess for `inet_ntoa` we should just remove @trusted. For `getprotobynumber`, I am not sure if we should just remove @trusted or if it is sufficient to mark the return value `const` (it seems like it might not be. Given that it says windows sockets will return pointers pointing to stuff it has allocated internally, it might also deallocate it internally at a later point?)

November 13, 2022

On 11/13/22 3:54 AM, Timon Gehr wrote:

>

On 6/14/22 04:39, Steven Schveighoffer wrote:

>

They are mostly marked @system, with a smattering of @safe and @trusted.

I'll tell you what, I'll do a whole file at a time winsock32.d ...

OK, I did it in less than 10 minutes.

https://github.com/dlang/druntime/pull/3839

There is a post-merge review of that pull request that points out that two of the functions cannot be @trusted. It seems in the current version of druntime in DMD master [1], they are still @trusted. (I would have commented on the pull request, but it is now archived.)

[1] https://github.com/dlang/dmd/blob/master/druntime/src/core/sys/windows/winsock2.d

I don't know much about windows sockets, so I am not sure what is the best way to fix this. I guess for inet_ntoa we should just remove @trusted. For getprotobynumber, I am not sure if we should just remove @trusted or if it is sufficient to mark the return value const (it seems like it might not be. Given that it says windows sockets will return pointers pointing to stuff it has allocated internally, it might also deallocate it internally at a later point?)

Thanks! I didn't notice that review. getprotobynumber also states that the "application should copy any information that it needs before issuing any other Windows Sockets function calls" Which suggests the data may not be valid on a second call.

In other words, the struct contains e.g. a char *. If you copy that pointer, it may not be valid upon a second call.

When I did the first PR, I did not focus enough on the return values.

https://github.com/dlang/dmd/pull/14639

-Steve

November 13, 2022

On Saturday, 12 November 2022 at 22:09:45 UTC, Steven Schveighoffer wrote:

>

On 11/12/22 2:35 PM, Dukc wrote:

>

Sorry to wake up an old thread, but I have a request. May I use this as an example of what can go wrong in @system code for the "Memory safety in modern systems programming language" series in the D blog? And if, is a direct link here okay?

Of course! Feel free to link to anything I've said on these forums.

Thanks!

November 13, 2022
On 13.11.22 17:06, Steven Schveighoffer wrote:
> 
> When I did the first PR, I did not focus enough on the return values.
> 
> https://github.com/dlang/dmd/pull/14639

Thank you! :)
4 5 6 7 8 9 10 11 12 13 14
Next ›   Last »