February 02, 2022

On 2/2/22 1:57 PM, forkit wrote:

>

On Wednesday, 2 February 2022 at 18:51:04 UTC, forkit wrote:

>

This code below, will not compile using these parameters:

-m64 -betterC

but WILL using

-m32 -betterC

.. I mean specifically on Windows of course.

It's fine on linux.

Dennis is likely correct that it has to do with whether you are using MSVC libc or DMC libc.

I was going to look further, but github seems to be down.

-Steve

February 02, 2022
On 2/2/2022 4:17 AM, kinke wrote:
> On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:
>> ```d
>> else version (CRuntime_Microsoft)
>> {
>>     ///
>>     shared FILE* stdin;  // = &__iob_func()[0];
>>     ///
>>     shared FILE* stdout; // = &__iob_func()[1];
>>     ///
>>     shared FILE* stderr; // = &__iob_func()[2];
>> }
>> ```
>>
>> shouldn't these variable declarations be `extern` ?
> 
> Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.

The trouble is -betterC does not link with druntime, so it can't find stderr. The solution is to make stderr a template, so that no linking with druntime is necessary.
February 03, 2022

On 2/2/22 12:19 PM, Dennis wrote:

>

On Wednesday, 2 February 2022 at 14:38:49 UTC, Steven Schveighoffer wrote:

>

I tend to believe that maybe the OP is mistaken that it works, or there was a latent bug that was still running some of druntime that has been fixed.

Maybe 2.091 was when dub still defaulted to OMF using the DigitalMars runtime, and it just seems to work since it's not using the Windows runtime.

I double checked. dub switched to MSCOFF by default in 2.086.

Though it's possible the user is using a different version of dub.

Only way to be sure is to do a clean install and try it on Windows.

-Steve

February 03, 2022
On Wednesday, 2 February 2022 at 20:58:25 UTC, Walter Bright wrote:
> On 2/2/2022 4:17 AM, kinke wrote:
>> On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:
>>> ```d
>>> else version (CRuntime_Microsoft)
>>> {
>>>     ///
>>>     shared FILE* stdin;  // = &__iob_func()[0];
>>>     ///
>>>     shared FILE* stdout; // = &__iob_func()[1];
>>>     ///
>>>     shared FILE* stderr; // = &__iob_func()[2];
>>> }
>>> ```
>>>
>>> shouldn't these variable declarations be `extern` ?
>> 
>> Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.
>
> The trouble is -betterC does not link with druntime, so it can't find stderr. The solution is to make stderr a template, so that no linking with druntime is necessary.

That's not a solution, but a hack. ;) - With at least 2 major problems:

* Template culling. If the compiler e.g. sees a stderr instantiation in druntime in the import graph, it may decide not to emit the stderr symbol into the betterC binary, assuming that druntime will be linked anyway.
* Potentially a DSO-local stderr symbol for each binary (executable or DLL/.so/.dylib), so that changing it in one DSO might not change it for the whole process.

There have been previous 'dummy-templatizations' in druntime/Phobos to work around missing symbols with -betterC. IMO, that's just patching over the cracks of the -betterC hack and pessimizing regular D, and in case it's not obvious, I'm definitely no fan of this. :)
February 03, 2022

On 2/3/22 2:55 PM, kinke wrote:

>

On Wednesday, 2 February 2022 at 20:58:25 UTC, Walter Bright wrote:

>

On 2/2/2022 4:17 AM, kinke wrote:

>

On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:

>
else version (CRuntime_Microsoft)
{
    ///
    shared FILE* stdin;  // = &__iob_func()[0];
    ///
    shared FILE* stdout; // = &__iob_func()[1];
    ///
    shared FILE* stderr; // = &__iob_func()[2];
}

shouldn't these variable declarations be extern ?

Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with -betterC.

The trouble is -betterC does not link with druntime, so it can't find stderr. The solution is to make stderr a template, so that no linking with druntime is necessary.

That's not a solution, but a hack. ;) - With at least 2 major problems:

  • Template culling. If the compiler e.g. sees a stderr instantiation in druntime in the import graph, it may decide not to emit the stderr symbol into the betterC binary, assuming that druntime will be linked anyway.
  • Potentially a DSO-local stderr symbol for each binary (executable or DLL/.so/.dylib), so that changing it in one DSO might not change it for the whole process.

