def natural_loops(target: Function) -> int:
return sum([bb in bb.dominance_frontier for bb in target.basic_blocks])
The len() function will then return the length of this list, which is the number of basic blocks in target.basic_blocks, not the number of natural loops.
If you want to count the number of basic blocks that exist within their own dominance bounds (actually the number of natural loops), then you should use sum() instead of len().
def natural_loops(target: Function) -> int: return sum([bb in bb.dominance_frontier for bb in target.basic_blocks])
The len() function will then return the length of this list, which is the number of basic blocks in target.basic_blocks, not the number of natural loops.
If you want to count the number of basic blocks that exist within their own dominance bounds (actually the number of natural loops), then you should use sum() instead of len().