Skip to content

Commit

Permalink
The oldest CAPI version we support right now is 3.7 (#15839)
Browse files Browse the repository at this point in the history
Looks like `capi_version < 3.7` is not supported, so I changed the
lowest version to be `3.7`.

Based on the discord discussion.
  • Loading branch information
sobolevn committed Aug 10, 2023
1 parent eab5b50 commit d0d63b4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
8 changes: 2 additions & 6 deletions mypyc/codegen/emitclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
generate_richcompare_wrapper,
generate_set_del_item_wrapper,
)
from mypyc.common import BITMAP_BITS, BITMAP_TYPE, NATIVE_PREFIX, PREFIX, REG_PREFIX, use_fastcall
from mypyc.common import BITMAP_BITS, BITMAP_TYPE, NATIVE_PREFIX, PREFIX, REG_PREFIX
from mypyc.ir.class_ir import ClassIR, VTableEntries
from mypyc.ir.func_ir import FUNC_CLASSMETHOD, FUNC_STATICMETHOD, FuncDecl, FuncIR
from mypyc.ir.rtypes import RTuple, RType, object_rprimitive
Expand Down Expand Up @@ -794,11 +794,7 @@ def generate_methods_table(cl: ClassIR, name: str, emitter: Emitter) -> None:
continue
emitter.emit_line(f'{{"{fn.name}",')
emitter.emit_line(f" (PyCFunction){PREFIX}{fn.cname(emitter.names)},")
if use_fastcall(emitter.capi_version):
flags = ["METH_FASTCALL"]
else:
flags = ["METH_VARARGS"]
flags.append("METH_KEYWORDS")
flags = ["METH_FASTCALL", "METH_KEYWORDS"]
if fn.decl.kind == FUNC_STATICMETHOD:
flags.append("METH_STATIC")
elif fn.decl.kind == FUNC_CLASSMETHOD:
Expand Down
5 changes: 2 additions & 3 deletions mypyc/codegen/emitmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
TOP_LEVEL_NAME,
shared_lib_name,
short_id_from_name,
use_fastcall,
use_vectorcall,
)
from mypyc.errors import Errors
Expand Down Expand Up @@ -1107,8 +1106,8 @@ def is_fastcall_supported(fn: FuncIR, capi_version: tuple[int, int]) -> bool:
# We can use vectorcalls (PEP 590) when supported
return use_vectorcall(capi_version)
# TODO: Support fastcall for __init__.
return use_fastcall(capi_version) and fn.name != "__init__"
return use_fastcall(capi_version)
return fn.name != "__init__"
return True


def collect_literals(fn: FuncIR, literals: Literals) -> None:
Expand Down
5 changes: 0 additions & 5 deletions mypyc/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ def short_name(name: str) -> str:
return name


def use_fastcall(capi_version: tuple[int, int]) -> bool:
# We can use METH_FASTCALL for faster wrapper functions on Python 3.7+.
return capi_version >= (3, 7)


def use_vectorcall(capi_version: tuple[int, int]) -> bool:
# We can use vectorcalls to make calls on Python 3.8+ (PEP 590).
return capi_version >= (3, 8)
Expand Down
4 changes: 2 additions & 2 deletions mypyc/test/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def build_ir_for_single_file2(

# By default generate IR compatible with the earliest supported Python C API.
# If a test needs more recent API features, this should be overridden.
compiler_options = compiler_options or CompilerOptions(capi_version=(3, 5))
compiler_options = compiler_options or CompilerOptions(capi_version=(3, 7))
options = Options()
options.show_traceback = True
options.hide_error_codes = True
Expand Down Expand Up @@ -272,7 +272,7 @@ def infer_ir_build_options_from_test_name(name: str) -> CompilerOptions | None:
return None
if "_32bit" in name and not IS_32_BIT_PLATFORM:
return None
options = CompilerOptions(strip_asserts="StripAssert" in name, capi_version=(3, 5))
options = CompilerOptions(strip_asserts="StripAssert" in name, capi_version=(3, 7))
# A suffix like _python3.8 is used to set the target C API version.
m = re.search(r"_python([3-9]+)_([0-9]+)(_|\b)", name)
if m:
Expand Down

0 comments on commit d0d63b4

Please sign in to comment.