There have been previous 'dummy-templatizations' in druntime/Phobos to work around missing symbols with -betterC. IMO, that's just patching over the cracks of the -betterC hack and pessimizing regular D, and in case it's not obvious, I'm definitely no fan of this. :)

Since pragma inline works now even without the -inline switch, could an inline function take the place of the macro?

-Steve

February 03, 2022

On Thursday, 3 February 2022 at 21:56:27 UTC, Steven Schveighoffer wrote:

>

Since pragma inline works now even without the -inline switch, could an inline function take the place of the macro?

Nope, sadly not - the problem is &stderr returning a function pointer then, not the address of the symbol directly.

February 03, 2022

On 2/3/22 5:13 PM, kinke wrote:

>

On Thursday, 3 February 2022 at 21:56:27 UTC, Steven Schveighoffer wrote:

>

Since pragma inline works now even without the -inline switch, could an inline function take the place of the macro?

Nope, sadly not - the problem is &stderr returning a function pointer then, not the address of the symbol directly.

Ugh, yep. Damn us for not correctly implementing @property.

Would be the same problem with a template as well.

-Steve

February 03, 2022
On 2/3/2022 11:55 AM, kinke wrote:
> * Template culling. If the compiler e.g. sees a stderr instantiation in druntime in the import graph, it may decide not to emit the stderr symbol into the betterC binary, assuming that druntime will be linked anyway.
> * Potentially a DSO-local stderr symbol for each binary (executable or DLL/.so/.dylib), so that changing it in one DSO might not change it for the whole process.
> 
> There have been previous 'dummy-templatizations' in druntime/Phobos to work around missing symbols with -betterC. IMO, that's just patching over the cracks of the -betterC hack and pessimizing regular D, and in case it's not obvious, I'm definitely no fan of this. :)

"Header only" libraries work well for C++. We can make it work for D. In fact, we have to.

As for stderr, it should never be an instance of the iob itself. That instance resides only in the C stdlib. stderr should only be an indirect reference to it, hence multiple instances of stderr should work just fine.

With a bit of careful library design, we can make this work.
February 04, 2022

On Friday, 4 February 2022 at 00:54:50 UTC, Steven Schveighoffer wrote:

>

On 2/3/22 5:13 PM, kinke wrote:

>

On Thursday, 3 February 2022 at 21:56:27 UTC, Steven Schveighoffer wrote:

>

Since pragma inline works now even without the -inline switch, could an inline function take the place of the macro?

Nope, sadly not - the problem is &stderr returning a function pointer then, not the address of the symbol directly.

Ugh, yep. Damn us for not correctly implementing @property.

Would be the same problem with a template as well.

-Steve

What will it take to implement @property correctly? What is it that we're lacking?

I genuinely don't understand anything about this particular topic: what is preventing us from fixing this particular part of the language even though it crops up pretty frequently?
Could you maybe please link me to a forum post where this has been discussed?

February 04, 2022

On 2/3/22 11:13 PM, Tejas wrote:

>

On Friday, 4 February 2022 at 00:54:50 UTC, Steven Schveighoffer wrote:

>

Ugh, yep. Damn us for not correctly implementing @property.

Would be the same problem with a template as well.

What will it take to implement @property correctly? What is it that we're lacking?

What @property should have done (it's very limited in functionality now, and not likely to be fixed) is to disable accessing via the function at all. The fact that it's a function call should be an implementation detail.

in other words:

int _x;
@property ref int x() { return _x;}


static assert(is(typeof(x) == int)); // this is true today
static assert(typeof(&x) == int *)); // this is not true but should be

auto y = x(); // should not compile, but does, an int is not a function.

If this were the case, then fixing the stderr problem mentioned here would be possible using properties.

>

I genuinely don't understand anything about this particular topic: what is preventing us from fixing this particular part of the language even though it crops up pretty frequently?
Could you maybe please link me to a forum post where this has been discussed?

The @property debate is really old. When it was added, the thought was to get rid of some of these sticky corner cases. D has had property syntax since D1. But the @property attribute was supposed to be a way to declare "this is a property, so it shouldn't behave like a function".

But core members disliked the added complications, and so the benefits of @property were kind of cancelled. There are a few draft DIPS on it (from the old system in the wiki, see here: https://wiki.dlang.org/DIPs). Now we are just left with a really obscure difference (the typeof difference) which is IMO confusing anyway.

-Steve