Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SOT][3.12] fix codegen out of range about generating LOAD_ATTR in Python 3.12 #62176

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 +765,13 @@ 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 name not in self._code_options["co_names"]:
self._code_options["co_names"].append(name)
idx = self._code_options["co_names"].index(name)
return self.add_instr("LOAD_METHOD", arg=idx, argval=name)
if sys.version_info >= (3, 12):
self.gen_load_attr(name, True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也加一个 return 吧,不然两个分支返回类型是不一致的

另外,加 return 的话,可以改写成 Early Return 的形式,去掉 else 及缩进

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

else:
if name not in self._code_options["co_names"]:
self._code_options["co_names"].append(name)
idx = self._code_options["co_names"].index(name)
return self.add_instr("LOAD_METHOD", arg=idx, argval=name)

def gen_delete_global(self, name: str):
if name not in self._code_options["co_names"]:
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