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

Denis Feklushkin feklushkin.denis at gmail.com
Tue Nov 14 00:33:34 UTC 2023


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

(druntime/impl contains directories what named like most 
frequently used versions names)

Platform will be switched on tag-based by build script without 
"branches of branches" inside of code. I.e., if we build for a 
wide available Debian Linux for x86 it would be 3 tags: 
linux+glibc+x86, and for module core/sys/posix/setjmp.d these 
directories will be used:

druntime/impl/x86/core/sys/posix/-no-file-
druntime/impl/glibc/core/sys/posix/setjmp.d <- this will be used
druntime/impl/linux/core/sys/posix/-no-file-

(Obviously, except default, only one file must be found - 
otherwise this is error condition)

You should remember: not all modules are so complex as setjmp.d, 
most files will be in default directory (and many will not be in 
druntime/impl hierarchy at all). And, also, druntime is a special 
sort of software and this approach will help to maintain 
duplicated nature of druntime's bindings.

This approach will force us to avoid difficult branching schemas 
and to separate common logic and OS- or arch- related stuff

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)




More information about the Dlang-internal mailing list