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] extract RETURN_VALUE and RETURN_CONST hard code #62073

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -47,7 +47,7 @@
calc_stack_effect,
get_instructions,
)
from ..instruction_utils.opcode_info import JumpDirection, PopJumpCond
from ..instruction_utils.opcode_info import RETURN, JumpDirection, PopJumpCond
from .dispatch_functions import (
operator_BAD,
operator_exception_match,
Expand Down Expand Up @@ -1644,8 +1644,10 @@ def FOR_ITER(self, instr):
start = self.indexof(instr)
end = self.indexof(instr.jump_to)
for i in range(start, end):
if self._instructions[i].opname == "RETURN_VALUE":
raise FallbackError("Found RETURN_VALUE in for loop body.")
if self._instructions[i].opname in RETURN:
raise FallbackError(
f"Found {self._instructions[i].opname} in for loop body."
)

self._graph.add_global_guarded_variable(iterator)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
from paddle.jit.utils import OrderedSet

from .instruction_utils import Instruction
from .opcode_info import ALL_JUMP, HAS_FREE, HAS_LOCAL, UNCONDITIONAL_JUMP
from .opcode_info import (
ALL_JUMP,
HAS_FREE,
HAS_LOCAL,
RETURN,
UNCONDITIONAL_JUMP,
)


@dataclasses.dataclass
Expand Down Expand Up @@ -122,7 +128,7 @@ def walk(state: State, start: int) -> OrderedSet[str]:
else State(OrderedSet(), OrderedSet(), OrderedSet())
)
return jump_branch | not_jump_branch
elif instr.opname == "RETURN_VALUE":
elif instr.opname in RETURN:
return state
return state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
UNCONDITIONAL_JUMP = {"JUMP_ABSOLUTE", "JUMP_FORWARD"}
if sys.version_info >= (3, 11):
UNCONDITIONAL_JUMP.add("JUMP_BACKWARD")
RETURN = {"RETURN_VALUE"}
if sys.version_info >= (3, 12):
RETURN.add("RETURN_CONST")


class JumpDirection(Enum):
Expand Down