Thread overview
Internal Error
Apr 02, 2008
Neil Vice
Apr 02, 2008
Neil Vice
Apr 02, 2008
Russell Lewis
Apr 02, 2008
bearophile
April 02, 2008
I've encountered the following error in DMD 2.012:

    Internal error: ..\ztc\cod1.c 1662

I would submit a bug report except that I can't seem to determine a simple case that produces the bug, so I guess I'm looking for some assistance in narrowing down the problem.

I have two structs, one representing a time-stamp and another representing a time-period. They both implement opSub. Nested within a method in a class within a class in a seperate package I have some code along the lines of:

    auto result = a - (b - c);

where a is a TimePeriod and b & c are TimeStamps.

If I replace this line with:

    auto _result = b - c;
    auto result = a - _result;

the Internal error goes away.

I have attempted to construct a simple case with two similar structs with opSub methods and a main() containing the problem expression, however I cannot reproduce the error.

Any suggestions on where to go from here?


April 02, 2008
"Neil Vice" wrote in message
> I've encountered the following error in DMD 2.012:
>
>    Internal error: ..\ztc\cod1.c 1662
>
> I would submit a bug report except that I can't seem to determine a simple case that produces the bug, so I guess I'm looking for some assistance in narrowing down the problem.
>
> I have two structs, one representing a time-stamp and another representing a time-period. They both implement opSub. Nested within a method in a class within a class in a seperate package I have some code along the lines of:
>
>    auto result = a - (b - c);
>
> where a is a TimePeriod and b & c are TimeStamps.
>
> If I replace this line with:
>
>    auto _result = b - c;
>    auto result = a - _result;
>
> the Internal error goes away.
>
> I have attempted to construct a simple case with two similar structs with opSub methods and a main() containing the problem expression, however I cannot reproduce the error.
>
> Any suggestions on where to go from here?

Try to reproduce the error with a simple main function that does just the lines above.

If this still fails, then try removing pieces of your classes, making sure the error remains.  When you narrow that down, you might be able to see clearer what the minimal case is.

If this doesn't fail, then try moving around where you are making the auto result = a - (b - c) call, trying to simplify that code.

Good luck.

-Steve


April 02, 2008
Neil Vice wrote:
> I've encountered the following error in DMD 2.012:
> 
>     Internal error: ..\ztc\cod1.c 1662
> 
> I would submit a bug report except that I can't seem to determine a simple case that produces the bug, so I guess I'm looking for some assistance in narrowing down the problem.
> 
> I have two structs, one representing a time-stamp and another representing a time-period. They both implement opSub. Nested within a method in a class within a class in a seperate package I have some code along the lines of:
> 
>     auto result = a - (b - c);
> 
> where a is a TimePeriod and b & c are TimeStamps.
> 
> If I replace this line with:
> 
>     auto _result = b - c;
>     auto result = a - _result;
> 
> the Internal error goes away.
> 
> I have attempted to construct a simple case with two similar structs with opSub methods and a main() containing the problem expression, however I cannot reproduce the error.
> 
> Any suggestions on where to go from here? 

Generally, I do binary search on my code.  I comment out huge swaths of code that I think might be irrelevant, then recompile.  If the failure goes away, then I only comment out half of that section, and try again.

It's a painful, iterative process, but it usually works.  Most times I can reduce 1000s of lines of code down to a 10-line example.

If you don't have time for that, I would recommend that you still post the bug with your complete code.  Maybe somebody else will have time. IMHO, it ought to be recorded.
April 02, 2008
"Steven Schveighoffer" <schveiguy@yahoo.com> wrote in message news:ft04i9$5in$1@digitalmars.com...
> "Neil Vice" wrote in message
>> I've encountered the following error in DMD 2.012:
>>
>>    Internal error: ..\ztc\cod1.c 1662
>>
>> I would submit a bug report except that I can't seem to determine a simple case that produces the bug, so I guess I'm looking for some assistance in narrowing down the problem.
>>
>> I have two structs, one representing a time-stamp and another representing a time-period. They both implement opSub. Nested within a method in a class within a class in a seperate package I have some code along the lines of:
>>
>>    auto result = a - (b - c);
>>
>> where a is a TimePeriod and b & c are TimeStamps.
>>
>> If I replace this line with:
>>
>>    auto _result = b - c;
>>    auto result = a - _result;
>>
>> the Internal error goes away.
>>
>> I have attempted to construct a simple case with two similar structs with opSub methods and a main() containing the problem expression, however I cannot reproduce the error.
>>
>> Any suggestions on where to go from here?
>
> Try to reproduce the error with a simple main function that does just the lines above.
>
> If this still fails, then try removing pieces of your classes, making sure the error remains.  When you narrow that down, you might be able to see clearer what the minimal case is.
>
> If this doesn't fail, then try moving around where you are making the auto result = a - (b - c) call, trying to simplify that code.
>
> Good luck.
>
> -Steve

Well I had another crack at it and have come up with a simpler case.

The error only occurs when you attempt an operation (duplicated only for + and - so far) on operands for which that operation has not been defined. Furthermore it appears that one of the operands must be a const variable. I've also only encountered the error when the other operand was the result of another expression i.e. not a simple variable.

What's interesting also is the fact that replacing "auto result = a - (b - c);" with "auto tmp = b - c; auto result = a - tmp;" neither causes the internal error nor causes a compile error due to the fact that the operation "a - tmp" is undefined as far as I can tell.

I wonder what the compiler actually generates there...

http://d.puremagic.com/issues/show_bug.cgi?id=1969



April 02, 2008
Russell Lewis:
> Generally, I do binary search on my code.  I comment out huge swaths of code that I think might be irrelevant, then recompile.  If the failure goes away, then I only comment out half of that section, and try again. It's a painful, iterative process, but it usually works. Most times I can reduce 1000s of lines of code down to a 10-line example.

Computers are good at performing quickly boring operations. So there are ways to automate that. For a simple Python implementation you can look here, inside the software of the book "Beautiful Code", subdirectory "Zeller":
http://examples.oreilly.com/9780596510046/examples.zip
Around there are better implementations of that idea, written in C too.

Bye,
bearophile