Commit e2d1090f authored by Stefan Behnel's avatar Stefan Behnel

Fix branch prediction hints for plain (unlikely/exceptional) "raise"...

Fix branch prediction hints for plain (unlikely/exceptional) "raise" statements in if/else clauses that are not preceded by other statements.
parent 6e8c26e2
......@@ -6515,14 +6515,18 @@ class IfStatNode(StatNode):
def _set_branch_hint(self, clause, statements_node, inverse=False):
if not statements_node.is_terminator:
return
if not isinstance(statements_node, StatListNode) or not statements_node.stats:
if isinstance(statements_node, StatListNode):
if not statements_node.stats:
return
statements = statements_node.stats
else:
statements = [statements_node]
# Anything that unconditionally raises exceptions should be considered unlikely.
if isinstance(statements_node.stats[-1], (RaiseStatNode, ReraiseStatNode)):
if len(statements_node.stats) > 1:
if isinstance(statements[-1], (RaiseStatNode, ReraiseStatNode)):
if len(statements) > 1:
# Allow simple statements before the 'raise', but no conditions, loops, etc.
non_branch_nodes = (ExprStatNode, AssignmentNode, DelStatNode, GlobalNode, NonlocalNode)
for node in statements_node.stats[:-1]:
for node in statements[:-1]:
if not isinstance(node, non_branch_nodes):
return
clause.branch_hint = 'likely' if inverse else 'unlikely'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment