[SOT] Fix LOAD_METHOD
stack layout when bound instance override the __getattr__
#58956
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Bug fixes
PR changes
Others
Description
修复在
LOAD_METHOD
模拟执行时与 Python 行为不一致的问题当
LOAD_METHOD
的实例对象类上重载了__getattr__
时,method 并不会按照func | self | arg1 | arg2 | ... | argN
(左侧为栈底)的「method」布局,而是按照NULL | method | arg1 | arg2 | ... | argN
的「function」布局,因此模拟执行与真实执行会有一点 diff,在生成代码将栈上 Variable 恢复的时候可能出问题Python 3.8 的处理代码见:
https://github.com/python/cpython/blob/c1c6bedfd3ee66ad208e0cd9cdd732374c95b83d/Objects/object.c#L1149-L1153
Layer
本身重载了__getattr__
,因此用户继承的自定义类上的方法都会有这个问题,比如这里的
self.forward_features(x)
的 LOAD_METHOD 会因为Layer
重载了__getattr__
而变成NULL | self.forward_features
而不是MyLayer.forward_features | self
,此时发生 Fallback 而生成的代码就有可能出问题(最新的 fallback 会生成代码),因为模拟执行并不知道有一个 NULL,因此恢复时候将该 NULL STORE_FAST 到一个 local var,之后 LOAD 时候就会报错因此按照类似 Python 的处理方式,当用户重载了
__getattr__
时,同样认为它是「function」layoutPCard-66972