[Dlang-internal] druntime: proposed changes in code organization

IGotD- nise at nise.com
Thu Nov 16 15:13:44 UTC 2023


On Tuesday, 14 November 2023 at 00:33:34 UTC, Denis Feklushkin 
wrote:
> Hi!
>
> I propose to discuss a possibility of reorganizing code by this 
> way:
>
> For example, druntime/src/core/sys/posix/setjmp.d file contains 
> few version branches of libc and OSes versions. It can be 
> reorganized as:
>
> druntime/impl/arm/core/sys/posix/-no-file-
> druntime/impl/x86/core/sys/posix/-no-file-
> druntime/impl/netbsd/core/sys/posix/setjmp.d
> druntime/impl/openbsd/core/sys/posix/setjmp.d
> druntime/impl/linux/core/sys/posix/-no-file-
> druntime/impl/glibc/core/sys/posix/setjmp.d
> druntime/impl/default/core/sys/posix/setjmp.d
>

I suggested this a while ago that druntime should be refactored 
to files instead of the version hell like #ifdef hell in C. 
However, in order this to properly work was that import should be 
able to use version strings in the filename path.

Also, one question in the example. Why two files

druntime/impl/arm/core/sys/posix/-no-file-
druntime/impl/x86/core/sys/posix/-no-file-

as I assume these are stubs. Isn't a stub no OS at all?

Apart from that. I strongly support having stubbed versions in 
druntime, also with more fine granularity which would be great 
for embedded systems. Some systems have file systems but no 
process support for example.

>
> It opens ability to import modules with foreign data structures 
> on non-native OSes: it will be possible to remove module 
> "guards" like "version (Linux):" at start of modules and your 
> Windows app will be able to import Linux data structures
>
> This approach also helps to add new platforms (most important 
> for me)

First thing is that we need version strings in imports. This has 
been suggested for years but nothing has happened. If we add 
this, then modularizing druntime will fall more naturally (and 
perhaps their own projects too).



More information about the Dlang-internal mailing list