Skip to content

Commit 1886b04

Browse files
DinoVfacebook-github-bot
authored andcommitted
Fix LOAD_ASSERITON_ERROR code gen
Summary: 3.14 has moved `LOAD_ASSERTION_ERROR` into a new `LOAD_COMMON_CONSTANT` opcode. Reviewed By: alexmalyshev Differential Revision: D80753194 fbshipit-source-id: 0fad1a0e029647a3b2eed28cbfc512ceea418a6b
1 parent bd245ec commit 1886b04

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

cinderx/PythonLib/cinderx/compiler/pyassem.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,13 @@ class PyFlowGraphCinder312(PyFlowGraphCinderMixin, PyFlowGraph312):
22132213

22142214
class PyFlowGraph314(PyFlowGraph312):
22152215
flow_graph_optimizer = FlowGraphOptimizer314
2216+
_constant_idx = {
2217+
AssertionError: 0,
2218+
}
2219+
_converters: dict[str, Callable[[PyFlowGraph, object], int]] = {
2220+
**PyFlowGraph312._converters,
2221+
"LOAD_COMMON_CONSTANT": lambda self, val: PyFlowGraph314._constant_idx[val],
2222+
}
22162223

22172224
def instrsize(self, opname: str, oparg: int) -> int:
22182225
base_size = _inline_cache_entries.get(opname, 0)

cinderx/PythonLib/cinderx/compiler/pycodegen.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,12 @@ def _visitSequenceLoad(
26882688
) -> None:
26892689
raise NotImplementedError()
26902690

2691+
def emit_load_assertion_error(self, loc: AST | SrcLocation | None = None) -> None:
2692+
if loc:
2693+
self.graph.emit_with_loc("LOAD_ASSERTION_ERROR", 0, loc)
2694+
else:
2695+
self.emit("LOAD_ASSERTION_ERROR")
2696+
26912697
def visitAssert(self, node: ast.Assert) -> None:
26922698
raise NotImplementedError()
26932699

@@ -2809,7 +2815,7 @@ def visitAssert(self, node: ast.Assert) -> None:
28092815
end = self.newBlock()
28102816
self.compileJumpIf(node.test, end, True)
28112817

2812-
self.emit("LOAD_ASSERTION_ERROR")
2818+
self.emit_load_assertion_error()
28132819
if node.msg:
28142820
self.visit(node.msg)
28152821
self.emit_call_one_arg()
@@ -3867,7 +3873,7 @@ def visitAssert(self, node: ast.Assert) -> None:
38673873
end = self.newBlock()
38683874
self.compileJumpIf(node.test, end, True)
38693875

3870-
self.graph.emit_with_loc("LOAD_ASSERTION_ERROR", 0, node)
3876+
self.emit_load_assertion_error(node)
38713877
if node.msg:
38723878
self.visit(node.msg)
38733879
self.set_pos(node)
@@ -5935,6 +5941,12 @@ def optimize_tree(
59355941
def emit_binary_subscr(self) -> None:
59365942
self.emit("BINARY_OP", self.find_op_idx("NB_SUBSCR"))
59375943

5944+
def emit_load_assertion_error(self, loc: AST | SrcLocation | None = None) -> None:
5945+
if loc:
5946+
self.graph.emit_with_loc("LOAD_COMMON_CONSTANT", AssertionError, loc)
5947+
else:
5948+
self.emit("LOAD_COMMON_CONSTANT", AssertionError)
5949+
59385950
def emit_kwonlydefaults(self, node: FuncOrLambda) -> bool:
59395951
default_count = 0
59405952
for kwonly, default in zip(node.args.kwonlyargs, node.args.kw_defaults):

0 commit comments

Comments
 (0)