Skip to content

[GR-81913] Honor Python optimization flags and environment settings. - #1333

Merged
graalvmbot merged 2 commits into
masterfrom
fniephaus/GR-81913/optimize-flags
Nov 23, 2026
Merged

graalvmbot merged 2 commits into
masterfrom
fniephaus/GR-81913/optimize-flags

Conversation

@graalvmbot

Copy link
Copy Markdown
Collaborator

🤖 The launcher accepts -O and -OO but ignores them and never reads PYTHONOPTIMIZE. The compiler supports optimization levels, but its process default is boolean, and file/stdin and interactive execution force level 0.

Add the integer engine option python.OptimizationLevel and wire repeated/clustered -O flags and PYTHONOPTIMIZE to it. Match CPython's environment parsing and maximum-of-flags/environment behavior, respecting -E and -I. Preserve the stable boolean PythonOptimizeFlag option as an alias for level 1.

Use the resolved level for sys.flags.optimize, builtins.debug, and default compilation, including files, stdin, interactive/inline parsing, compile(), exec(), eval(), and optimized ASTs. Explicit compile/source optimization levels continue to override the context default. Document the embedding option and update launcher help.

Add nine Python regression methods covering flags, environment precedence, assertions, docstrings, execution modes, dynamic compilation and import cache levels. Extend embedding tests for source overrides and code-cache separation between contexts sharing an engine.

Validation on Linux AArch64 with JDK 25:

  • Source JVM standalone and targeted JUnit dependency builds passed.
  • 117 Python tests passed, with 2 Windows-only skips, across the new regressions and related parser, assertion, code, AST, sys and import tests.
  • All 5 SourceOptionsTests embedding tests passed. All 8 portable regression methods also passed on CPython; the GraalPy-only method was skipped there.
  • The flag regression fails on the baseline. The fixed reproducer reports 1/False for -O, 2/False with removed docstrings for -OO, and the corresponding environment behavior.
  • Eclipse formatting, Checkstyle and diff checks passed.

Signed-off-by: Fabio Niephaus <fabio.niephaus@oracle.com>
Signed-off-by: Fabio Niephaus <fabio.niephaus@oracle.com>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 23, 2026
@graalvmbot
graalvmbot merged commit 96f2295 into master Nov 23, 2026
12 of 17 checks passed
@graalvmbot
graalvmbot deleted the fniephaus/GR-81913/optimize-flags branch November 23, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants