-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[SOT][3.12] fix codegen out of range about generating LOAD_ATTR
in Python 3.12
#62176
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
def gen_load_attr(self, name: str, push_null=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 push_null: | ||
idx |= 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
与 LOAD_GLOBAL
不同,LOAD_ATTR
在 3.12 的最后一位用于表示 is_method
,所以变量名需要修改下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if sys.version_info >= (3, 12): | ||
codegen.gen_load_attr("update", True) | ||
else: | ||
codegen.gen_load_method("update") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不建议在这里做版本分发,可以考虑在 gen_load_method
中将 3.12+ 行为分发到 gen_load_attr(name, is_method)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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) |
There was a problem hiding this comment.
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 及缩进
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR types
Others
PR changes
Others
Description
python 3.12中,test_21_global.py单测codegen超出范围报错:
ValueError: bytes must be in range(0, 256)
,排查发现是因为side_effect文件的dict默认调用gen_load_method,对应的opcode是262 所以出错;3.12中dict.update/clear函数调用不会生成
LOAD_METHOD
字节码,所以改成生成LOAD_ATTR
,而dict的update/clear方法需要生成LOAD_ATTR
额外push NULL;TODO: test_inplace_api.py存在类似codegen问题和
POP_JUMP_FORWARD_IF_FALSE
不支持生成问题