Skip to content

Commit

Permalink
[SOT][3.12] fix codegen out of range about generating LOAD_ATTR in …
Browse files Browse the repository at this point in the history
…Python 3.12 (#62176)
  • Loading branch information
diadestiny authored Feb 29, 2024
1 parent 4448d45 commit 473f7ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,14 @@ def gen_load_deref(self, name):
idx = self.cell_free_storage.index(name)
return self.add_instr("LOAD_DEREF", arg=idx, argval=name)

def gen_load_attr(self, name: str):
def gen_load_attr(self, name: str, is_method=False):
if name not in self._code_options["co_names"]:
self._code_options["co_names"].append(name)
idx = self._code_options["co_names"].index(name)
if sys.version_info >= (3, 12):
idx <<= 1
if is_method:
idx |= 1
return self.add_instr("LOAD_ATTR", arg=idx, argval=name)

def gen_store_attr(self, name: str):
Expand All @@ -763,6 +765,8 @@ def gen_delete_attr(self, name: str):
return self.add_instr("DELETE_ATTR", arg=idx, argval=name)

def gen_load_method(self, name: str):
if sys.version_info >= (3, 12):
return self.gen_load_attr(name, True)
if name not in self._code_options["co_names"]:
self._code_options["co_names"].append(name)
idx = self._code_options["co_names"].index(name)
Expand Down
1 change: 0 additions & 1 deletion test/sot/skip_files_py312
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
./test_11_jumps.py
./test_12_for_loop.py
./test_21_global.py
./test_builtin_zip.py
./test_inplace_api.py
./test_min_graph_size.py
Expand Down

0 comments on commit 473f7ba

Please sign in to comment.