Skip to content
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
2 changes: 1 addition & 1 deletion ddtrace/internal/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def transform_instruction(opcode: str, arg: t.Any) -> t.Tuple[str, t.Any]:
opcode = "LOAD_ATTR"
arg = (True, arg)
elif opcode.upper() == "LOAD_ATTR" and not isinstance(arg, tuple):
arg = (sys.version_info >= (3, 14), arg)
arg = (False, arg)

return opcode, arg

Expand Down
144 changes: 135 additions & 9 deletions ddtrace/internal/wrapping/asyncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
ASYNC_GEN_ASSEMBLY = Assembly()
ASYNC_HEAD_ASSEMBLY = None

if PY >= (3, 14):
if PY >= (3, 15):
raise NotImplementedError("This version of CPython is not supported yet")

elif PY >= (3, 14):
ASYNC_HEAD_ASSEMBLY = Assembly()
ASYNC_HEAD_ASSEMBLY.parse(
r"""
Expand All @@ -50,7 +53,7 @@

presend:
send @send
yield_value 2
yield_value 0
resume 3
jump_backward_no_interrupt @presend
send:
Expand All @@ -77,20 +80,19 @@
tried

try @genexit lasti
yield_value 3
yield_value 0
resume 3
jump_backward_no_interrupt @loop
send0:
end_send

yield:
call_intrinsic_1 asm.Intrinsic1Op.INTRINSIC_ASYNC_GEN_WRAP
yield_value 3
yield_value 0
resume 1
push_null
swap 2
load_fast $__ddgensend
swap 2
swap 3
call 1
jump_backward @loop
tried
Expand All @@ -110,7 +112,7 @@

presend1:
send @send1
yield_value 4
yield_value 0
resume 3
jump_backward_no_interrupt @presend1
send1:
Expand All @@ -122,19 +124,20 @@

exc:
pop_top
push_null
load_fast $__ddgen
load_attr (False, 'athrow')
push_null
load_const sys.exc_info
push_null
call 0
push_null
call_function_ex
get_awaitable 0
load_const None

presend2:
send @send2
yield_value 4
yield_value 0
resume 3
jump_backward_no_interrupt @presend2
send2:
Expand All @@ -159,6 +162,129 @@
"""
)

elif PY >= (3, 13):
ASYNC_HEAD_ASSEMBLY = Assembly()
ASYNC_HEAD_ASSEMBLY.parse(
r"""
return_generator
pop_top
"""
)

COROUTINE_ASSEMBLY.parse(
r"""
get_awaitable 0
load_const None

presend:
send @send
yield_value 0
resume 3
jump_backward_no_interrupt @presend
send:
end_send
"""
)

ASYNC_GEN_ASSEMBLY.parse(
r"""
try @stopiter
copy 1
store_fast $__ddgen
load_attr (False, 'asend')
store_fast $__ddgensend
load_fast $__ddgen
load_attr (True, '__anext__')
call 0

loop:
get_awaitable 0
load_const None
presend0:
send @send0
tried

try @genexit lasti
yield_value 0
resume 3
jump_backward_no_interrupt @loop
send0:
end_send

yield:
call_intrinsic_1 asm.Intrinsic1Op.INTRINSIC_ASYNC_GEN_WRAP
yield_value 0
resume 1
push_null
load_fast $__ddgensend
swap 3
call 1
jump_backward @loop
tried

genexit:
try @stopiter
push_exc_info
load_const GeneratorExit
check_exc_match
pop_jump_if_false @exc
pop_top
load_fast $__ddgen
load_attr (True, 'aclose')
call 0
get_awaitable 0
load_const None

presend1:
send @send1
yield_value 0
resume 3
jump_backward_no_interrupt @presend1
send1:
end_send
pop_top
pop_except
load_const None
return_value

exc:
pop_top
load_fast $__ddgen
load_attr (False, 'athrow')
push_null
load_const sys.exc_info
push_null
call 0
call_function_ex 0
get_awaitable 0
load_const None

presend2:
send @send2
yield_value 0
resume 3
jump_backward_no_interrupt @presend2
send2:
end_send
swap 2
pop_except
jump_backward @yield
tried

stopiter:
push_exc_info
load_const StopAsyncIteration
check_exc_match
pop_jump_if_false @propagate
pop_top
pop_except
load_const None
return_value

propagate:
reraise 0
"""
)

elif PY >= (3, 12):
ASYNC_HEAD_ASSEMBLY = Assembly()
Expand Down
92 changes: 86 additions & 6 deletions ddtrace/internal/wrapping/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
GENERATOR_ASSEMBLY = Assembly()
GENERATOR_HEAD_ASSEMBLY = None

if PY >= (3, 14):
if PY >= (3, 15):
raise NotImplementedError("This version of CPython is not supported yet")

elif PY >= (3, 14):
GENERATOR_HEAD_ASSEMBLY = Assembly()
GENERATOR_HEAD_ASSEMBLY.parse(
r"""
Expand All @@ -46,8 +49,86 @@
store_fast $__ddgen
load_attr $send
store_fast $__ddgensend
load_const next
push_null
load_fast_borrow $__ddgen

loop:
call 1
tried

yield:
try @genexit lasti
yield_value 0
resume 1
push_null
load_fast_borrow $__ddgensend
swap 3
jump_backward @loop
tried

genexit:
try @stopiter
push_exc_info
load_const GeneratorExit
check_exc_match
pop_jump_if_false @exc
pop_top
load_fast $__ddgen
load_method $close
call 0
swap 2
pop_except
return_value

exc:
pop_top
load_fast $__ddgen
load_attr $throw
push_null
load_const sys.exc_info
push_null
call 0
push_null
call_function_ex
swap 2
pop_except
jump_backward @yield
tried

stopiter:
push_exc_info
load_const StopIteration
check_exc_match
pop_jump_if_false @propagate
pop_top
pop_except
load_const None
return_value

propagate:
reraise 0
"""
)

elif PY >= (3, 13):
GENERATOR_HEAD_ASSEMBLY = Assembly()
GENERATOR_HEAD_ASSEMBLY.parse(
r"""
return_generator
pop_top
"""
)

GENERATOR_ASSEMBLY.parse(
r"""
try @stopiter
copy 1
store_fast $__ddgen
load_attr $send
store_fast $__ddgensend
load_const next
push_null
load_fast $__ddgen

loop:
Expand All @@ -56,12 +137,11 @@

yield:
try @genexit lasti
yield_value 3
yield_value 0
resume 1
push_null
swap 2
load_fast $__ddgensend
swap 2
swap 3
jump_backward @loop
tried

Expand All @@ -81,13 +161,13 @@

exc:
pop_top
push_null
load_fast $__ddgen
load_attr $throw
push_null
load_const sys.exc_info
push_null
call 0
call_function_ex
call_function_ex 0
swap 2
pop_except
jump_backward @yield
Expand Down
Loading
Loading