www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Safer D is implemented!

reply Walter Bright <newshound2 digitalmars.com> writes:
https://github.com/dlang/dmd/pull/17044

It's enabled with -preview=safer

It enables "safe by default". This is different from marking functions as
 safe, 
in that:

1. it does not mark the function as  safe, the function mangling does not change

2. it enables all  safe checks except it does not complain about calling
 system 
functions

3. it does not interfere with attribute inference

In other words, it does not impose transitive safety. You can still call 
malloc() and printf() in it.

Once it appears in the next release, I encourage people to add -preview=safer
to 
their build process.
Nov 27 2024
next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Thursday, November 28, 2024 12:08:29 AM MST Walter Bright via Digitalmars-
d-announce wrote:
 https://github.com/dlang/dmd/pull/17044

 It's enabled with -preview=safer

 It enables "safe by default". This is different from marking functions as
  safe, in that:

 1. it does not mark the function as  safe, the function mangling does not
 change

 2. it enables all  safe checks except it does not complain about calling
  system functions

 3. it does not interfere with attribute inference

 In other words, it does not impose transitive safety. You can still call
 malloc() and printf() in it.

 Once it appears in the next release, I encourage people to add
 -preview=safer to their build process.
So, essentially, it makes functions with no explicit safety attributes be somewhere between system and safe by disallowing language constructs which are considered system but not disallowing calling system functions. - Jonathan M Davis
Nov 28 2024
parent reply Walter Bright <newshound2 digitalmars.com> writes:
Right.
Nov 28 2024
parent reply f <f abc.com> writes:
On Thursday, 28 November 2024 at 21:01:30 UTC, Walter Bright 
wrote:
 Right.
11 languages have coroutine support natively Only 1 with full borrow semantics : rust. That according to chatgpt Please sir , the coroutine dips is still at 1st draft. While other dip will make lines fewer , their execution still from top down. The coroutine, is a game changer. That will make porting library from other languages straightforward.
Nov 28 2024
next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 29/11/2024 10:30 AM, f wrote:
 On Thursday, 28 November 2024 at 21:01:30 UTC, Walter Bright wrote:
 Right.
11 languages have coroutine support natively Only 1 with full borrow semantics : rust. That according to chatgpt Please sir , the coroutine dips is still at 1st draft. While other dip will make lines fewer , their execution still from top down. The coroutine, is a game changer. That will make portingĀ  library from other languages straightforward.
I'll be restarting on my language design work, including coroutines next year. I'm taking a few months where I work on my own stuff. I have not forgotten any of the design work :)
Nov 28 2024
prev sibling parent Sergey <kornburn yandex.ru> writes:
On Thursday, 28 November 2024 at 21:30:33 UTC, f wrote:
 On Thursday, 28 November 2024 at 21:01:30 UTC, Walter Bright 
 wrote:
 Right.
The coroutine, is a game changer. That will make porting library from other languages straightforward.
People mostly with C99 and C++(who even touch 20th standard, right?) experience will answer: we have core.thread and std.concurrency for years.. this is enough, what else do you want? :P
Nov 28 2024
prev sibling next sibling parent Duan Tihua <duantihua 163.com> writes:
On Thursday, 28 November 2024 at 07:08:29 UTC, Walter Bright 
wrote:
 https://github.com/dlang/dmd/pull/17044

 It's enabled with -preview=safer
For writing memory safe code, this is a more practical engineering approach. Fortunately, this compilation option will reduce the number of times safe annotation is used and the code will be relatively cleaner.
Nov 29 2024
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On Thursday, 28 November 2024 at 07:08:29 UTC, Walter Bright 
wrote:
 https://github.com/dlang/dmd/pull/17044

 It's enabled with -preview=safer
This is pretty cool! But I've noticed it shows errors for ImportC code:
 lib\gen-blend2d-windows\blend2d.c(207,45): Error: cast from 
 `int` to `void*` not allowed in safe code
Is there a bug report for it?
Dec 29 2024
prev sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On Thursday, 28 November 2024 at 07:08:29 UTC, Walter Bright 
wrote:
 https://github.com/dlang/dmd/pull/17044

 It's enabled with -preview=safer
I think this is going to still cause issues with dependencies, which might just be a dub problem but I'm not sure. For example I've tried to add `dflags `-preview=safer` to my dub.sdl and now I get errors from 3rd party libraries: ``` lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(326,24): Error: `name.ptr` cannot be used in ` safe` code, use `&name[0]` instead lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(342,33): Error: ` safe` function `loadGLFW` cannot access `__gshared` data `glfwInit` lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(342,20): Error: cast from `extern (C) int function() nothrow nogc*` to `void**` not allowed in safe code lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(343,33): Error: ` safe` function `loadGLFW` cannot access `__gshared` data `glfwTerminate` lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(343,20): Error: cast from `extern (C) void function() nothrow nogc*` to `void**` not allowed in safe code lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(344,33): Error: ` safe` function `loadGLFW` cannot access `__gshared` data `glfwGetVersion` ``` Still it's a great step forward, thanks for your work~
Dec 29 2024
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On Sunday, 29 December 2024 at 12:22:42 UTC, Andrej Mitrovic 
wrote:
 On Thursday, 28 November 2024 at 07:08:29 UTC, Walter Bright 
 wrote:
 https://github.com/dlang/dmd/pull/17044

 It's enabled with -preview=safer
I think this is going to still cause issues with dependencies, which might just be a dub problem but I'm not sure. For example I've tried to add `dflags `-preview=safer` to my dub.sdl and now I get errors from 3rd party libraries: ``` lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(326,24): Error: `name.ptr` cannot be used in ` safe` code, use `&name[0]` instead lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(342,33): Error: ` safe` function `loadGLFW` cannot access `__gshared` data `glfwInit` lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(342,20): Error: cast from `extern (C) int function() nothrow nogc*` to `void**` not allowed in safe code lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(343,33): Error: ` safe` function `loadGLFW` cannot access `__gshared` data `glfwTerminate` lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(343,20): Error: cast from `extern (C) void function() nothrow nogc*` to `void**` not allowed in safe code lib\bindbc-glfw\source\bindbc\glfw\binddynamic.d(344,33): Error: ` safe` function `loadGLFW` cannot access `__gshared` data `glfwGetVersion` ``` Still it's a great step forward, thanks for your work~
So essentially this might even work fine if I used .di dependencies instead of .d, as that would hide the implementation code from the compiler so it couldn't do any analysis (never mind that nobody uses .di). But with templates it wouldn't be a workable solution anyway. I don't see how anyone is going to try and use -preview=safer *unless* they are able to use other libraries which are ready for this switch. But most libraries will not be ready for it. Therefore people who use libraries will not be able to enable this switch. Therefore this is a catch-22 problem. I don't know if it's possible to limit certain switches to particular packages, but I would prefer if I could enable the `-preview=safer` switch *only* for code within `./src`. In other words code I directly have control over. Is that possible with dub..?
Dec 29 2024