November 09, 2021
On 09.11.21 22:45, Stanislav Blinov wrote:
> 
> That won't help.

It will help in some cases. What will help with the specific issue you have shown was already explained in the first part of my post. I.e., the compiler needs fixing.

https://issues.dlang.org/show_bug.cgi?id=22499

Of course, this was just one example. Again: I am pretty sure that if you explain other pain points we will find more bugs in the compiler.
November 09, 2021

On Tuesday, 9 November 2021 at 19:00:38 UTC, Stanislav Blinov wrote:

>

On Tuesday, 9 November 2021 at 18:35:44 UTC, Alexandru Ermicioi wrote:

>

If compiler can help in preventing potential bugs...

That's just the thing. That error message is, plain and simple, handwaving. Unless, like I said already, I'm missing something. The compiler is perfectly happy with me initializing a nested struct to its .init value. But instantiating it elsewhere - nuuuh, that's not allowed!

.init field itself has lots of edge cases that are not well thought, and you might just be hitting one of them. Per my understanding (which is not necessarily right, please correct if it), the .init of a nested struct should have the context pointer of the method it is called in setup. I.e. .init for such structs would be possible to use only in the scope of parent,
be it class, or function body.

>

Please, this is not helpful. There are already reports on this, including ones filed by myself. Why do you think I created this topic?

Wasn't aware that they were there already, hence recommended to be filed.

>

That is not "inner" struct. That is nested struct. And the whole point of this topic is nested structs. I don't need to eliminate context pointer. I need generic code to work with nested structs. Including the copy tests being discussed here. Including, for gods sake, Phobos ranges.

I was referring to nested structs. Inner or nested structs are the same thing, they are inside or nested into something.

The only current solution I'd see to avoid this issue, would be to first static check if the type is nested type, and just use hasMember trait to check that a __ctor with one argument of same type as the structure itself is present. If so, most probably it is a copy constructor, and hence you can return true. I.e. check the signature of constructor, instead of actually trying to instantiate the nested struct inside is expression or __traits compiles expression. That should work even with @disabled copy constructors, per my knowledge.

I know, that sometimes D meta-programming is pain in some ... place due to bugs, and not well rounded edge cases, but the solution you proposed to fix that (have context pointer null), is a thing which is not better than the current language spec, in my opinion.

So for now best is to try to convince people working on compiler that the issue is quite serious and needs working on (guess this thread itself), while in meantime, you may try use the solution I've proposed to do the checks.

Best regards,
Alexandru.

November 09, 2021

On Tuesday, 9 November 2021 at 22:22:20 UTC, Alexandru Ermicioi wrote:

>

...

Best regards,
Alexandru.

You may also try iterate over all constructor overloads, and check for function signature with is expression. This should not force the compiler to instantiate the struct (and hence complain for missing context pointer), and achieve what you need in case for copy constructor.

November 09, 2021

On Tuesday, 9 November 2021 at 22:22:20 UTC, Alexandru Ermicioi wrote:

>

if it), the .init of a nested struct should have the context pointer of the method it is called in setup.

No. .init of a nested struct just contains a null pointer in the .tupleof[$-1]. Context does not exist until you instantiate a nested struct within the parent scope. That's when an actual stack frame gets allocated. Consequently, doing things like T a = T.init; when T is a nested struct is exactly the kind of "bug" you're referring to. And the compiler is perfectly happy with that. Because, actually, that is not a bug at all. Just like leaving raw pointers null-initialized.

>

The only current solution I'd see to avoid this issue, would be to first static check if the type is nested type, and just use hasMember trait to check that a __ctor with one argument of same type as the structure itself is present.

There is a dedicated trait that shows presence of copy constructor. BTW, hasMember is the WORST method of checking for functions. Because of overloads, and because of templates. IMHO, it's only good for checking for the presence of a destructor, and that's about it.

Please understand, I am not asking "how to work around this" here. I know how, I've already shown how. That is not what I want to be doing. I want the opposite - to not have to be doing that.

>

If so, most probably it is a copy constructor, and hence you can return true.

No, you can't. The ctor might be templated, so won't even exist unless you try to instantiate it. Or there might not be any copy constructor at all. Nor postblit. But the thing may simply not be copyable (i.e. const pointer into a pointer), hence the trait must return false.

November 09, 2021
On Tuesday, 9 November 2021 at 22:20:35 UTC, Timon Gehr wrote:
> On 09.11.21 22:45, Stanislav Blinov wrote:
>> 
>> That won't help.
>
> It will help in some cases. What will help with the specific issue you have shown was already explained in the first part of my post. I.e., the compiler needs fixing.

Yes, it does :) But I think instead of "fixing" that error message it simply needs to be thrown out. It's not doing anything useful, and plenty harmful.

> https://issues.dlang.org/show_bug.cgi?id=22499
>
> Of course, this was just one example. Again: I am pretty sure that if you explain other pain points we will find more bugs in the compiler.

I believe that would be the same as

https://issues.dlang.org/show_bug.cgi?id=22446

There are also some other nested-related things.

https://issues.dlang.org/show_bug.cgi?id=22434
https://issues.dlang.org/show_bug.cgi?id=19375


1 2 3 4
Next ›   Last »