Power-Fx icon indicating copy to clipboard operation
Power-Fx copied to clipboard

Allow more than 20 And operatrors.

Open MikeStall opened this issue 10 months ago • 4 comments

This should succeed.

true && true && true && true && true &&
true && true && true && true && true && 
true && true && true && true && true &&
true && true && true && true && true &&
true && true && true && true && true &&
true && true && true && true && true &&
true && true && true && true && true &&
true && true && true && true && true

It's hitting protections for max nesting depth: Message:"Max call depth exceeded.

Note that arranging in flat form works:

And(
    true,true,true,true,true,
    true,true,true,true,true,
    true,true,true,true,true,
    true,true,true,true,true,
    true,true,true,true,true,
    true,true,true,true,true,
    true,true,true,true,true,
    true,true,true,true,true)

MikeStall avatar Feb 18 '25 18:02 MikeStall

Can't hosts simply

new PowerFxConfig(...)
{
    MaxCallDepth = NEW_MAX_NUMBER
}

anderson-joyle avatar Feb 18 '25 20:02 anderson-joyle

The problem is that fundamentally, a && b && c shouldn't threaten a stack overflow.

MikeStall avatar Feb 18 '25 21:02 MikeStall

This may help: https://github.com/microsoft/Power-Fx/blob/5132996c77c101f816a91e5a5e6287db6052e0ca/src/libraries/Microsoft.PowerFx.Core/IR/IRTranslator.cs#L600

I think similar optimization may help for all the operator that we convert to call node.

jas-valgotar avatar Feb 19 '25 16:02 jas-valgotar

This is doable, but will require a breaking change to update TexlNode. The current node is a binary op with just left and right - which mandates a deep tree structure which makes us suspectable to stack overflows. We need to change to a new node that is flat.

So: a+b+c+d

becomes this tree:

BinOp(BinOp(BinOp(a,b),c),d)

which is deep and recursive. We need a flatter structure:

BinOp(a,b,c,d)

MikeStall avatar Mar 27 '25 16:03 MikeStall

Fixing this on Fx side is a too large of breaking change. Even after the breaking change to AST, every visitor needs to be updated

We have made a fix on the MCS side to use And() instead of &&

MikeStall avatar Jul 01 '25 16:07 MikeStall