March 31, 2009
Max Samukha schrieb:
>> "variable main.main.i voids have no value"
> 
> __traits is buggy.
> 
> template isFunction(C, string member)
> {
>     enum isFunction = is(typeof(mixin("C." ~ member)) == function);
> }
> 
> void main()
> {
>     //SpinLock lock;
> 
>     enum members = __traits(allMembers, Class);
>     foreach (i; Sequence!(members.length))
>     {
>         static if (isFunction!(Class, members[i]))
>         {
>             foreach (j; __traits(getVirtualFunctions, Class,
> members[i]))
>                 writefln(members[i], ": ", typeid(typeof(j)));
>         }
>     }
> } 
> 

Yeah extreeemely buggy. dmd also crashes if that enum members is changed to const members or invariant members.

In fact, what I'm trying to do is getting all the functions of a given class and checking their parameters for correctness.
March 31, 2009
On Tue, 31 Mar 2009 13:53:02 +0200, Trass3r <mrmocool@gmx.de> wrote:

>Max Samukha schrieb:
>>> So it is a tuple although the docs tell us it's an array?
>>>
>> 
>> Yeah, __traits returns expressions of various types depending on the Id. In case of getVirtualFunctions, it's a tuple expression. You may want to look through traits.c in dmd sources to see what's going on.
>> 
>
>So the docs are incorrect:
>"getVirtualFunctions
>The result is an array of the virtual overloads of that function."

I've got a feeling that the compile-time introspection thing is going to change, so relying on its current crippled implementation is risky.
March 31, 2009
Trass3r wrote:
> Yeah extreeemely buggy. dmd also crashes if that enum members is changed to const members or invariant members.

Buggy __traits is the major reason I'm not on d2. If __traits were not buggy, I could do, god, so many things!

Though it would be even better to have the runtime equivalent.
March 31, 2009
Christopher Wright schrieb:
> Buggy __traits is the major reason I'm not on d2. If __traits were not buggy, I could do, god, so many things!
> 
> Though it would be even better to have the runtime equivalent.

Any chance traits get fixed anytime soon?
April 01, 2009
Trass3r wrote:
> Christopher Wright schrieb:
>> Buggy __traits is the major reason I'm not on d2. If __traits were not buggy, I could do, god, so many things!
>>
>> Though it would be even better to have the runtime equivalent.
> 
> Any chance traits get fixed anytime soon?

I was using __traits + CTFE around 2.006 through 2.011. Every release, things were broken in new and incompatible ways. I could never narrow it down sufficiently to get a good bug report (well, usually not), but I could usually make it work by bashing my code in a few times.

The one consistent bug I found was fixed. So I could get back to it, but I don't want to keep chasing the CTFE engine.
April 01, 2009
Christopher Wright wrote:
> Trass3r wrote:
>> Christopher Wright schrieb:
>>> Buggy __traits is the major reason I'm not on d2. If __traits were not buggy, I could do, god, so many things!
>>>
>>> Though it would be even better to have the runtime equivalent.
>>
>> Any chance traits get fixed anytime soon?
> 
> I was using __traits + CTFE around 2.006 through 2.011. Every release, things were broken in new and incompatible ways. I could never narrow it down sufficiently to get a good bug report (well, usually not), but I could usually make it work by bashing my code in a few times.
> 
> The one consistent bug I found was fixed. So I could get back to it, but I don't want to keep chasing the CTFE engine.

That situation should be much better now that we have all of the source code. If something changes, it'll be really easy to find exactly what caused the change.
April 01, 2009
Don schrieb:
> That situation should be much better now that we have all of the source code. If something changes, it'll be really easy to find exactly what caused the change.

Well, if dmd was available in a source control repository we could really easily track the changes.
April 01, 2009
Trass3r wrote:
> Don schrieb:
>> That situation should be much better now that we have all of the source code. If something changes, it'll be really easy to find exactly what caused the change.
> 
> Well, if dmd was available in a source control repository we could really easily track the changes.

Agreed, but we effectively have a repository with a once-per-month commit, which isn't too bad.
It's more of a problem for people submitting bugfixes -- there's been a couple of cases where someone's submitted a patch, only to be told by Walter that he'd already fixed it.
Since there are about 1000 bugs in bugzilla, it's a shame to waste effort that way.
April 01, 2009
Trass3r schrieb:
> foreach (member; __traits (allMembers, Class))
> {
>     foreach (overload; __traits (getVirtualFunctions, Class, member))
>     {
>         // do stuff
>     }
> }
> 

omg, those bugs are known for nearly 2 years now.
http://d.puremagic.com/issues/show_bug.cgi?id=1386
http://d.puremagic.com/issues/show_bug.cgi?id=1499
April 01, 2009
Trass3r schrieb:
>>     enum members = __traits(allMembers, Class);
>>     foreach (i; Sequence!(members.length))
>>     {
>>         static if (isFunction!(Class, members[i]))
>>         {
>>             foreach (j; __traits(getVirtualFunctions, Class,
>> members[i]))
>>                 writefln(members[i], ": ", typeid(typeof(j)));
>>         }
>>     }
>> }
> 
> Yeah extreeemely buggy. dmd also crashes if that enum members is changed to const members or invariant members.
> 


Ok, narrowed that down to:
template Sequence(size_t count, size_t index = 0)
{
   static if (index < count)
      alias Tuple!(index, Sequence!(count, index + 1)) Sequence;
}

void main()
{
	const members = ["foo", "bar"];
	foreach (i; Sequence!(members.length))
	{
		writefln(members[i]);
	}
}

Also crashes. Changing to auto or even enum (i mean enum is also constant, so ???)
yields:
Error: variable main2.main.i voids have no value