DIP 1024---Shared Atomics---Final Review
Petar
Petar
Wed Dec 11 12:59:32 UTC 2019
On Wednesday, 11 December 2019 at 11:23:12 UTC, RazvanN wrote:
> On Wednesday, 11 December 2019 at 09:47:12 UTC, Manu wrote:
>> On Wed, Dec 11, 2019 at 7:30 PM Walter Bright via
>> Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>> [...]
>>
>> core.stdc, core.stdcpp, core.atomic should be all inline (or
>> externs
>> to the C lib) and absolutely not require linking any d-libs.
>> Sadly, we don't have an inline qualifier that works right; the
>> only
>> hack we have is to make should-be-inline functions a template
>> with no
>> template args, which is a lame hack that frustrates some forms
>> of meta
>> :/
>
> This is a bit risky. Consider that the function in core.atomic
> might use other non-template functions from druntime which will
> cause a link time failure.
No it's not risky as there are only two sensible ways of
implementing of core.atomic:
1. Inline assembly (per each supported target arch)
2. GCC or LLVM intrinsics/builtins (I think GCC's libatomic would
be categorized as builtin)
DMD uses 1. whereas GDC and LDC use 2.
As such, core.atomic doesn't have any link-time dependencies and
so it's 100% -betterC compatible. If you can check the source
code you will see that there are @betterC unit tests that ensure
that core.atomic works in -betterC mode:
https://github.com/dlang/druntime/blob/7a6d30d457fe52d56d3b8241ad10cc7a4a049ed1/src/core/atomic.d#L889
https://github.com/dlang/druntime/blob/7a6d30d457fe52d56d3b8241ad10cc7a4a049ed1/src/core/atomic.d#L968
https://github.com/dlang/druntime/blob/7a6d30d457fe52d56d3b8241ad10cc7a4a049ed1/src/core/atomic.d#L1008
https://github.com/dlang/druntime/blob/7a6d30d457fe52d56d3b8241ad10cc7a4a049ed1/src/core/atomic.d#L1066
As long as we have those tests, there's no risk in making
core.atomic incompatible with -betterC.
More information about the Digitalmars-d
mailing list