Skip to content

Commit acfd53a

Browse files
authored
Cleanup backwards compat layer for use_vectorcall and use_method_vectorcall (#18548)
Followup to #18341 and #18546 We only support Python 3.9+, so `PyObject_Vectorcall` and `PyObject_VectorcallMethod` are always available. Remove backwards compatibility layer.
1 parent bec0dd3 commit acfd53a

File tree

6 files changed

+14
-45
lines changed

6 files changed

+14
-45
lines changed

mypyc/codegen/emit.py

-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
REG_PREFIX,
1818
STATIC_PREFIX,
1919
TYPE_PREFIX,
20-
use_vectorcall,
2120
)
2221
from mypyc.ir.class_ir import ClassIR, all_concrete_classes
2322
from mypyc.ir.func_ir import FuncDecl
@@ -398,9 +397,6 @@ def _emit_attr_bitmap_update(
398397
if value:
399398
self.emit_line("}")
400399

401-
def use_vectorcall(self) -> bool:
402-
return use_vectorcall(self.capi_version)
403-
404400
def emit_undefined_attr_check(
405401
self,
406402
rtype: RType,

mypyc/codegen/emitclass.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ def native_slot(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:
3131
return f"{NATIVE_PREFIX}{fn.cname(emitter.names)}"
3232

3333

34-
def wrapper_slot(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:
35-
return f"{PREFIX}{fn.cname(emitter.names)}"
36-
37-
3834
# We maintain a table from dunder function names to struct slots they
3935
# correspond to and functions that generate a wrapper (if necessary)
4036
# and return the function name to stick in the slot.
@@ -137,12 +133,7 @@ def wrapper_slot(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:
137133

138134

139135
def generate_call_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:
140-
if emitter.use_vectorcall():
141-
# Use vectorcall wrapper if supported (PEP 590).
142-
return "PyVectorcall_Call"
143-
else:
144-
# On older Pythons use the legacy wrapper.
145-
return wrapper_slot(cl, fn, emitter)
136+
return "PyVectorcall_Call"
146137

147138

148139
def slot_key(attr: str) -> str:
@@ -333,7 +324,7 @@ def emit_line() -> None:
333324
flags = ["Py_TPFLAGS_DEFAULT", "Py_TPFLAGS_HEAPTYPE", "Py_TPFLAGS_BASETYPE"]
334325
if generate_full:
335326
flags.append("Py_TPFLAGS_HAVE_GC")
336-
if cl.has_method("__call__") and emitter.use_vectorcall():
327+
if cl.has_method("__call__"):
337328
fields["tp_vectorcall_offset"] = "offsetof({}, vectorcall)".format(
338329
cl.struct_name(emitter.names)
339330
)
@@ -381,7 +372,7 @@ def generate_object_struct(cl: ClassIR, emitter: Emitter) -> None:
381372
seen_attrs: set[tuple[str, RType]] = set()
382373
lines: list[str] = []
383374
lines += ["typedef struct {", "PyObject_HEAD", "CPyVTableItem *vtable;"]
384-
if cl.has_method("__call__") and emitter.use_vectorcall():
375+
if cl.has_method("__call__"):
385376
lines.append("vectorcallfunc vectorcall;")
386377
bitmap_attrs = []
387378
for base in reversed(cl.base_mro):
@@ -576,7 +567,7 @@ def generate_setup_for_class(
576567
field = emitter.bitmap_field(i)
577568
emitter.emit_line(f"self->{field} = 0;")
578569

579-
if cl.has_method("__call__") and emitter.use_vectorcall():
570+
if cl.has_method("__call__"):
580571
name = cl.method_decl("__call__").cname(emitter.names)
581572
emitter.emit_line(f"self->vectorcall = {PREFIX}{name};")
582573

mypyc/codegen/emitmodule.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
TYPE_VAR_PREFIX,
4646
shared_lib_name,
4747
short_id_from_name,
48-
use_vectorcall,
4948
)
5049
from mypyc.errors import Errors
5150
from mypyc.ir.func_ir import FuncIR
@@ -1106,7 +1105,7 @@ def is_fastcall_supported(fn: FuncIR, capi_version: tuple[int, int]) -> bool:
11061105
if fn.class_name is not None:
11071106
if fn.name == "__call__":
11081107
# We can use vectorcalls (PEP 590) when supported
1109-
return use_vectorcall(capi_version)
1108+
return True
11101109
# TODO: Support fastcall for __init__.
11111110
return fn.name != "__init__"
11121111
return True

mypyc/codegen/emitwrapper.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
NATIVE_PREFIX,
2525
PREFIX,
2626
bitmap_name,
27-
use_vectorcall,
2827
)
2928
from mypyc.ir.class_ir import ClassIR
3029
from mypyc.ir.func_ir import FUNC_STATICMETHOD, FuncIR, RuntimeArg
@@ -173,7 +172,7 @@ def generate_wrapper_function(
173172
arg_ptrs += [f"&obj_{groups[ARG_STAR2][0].name}" if groups[ARG_STAR2] else "NULL"]
174173
arg_ptrs += [f"&obj_{arg.name}" for arg in reordered_args]
175174

176-
if fn.name == "__call__" and use_vectorcall(emitter.capi_version):
175+
if fn.name == "__call__":
177176
nargs = "PyVectorcall_NARGS(nargs)"
178177
else:
179178
nargs = "nargs"

mypyc/common.py

-10
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,6 @@ def short_name(name: str) -> str:
106106
return name
107107

108108

109-
def use_vectorcall(capi_version: tuple[int, int]) -> bool:
110-
# We can use vectorcalls to make calls on Python 3.8+ (PEP 590).
111-
return capi_version >= (3, 8)
112-
113-
114-
def use_method_vectorcall(capi_version: tuple[int, int]) -> bool:
115-
# We can use a dedicated vectorcall API to call methods on Python 3.9+.
116-
return capi_version >= (3, 9)
117-
118-
119109
def get_id_from_name(name: str, fullname: str, line: int) -> str:
120110
"""Create a unique id for a function.
121111

mypyc/irbuild/ll_builder.py

+8-14
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
MIN_LITERAL_SHORT_INT,
2222
MIN_SHORT_INT,
2323
PLATFORM_SIZE,
24-
use_method_vectorcall,
25-
use_vectorcall,
2624
)
2725
from mypyc.errors import Errors
2826
from mypyc.ir.class_ir import ClassIR, all_concrete_classes
@@ -898,11 +896,9 @@ def py_call(
898896
899897
Use py_call_op or py_call_with_kwargs_op for Python function call.
900898
"""
901-
if use_vectorcall(self.options.capi_version):
902-
# More recent Python versions support faster vectorcalls.
903-
result = self._py_vector_call(function, arg_values, line, arg_kinds, arg_names)
904-
if result is not None:
905-
return result
899+
result = self._py_vector_call(function, arg_values, line, arg_kinds, arg_names)
900+
if result is not None:
901+
return result
906902

907903
# If all arguments are positional, we can use py_call_op.
908904
if arg_kinds is None or all(kind == ARG_POS for kind in arg_kinds):
@@ -977,13 +973,11 @@ def py_method_call(
977973
arg_names: Sequence[str | None] | None,
978974
) -> Value:
979975
"""Call a Python method (non-native and slow)."""
980-
if use_method_vectorcall(self.options.capi_version):
981-
# More recent Python versions support faster vectorcalls.
982-
result = self._py_vector_method_call(
983-
obj, method_name, arg_values, line, arg_kinds, arg_names
984-
)
985-
if result is not None:
986-
return result
976+
result = self._py_vector_method_call(
977+
obj, method_name, arg_values, line, arg_kinds, arg_names
978+
)
979+
if result is not None:
980+
return result
987981

988982
if arg_kinds is None or all(kind == ARG_POS for kind in arg_kinds):
989983
# Use legacy method call API

0 commit comments

Comments
 (0)