Repository navigation
Fix literal_unroll pass erroneously exiting on non-conformant loop. - #8321
Conversation
The guard code for checking a loop is conformant to what literal_unroll can handle was incorrectly exiting the pass if it encountered a non-conformant loop, e.g. a while loop, opposed to just ignoring it. Fixes numba#8311
gmarkall
left a comment
There was a problem hiding this comment.
I think I'm ready to approve this, but I first want to confirm my understanding of the issue and patch is correct. I have resisted understanding entirely how the literal unroll pass works in detail, because there's a lot to it, but my general understanding is that it unrolls the loop and generates a switch table on the type of the "current" item containing the loop body so it can be typed for each member type as appropriate.
Anyway, I think what happened was:
- On the first iteration of applying the transform in
MixedContainerUnroller.run_pass(),apply_transform()runs, transforms theliteral_unroll()loop, and then moves on to looking at thewhileloop. - It sees that the
whileloop is not in the correct form for a literal unroll, so it returnsFalse - Back in
run_pass,statgets set toFalse, and thereforemutateddoes too, and the iteration of applying the transform exits its "infinite loop". - The function was changed, but
run_passreturnsFalseand signals that it did not change anything, and chaos ensues from the resulting inconsistency.
With the fix, the big for loop in apply_transform carries on looking at all loops even if some of them aren't in a suitable form for transformation, and therefore correctly reports that a change was made, so the subsequent pipeline operations get a consistent / correct view of things.
If this is accurate then I think the fix and test are good. If it's inaccurate I'll have another attempt at understanding the situation 🙂
Thanks for taking a look at this @gmarkall. I think your description is close to my assessment, but I think the root cause comes from this large loop: numba/numba/core/untyped_passes.py Lines 1039 to 1132 in a06693d doing a scan of all loops to build up some analysis info into variable literal_unroll_info about the "literal_unroll" driven loops. The bug is that this analysis loop exits the entire function here if a non-conformant loop is found:numba/numba/core/untyped_passes.py Lines 1046 to 1047 in a06693d which means there's no transformation made, hence the literal_unroll pass has no effect and the getitem on a heterogeneous tuple still exists which leads to the typing error.
|
|
Ah, that explanation makes the error message make way more sense. The only way I could rationalise it was that something inconsistent made a lot of confusion down the line. Thanks for clarifying! |
gmarkall
left a comment
There was a problem hiding this comment.
This looks good to me, now that I understand the issue properly! 🙂
No problem. Thanks for the assessment and review. |
The guard code for checking a loop is conformant to what
literal_unroll can handle was incorrectly exiting the pass if it
encountered a non-conformant loop, e.g. a while loop, opposed to
just ignoring it.
Fixes #8311