summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2022-02-02 20:02:59 -0800
committerGitHub <noreply@github.com>2022-02-02 20:02:59 -0800
commitf5ebec4d3e1199ec38b88920cfde8e460e5120dd (patch)
tree499948f4d385f17a2d5b7e186ef128b847fdb0bb /Tools
parentbpo-45975: Use walrus operator for some idlelib while loops (GH-31083) (diff)
downloadcpython-f5ebec4d3e1199ec38b88920cfde8e460e5120dd.tar.gz
cpython-f5ebec4d3e1199ec38b88920cfde8e460e5120dd.tar.bz2
cpython-f5ebec4d3e1199ec38b88920cfde8e460e5120dd.zip
[3.10] bpo-46576: bpo-46524: Disable compiler optimization within test_peg_generator. (GH-31015) (GH-31089)
Disable compiler optimization within test_peg_generator. This speed up test_peg_generator by always disabling compiler optimizations by using -O0 or equivalent when the test is building its own C extensions. A build not using --with-pydebug in order to speed up test execution winds up with this test taking a very long time as it would do repeated compilation of parser C code using the same optimization flags as CPython was built with. This speeds the test up 6-8x on gps-raspbian. Also incorporate's GH-31017's win32 conditional and flags. Co-authored-by: Kumar Aditya kumaraditya303. (cherry picked from commit 164a017e13ee96bd1ea1ae79f5ac9e25fe83994e) Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Tools')
-rw-r--r--Tools/peg_generator/pegen/build.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py
index b80fc854239..61a48d57145 100644
--- a/Tools/peg_generator/pegen/build.py
+++ b/Tools/peg_generator/pegen/build.py
@@ -1,6 +1,7 @@
import pathlib
import shutil
import tokenize
+import sys
import sysconfig
import tempfile
import itertools
@@ -33,6 +34,7 @@ def compile_c_extension(
build_dir: Optional[str] = None,
verbose: bool = False,
keep_asserts: bool = True,
+ disable_optimization: bool = True, # Significant test_peg_generator speedup.
) -> str:
"""Compile the generated source for a parser generator into an extension module.
@@ -62,6 +64,14 @@ def compile_c_extension(
extra_link_args = get_extra_flags("LDFLAGS", "PY_LDFLAGS_NODIST")
if keep_asserts:
extra_compile_args.append("-UNDEBUG")
+ if disable_optimization:
+ if sys.platform == 'win32':
+ extra_compile_args.append("/Od")
+ extra_link_args.append("/LTCG:OFF")
+ else:
+ extra_compile_args.append("-O0")
+ if sysconfig.get_config_var("GNULD") == "yes":
+ extra_link_args.append("-fno-lto")
extension = [
Extension(
extension_name,