Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IronPython bug related to long boolean expressions?

Tags:

ironpython

There seems to be something funny going on here. Using IronPython 2.6.2 for .NET 4.0, I get the following behaviour. The simplest case is as follows:

  1. I start the interactive shell
  2. I type the following line 5 times

    False or False or False or False or False or False or \
    
  3. I then end it with the following line

    False or False or False or False or False or False
    

As I am typing this, the process has clocked up 30 CPU minutes on a fairly good desktop and still not returned.

If I reduce step 2 by 1 i.e. have the line 4 times, then it returns in about a minute or two.

If I reduce step 2 by 2 ie. have the line 3 times, then it returns in about a second or so.

So what is happening, and why?

Of course, the real world example that caused me to isolate this is much more complex and not quite as frivolous looking.

Thanks Akil

like image 855
Akil Avatar asked Aug 08 '26 03:08

Akil


1 Answers

I'd suggest opening a bug on CodePlex. What's happening here is that IronPython's OrExpression AST node is attempting to discover it's type. To do that it looks at the left hand type and the right hand type. If they're the same OrExpression will produce an expression of the type on the left hand side - which is checked again. That 2nd call is mostly what causes this to grow out of proportion. Simply changing OrExpression.cs from:

return _left.Type == _right.Type ? _left.Type : typeof(object);

to:

Type lType = _left.Type;
return lType == _right.Type ? lType : typeof(object);

fixes the problem.

like image 74
Dino Viehland Avatar answered Aug 10 '26 21:08

Dino Viehland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!