Skip to content

Commit 1a49aa8

Browse files
authored
Add tail_call_interp to the bench configuration file (#465)
1 parent a1d16c7 commit 1a49aa8

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

doc/benchmark.conf.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pgo = True
5151
# PYTHON_JIT=0 can be used to disable the micro-op interpreter at runtime.
5252
jit = no
5353

54+
# Tail-calling interpreter?
55+
tail_call_interp = False
56+
5457
# The space-separated list of libraries that are package-only,
5558
# i.e., locally installed but not on header and library paths.
5659
# For each such library, determine the install path and add an

pyperformance/compile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ def compile(self):
295295
config_args.append("--with-lto")
296296
if self.conf.jit:
297297
config_args.append(f"--enable-experimental-jit={self.conf.jit}")
298+
if self.conf.tail_call_interp:
299+
config_args.append("--with-tail-call-interp")
298300
if self.conf.pkg_only:
299301
config_args.extend(self.get_package_only_flags())
300302
if self.conf.debug:
@@ -830,6 +832,7 @@ def getint(section, key, default=None):
830832
conf.lto = getboolean("compile", "lto", True)
831833
conf.pgo = getboolean("compile", "pgo", True)
832834
conf.jit = getstr("compile", "jit", "")
835+
conf.tail_call_interp = getboolean("compile", "tail_call_interp", False)
833836
conf.install = getboolean("compile", "install", True)
834837
conf.pkg_only = getstr("compile", "pkg_only", "").split()
835838
try:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import os
2+
import pathlib
3+
import tempfile
4+
import textwrap
5+
import types
6+
import unittest
7+
from unittest import mock
8+
9+
from pyperformance import compile as compile_mod
10+
11+
12+
class ParseConfigTests(unittest.TestCase):
13+
def test_parse_config_reads_tail_call_interp(self):
14+
with tempfile.TemporaryDirectory() as tmpdir:
15+
root = pathlib.Path(tmpdir)
16+
config_path = root / "benchmark.conf"
17+
config_path.write_text(
18+
textwrap.dedent(
19+
f"""\
20+
[config]
21+
json_dir = {root / "json"}
22+
23+
[scm]
24+
repo_dir = {root / "cpython"}
25+
26+
[compile]
27+
bench_dir = {root / "bench"}
28+
tail_call_interp = true
29+
30+
[run_benchmark]
31+
"""
32+
),
33+
encoding="utf-8",
34+
)
35+
36+
conf = compile_mod.parse_config(str(config_path), "compile")
37+
38+
self.assertTrue(conf.tail_call_interp)
39+
40+
41+
class CompileCommandTests(unittest.TestCase):
42+
def test_compile_adds_tail_call_interp_flag(self):
43+
conf = types.SimpleNamespace(
44+
build_dir="/tmp/build",
45+
repo_dir="/tmp/cpython",
46+
prefix="",
47+
debug=False,
48+
lto=False,
49+
pgo=True,
50+
jit="",
51+
tail_call_interp=True,
52+
pkg_only=[],
53+
jobs=0,
54+
)
55+
app = types.SimpleNamespace(
56+
branch="main",
57+
logger=None,
58+
safe_makedirs=mock.Mock(),
59+
run=mock.Mock(),
60+
)
61+
62+
compile_mod.Python(app, conf).compile()
63+
64+
configure_call = app.run.call_args_list[0]
65+
self.assertEqual(
66+
configure_call.args,
67+
(os.path.join(conf.repo_dir, "configure"), "--with-tail-call-interp"),
68+
)
69+
self.assertEqual(configure_call.kwargs, {"cwd": "/tmp/build"})
70+
71+
72+
if __name__ == "__main__":
73+
unittest.main()

0 commit comments

Comments
 (0)