Skip to content

Commit

Permalink
RollBACK opcode_translator
Browse files Browse the repository at this point in the history
  • Loading branch information
gouzil committed Jan 29, 2024
1 parent 1ce3ed8 commit f2335d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,7 @@ def step(self, instr: Instruction):
breakpoint() # noqa: T100

opname = instr.opname if instr.opname != "PRECALL" else "PRECALL__CALL"
if sys.version_info < (3, 12):
assert opname != "CALL", "CALL should fused with PRECALL"
assert opname != "CALL", "CALL should fused with PRECALL"
with EventGuard(f"{opname}", event_level=2):
return getattr(self, opname)(instr) # run single step.

Expand Down Expand Up @@ -717,33 +716,7 @@ def NOP(self, instr: Instruction):

@call_break_graph_decorator(push_n=1)
def LOAD_ATTR(self, instr: Instruction):
if sys.version_info >= (3, 12):
assert isinstance(instr.arg, int)
attr_name = self._code.co_names[instr.arg >> 1]
else:
attr_name = self._code.co_names[instr.arg]
if sys.version_info >= (3, 12) and instr.arg & 1:
attr_name_var = ConstantVariable.wrap_literal(
attr_name, self._graph
)
obj = self.stack.pop()

method = BuiltinVariable(
getattr, graph=self._graph, tracker=DanglingTracker()
)(obj, attr_name_var)

if isinstance(method, MethodVariable) and "__getattr__" not in dir(
method.bound_instance.get_py_type()
):
# bound method or the class override the __getattr__
# push the unbound method and the self
self.stack.push(method.fn)
self.stack.push(obj)
else:
# unbound method, push the dummy and the function
self.stack.push(NullVariable())
self.stack.push(method)
return
attr_name = self._code.co_names[instr.arg]
attr_name_var = ConstantVariable.wrap_literal(attr_name, self._graph)
obj = self.stack.pop()
self.stack.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,7 @@ def gen_unpack_sequence(self, count):

def gen_call_function(self, argc=0):
if sys.version_info >= (3, 11):
if sys.version_info == (3, 11):
self._add_instr("PRECALL", arg=argc, argval=argc)
self._add_instr("PRECALL", arg=argc, argval=argc)
self._add_instr("CALL", arg=argc, argval=argc)
else:
self._add_instr("CALL_FUNCTION", arg=argc, argval=argc)
Expand All @@ -892,8 +891,7 @@ def gen_call_function_ex(self, has_kwargs):

def gen_call_method(self, argc=0):
if sys.version_info >= (3, 11):
if sys.version_info == (3, 11):
self._add_instr("PRECALL", arg=argc, argval=argc)
self._add_instr("PRECALL", arg=argc, argval=argc)
self._add_instr("CALL", arg=argc, argval=argc)
else:
self._add_instr("CALL_METHOD", arg=argc, argval=argc)
Expand Down

0 comments on commit f2335d7

Please # to comment.