Skip to content

Commit 18b7331

Browse files
itamarometa-codesync[bot]
authored andcommitted
Emit INTRINSIC_ADD_CONDITIONAL_ANNOTATION for 3.16 conditional annotations
Summary: CPython gh-154902 changed how a conditional annotation's index is registered into the `__conditional_annotations__` set: instead of `SET_ADD`, 3.16 emits the new `INTRINSIC_ADD_CONDITIONAL_ANNOTATION` binary intrinsic (`CALL_INTRINSIC_2`). This diff mirrors that in cinderx's static bytecode compiler. Extract the emission into `CodeGenerator.emit_add_conditional_annotation()` (default: `SET_ADD 1`, preserving 3.12/3.14/3.15 output) and override it in `CodeGenerator316` to emit `CALL_INTRINSIC_2 INTRINSIC_ADD_CONDITIONAL_ANNOTATION`. The intrinsic index resolves via `emit_call_intrinsic_2`, which reads it from the running interpreter's opcode table, so it stays correct across versions. Fixes the 3.16 cinderx compiler-test breakage from the CPython main sync (SET_ADD vs CALL_INTRINSIC_2 disassembly mismatch). Reviewed By: DinoV Differential Revision: D115052327 fbshipit-source-id: 393d4d487fd7145c0c9af68632048236df671c4a
1 parent dcced3e commit 18b7331

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

cinderx/PythonLib/cinderx/compiler/pycodegen.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5992,9 +5992,14 @@ def emit_simple_ann_assign(self, node: ast.AnnAssign) -> None:
59925992
"__conditional_annotations__",
59935993
)
59945994
self.emit("LOAD_CONST", conditional_index)
5995-
self.emit("SET_ADD", 1)
5995+
self.emit_add_conditional_annotation()
59965996
self.emit("POP_TOP")
59975997

5998+
def emit_add_conditional_annotation(self) -> None:
5999+
# Register the annotation's index into the `__conditional_annotations__`
6000+
# set that is on top of the stack (below the just-loaded index).
6001+
self.emit("SET_ADD", 1)
6002+
59986003
def setup_annotations(
59996004
self,
60006005
loc: AST | SrcLocation,
@@ -6854,6 +6859,11 @@ class CodeGenerator316(CodeGenerator315):
68546859
# result is discarded (used as an expression statement).
68556860
_unused_listcomp_avoids_creation: bool = True
68566861

6862+
def emit_add_conditional_annotation(self) -> None:
6863+
# gh-154902: 3.16 registers a conditional annotation's index via the new
6864+
# INTRINSIC_ADD_CONDITIONAL_ANNOTATION binary intrinsic instead of SET_ADD.
6865+
self.emit_call_intrinsic_2("INTRINSIC_ADD_CONDITIONAL_ANNOTATION")
6866+
68576867
def make_annotations_code_holder(self, code_gen: CodeGenerator) -> CodeHolder:
68586868
# 3.16 extended the ".format" -> "format" rename to the
68596869
# typevar-bound/default and type-alias-value scopes (CPython's

0 commit comments

Comments
 (0)