Skip to content

[SOT] Add tracker for generator in Python 3.11+ #71777

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

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 @@ -28,7 +28,7 @@
from .dispatch_functions import generator_send
from .guard import StringifiedExpression, union_free_vars
from .opcode_executor import OpcodeExecutorBase, Stop
from .tracker import DanglingTracker, DummyTracker, Tracker
from .tracker import DanglingTracker, Tracker
from .variables import (
BuiltinVariable,
ConstantVariable,
Expand Down Expand Up @@ -245,8 +245,9 @@ def inline_call(self) -> VariableBase:
def RETURN_GENERATOR(self, instr: Instruction):
vframe = self.vframe
code_var = self._code_var
# NOTE: we set the real tracker in calling function
self.return_value = GeneratorVariable(
code_var, vframe, self._graph, DummyTracker([]) # TODO: Add tracker
code_var, vframe, self._graph, DanglingTracker()
)
return Stop(state="Return")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,12 @@ def call_function(self, /, *args, **kwargs):
inline_gen_executor = OpcodeInlineGeneratorExecutor(
vframe, code_var, self.graph
)
return inline_gen_executor.inline_call()
gen = inline_gen_executor.inline_call()
assert isinstance(
gen, GeneratorVariable
), f"GeneratorFunction calling result should be GeneratorVariable, but got {type(gen)}"
gen.tracker = DummyTracker([self, *args, *kwargs.values()])
Copy link
Preview

Copilot AI Mar 19, 2025

Choose a reason for hiding this comment

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

The tracker's type is assigned using DummyTracker here, while in opcode_inline_executor.py, a DanglingTracker is used. This inconsistency may lead to unexpected behavior.

Suggested change
gen.tracker = DummyTracker([self, *args, *kwargs.values()])
gen.tracker = DanglingTracker([self, *args, *kwargs.values()])

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

给你一拳

return gen
return GeneratorVariable(
code_var,
vframe,
Expand Down
Loading