Skip to content

Commit d6e2dae

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Add basic compiler infra
Summary: This adds new classes for a 3.15 compiler version. Reviewed By: martindemello Differential Revision: D85912010 fbshipit-source-id: 451e670ff1013e076df29c7b9ddbb34336d3513e
1 parent 73b1351 commit d6e2dae

6 files changed

Lines changed: 55 additions & 3 deletions

File tree

cinderx/PythonLib/cinderx/compiler/opcodes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,16 @@
796796
LOAD_TYPE=1,
797797
LOAD_METHOD_STATIC=2,
798798
)
799+
800+
if sys.version_info >= (3, 15):
801+
opcode.popped.update(
802+
FOR_ITER=2,
803+
POP_ITER=2,
804+
)
805+
opcode.pushed.update(
806+
FOR_ITER=3,
807+
GET_ITER=2,
808+
)
799809
for opname, popped in opcode.popped.items():
800810
pushed = opcode.pushed[opname]
801811
if isinstance(popped, int) and isinstance(pushed, int):

cinderx/PythonLib/cinderx/compiler/pyassem.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,10 @@ def optimizeCFG(self) -> None:
32563256
_const_opcodes: set[str] = set(PyFlowGraph312._const_opcodes) | {"LOAD_SMALL_INT"}
32573257

32583258

3259+
class PyFlowGraph315(PyFlowGraph314):
3260+
pass
3261+
3262+
32593263
# Constants for reference tracking flags
32603264
SUPPORT_KILLED = (
32613265
1 # The loaded reference is still on the stack when the local is killed

cinderx/PythonLib/cinderx/compiler/pycodegen.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
PyFlowGraph310,
6565
PyFlowGraph312,
6666
PyFlowGraph314,
67+
PyFlowGraph315,
6768
PyFlowGraphCinder310,
6869
PyFlowGraphCinder312,
6970
ResumeOparg,
@@ -82,6 +83,7 @@
8283
SymbolVisitor310,
8384
SymbolVisitor312,
8485
SymbolVisitor314,
86+
SymbolVisitor315,
8587
TypeParams,
8688
TypeParamScope,
8789
TypeVarDefault,
@@ -7194,6 +7196,10 @@ def visitInterpolation(self, node: ast.Interpolation) -> None:
71947196
self.emit("BUILD_INTERPOLATION", oparg)
71957197

71967198

7199+
class CodeGenerator315(CodeGenerator314):
7200+
flow_graph = PyFlowGraph315
7201+
7202+
71977203
class CinderCodeGenerator310(CinderCodeGenBase, CodeGenerator310):
71987204
flow_graph = PyFlowGraphCinder310
71997205
_SymbolVisitor = CinderSymbolVisitor
@@ -7298,7 +7304,13 @@ class CinderCodeGenerator314(CinderCodeGenerator312, CodeGenerator314):
72987304
flow_graph = PyFlowGraph314
72997305

73007306

7307+
class CinderCodeGenerator315(CinderCodeGenerator312, CodeGenerator315):
7308+
flow_graph = PyFlowGraph315
7309+
7310+
73017311
def get_default_cinder_generator() -> type[CodeGenerator]:
7312+
if sys.version_info >= (3, 15):
7313+
return CinderCodeGenerator315
73027314
if sys.version_info >= (3, 14):
73037315
return CinderCodeGenerator314
73047316
elif sys.version_info >= (3, 12):
@@ -7308,6 +7320,8 @@ def get_default_cinder_generator() -> type[CodeGenerator]:
73087320

73097321

73107322
def get_default_cpython_generator() -> type[CodeGenerator]:
7323+
if sys.version_info >= (3, 15):
7324+
return CodeGenerator315
73117325
if sys.version_info >= (3, 14):
73127326
return CodeGenerator314
73137327
elif sys.version_info >= (3, 12):

cinderx/PythonLib/cinderx/compiler/static/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
PyFlowGraph,
3939
PyFlowGraph312,
4040
PyFlowGraph314,
41+
PyFlowGraph315,
4142
PyFlowGraphCinder310,
4243
)
4344
from ..pycodegen import (
4445
CinderCodeGenerator310,
4546
CinderCodeGenerator312,
4647
CinderCodeGenerator314,
48+
CinderCodeGenerator315,
4749
CodeGenerator,
4850
CodeGenTree,
4951
compile_code,
@@ -1387,7 +1389,13 @@ def emit_load_static_method(
13871389
)
13881390

13891391

1390-
if sys.version_info >= (3, 14):
1392+
class Static315CodeGenerator(Static314CodeGenerator, CinderCodeGenerator315):
1393+
pass
1394+
1395+
1396+
if sys.version_info >= (3, 15):
1397+
StaticCodeGenerator = Static315CodeGenerator
1398+
elif sys.version_info >= (3, 14):
13911399
StaticCodeGenerator = Static314CodeGenerator
13921400
elif sys.version_info >= (3, 12):
13931401
StaticCodeGenerator = Static312CodeGenerator

cinderx/PythonLib/cinderx/compiler/strict/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
from types import CodeType
1111
from typing import Any
1212

13-
from ..pyassem import PyFlowGraph312, PyFlowGraph314, PyFlowGraphCinder310
13+
from ..pyassem import (
14+
PyFlowGraph312,
15+
PyFlowGraph314,
16+
PyFlowGraph315,
17+
PyFlowGraphCinder310,
18+
)
1419
from ..pycodegen import (
1520
CinderCodeGenerator310,
1621
CinderCodeGenerator312,
1722
CinderCodeGenerator314,
23+
CinderCodeGenerator315,
1824
)
1925
from .code_gen_base import StrictCodeGenBase
2026

@@ -35,6 +41,10 @@ class StrictCodeGenerator314(StrictCodeGenerator312, CinderCodeGenerator314):
3541
flow_graph = PyFlowGraph314
3642

3743

44+
class StrictCodeGenerator315(StrictCodeGenerator312, CinderCodeGenerator315):
45+
flow_graph = PyFlowGraph315
46+
47+
3848
def strict_compile(
3949
name: str,
4050
filename: str,
@@ -49,7 +59,9 @@ def strict_compile(
4959
return code_gen.getCode()
5060

5161

52-
if sys.version_info >= (3, 14):
62+
if sys.version_info >= (3, 15):
63+
StrictCodeGenerator = StrictCodeGenerator315
64+
elif sys.version_info >= (3, 14):
5365
StrictCodeGenerator = StrictCodeGenerator314
5466
elif sys.version_info >= (3, 12):
5567
StrictCodeGenerator = StrictCodeGenerator312

cinderx/PythonLib/cinderx/compiler/symbols.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,3 +1746,7 @@ def _visit_func_impl(
17461746
self.visit_list(node.body, scope)
17471747

17481748
parent.add_child(scope)
1749+
1750+
1751+
class SymbolVisitor315(SymbolVisitor314):
1752+
pass

0 commit comments

Comments
 (0)