Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

[opcode][3.11] support MAKE_FUNCTION in py311 #356

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented Aug 30, 2023

支持python3.11MAKE_FUNCTION

python3.11:

 13           2 LOAD_CONST               8 ((2, 3, 4))
              4 LOAD_CONST               4 (<code object fn at 0x109149960, file "/Users/gouzi/Documents/git/paddle-symbolic-trace/tests/test_13_make_function.py", line 13>)
              6 MAKE_FUNCTION            1 (defaults)
              8 STORE_FAST               1 (fn)

python3.8:

 13           0 LOAD_CONST               9 ((2, 3, 4))
              2 LOAD_CONST               4 (<code object fn at 0x10e0126b0, file "/Users/gouzi/Downloads/PaddleSOT/tests/test_13_make_function.py", line 13>)
              4 LOAD_CONST               5 ('make_fn.<locals>.fn')
              6 MAKE_FUNCTION            1 (defaults)
              8 STORE_FAST               1 (fn)

相关任务:任务 5

单测状态变化:

  • test_13_make_function.py ❌ -> ✅

@paddle-bot
Copy link

paddle-bot bot commented Aug 30, 2023

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Aug 30, 2023
Comment on lines +1268 to +1278
if sys.version_info < (3, 11):
fn_name = self.stack.pop()
codeobj = self.stack.pop()
if sys.version_info >= (3, 11):
# MAKE_FUNCTION behavior actually changed in 3.11, see
# https://github.com/python/cpython/pull/93189/
assert hasattr(codeobj.value, "co_qualname")
fn_name = ConstantVariable(
codeobj.value.co_qualname, self._graph, DummyTracker([codeobj])
)

Copy link
Member Author

Choose a reason for hiding this comment

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

这里其实也可以写成

        if sys.version_info < (3, 11):
            self.stack.pop()
        codeobj = self.stack.pop()
        assert hasattr(codeobj.value, "co_qualname")
        fn_name = ConstantVariable(
            codeobj.value.co_qualname, self._graph, DummyTracker([codeobj])
        )

少一次判断

Copy link
Member

Choose a reason for hiding this comment

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

如果能保证 3.10 stack[-1] == stack[-2].co_qualname 倒是没问题,这点能保证么?如果不能保证就维持现有逻辑吧

Copy link
Member Author

Choose a reason for hiding this comment

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

不太行emmm,我回滚了

@gouzil gouzil requested review from SigureMo and zrr1999 and removed request for SigureMo August 30, 2023 08:49
SigureMo
SigureMo previously approved these changes Aug 30, 2023
Comment on lines +1268 to +1278
if sys.version_info < (3, 11):
fn_name = self.stack.pop()
codeobj = self.stack.pop()
if sys.version_info >= (3, 11):
# MAKE_FUNCTION behavior actually changed in 3.11, see
# https://github.com/python/cpython/pull/93189/
assert hasattr(codeobj.value, "co_qualname")
fn_name = ConstantVariable(
codeobj.value.co_qualname, self._graph, DummyTracker([codeobj])
)

Copy link
Member

Choose a reason for hiding this comment

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

如果能保证 3.10 stack[-1] == stack[-2].co_qualname 倒是没问题,这点能保证么?如果不能保证就维持现有逻辑吧

@SigureMo SigureMo changed the title [opcode] support MAKE_FUNCTION in py311 [opcode][3.11] support MAKE_FUNCTION in py311 Aug 30, 2023
@zrr1999 zrr1999 merged commit 9756df4 into PaddlePaddle:develop Aug 30, 2023
17 checks passed
@SigureMo SigureMo deleted the support_MAKE_FUNCTION_py311 branch August 30, 2023 14:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants