Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_peg_generator now disables compiler optimization when testing
compilation of its own C extensions to significantly speed up the
testing on non-debug builds of CPython.
8 changes: 8 additions & 0 deletions Tools/peg_generator/pegen/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import itertools
import pathlib
import shutil
import sys
import sysconfig
import tempfile
import tokenize
Expand Down Expand Up @@ -32,6 +33,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.

Expand Down Expand Up @@ -61,6 +63,12 @@ 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")
extension = [
Extension(
extension_name,
Expand Down