-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-2506: Add -X noopt command line option #13600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@nedbat: Would you mind to test this change, maybe also review it? |
@@ -440,6 +441,9 @@ always available. | |||
Added ``dev_mode`` attribute for the new :option:`-X` ``dev`` flag | |||
and ``utf8_mode`` attribute for the new :option:`-X` ``utf8`` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to change these two (and line 424-425) for consistent style :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to not change these on purpose, it would be an unrelated change. Someone can work on a PR to update these once this PR is merged ;-)
I ran the Python test suite with -X noopt and I got multiple failures. I fixed all of them. I had to make additional changes:
|
Azure Pipelines PR: test_venv failed with a timeout (20 min) in the win32 job, but passed when run again. It's unrelated. |
Oh wow. When I ran the test suite using -X noopt, I found more and more issues, and I had to modify more ane more code. I didn't expect that I would have to go up to compile() to add a new parameter. It is need indirectly by distutils which uses py_compile. IMHO distutils must simply ignore noopt and always enable compiler optimizations. I don't see much value in distributing non optimized .pyc files on purpose. The common case is to expect optimized .pyc files. I will not have time to finish this PR and review it carefully before Friday (Python 3.8 feature freeze), so I prefer to tag the PR as WIP. |
I agree with @vstinner that worrying about |
It is unfortunate that in the current state of the code, you can’t control the compilation of pyc files in distutils build commands with options: the result depends on the -B/-O options passed to the python command itself. I had changed it in distutils2 but thought it could not be changed in distutils. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very large change. Are all of them necessary? Could we encode this option as special optimization level or compiler flag? This might keep more code unchanged.
@@ -27,7 +27,7 @@ byte-code cache files in the directory containing the source code. | |||
Exception raised when an error occurs while attempting to compile the file. | |||
|
|||
|
|||
.. function:: compile(file, cfile=None, dfile=None, doraise=False, optimize=-1, invalidation_mode=PycInvalidationMode.TIMESTAMP) | |||
.. function:: compile(file, cfile=None, dfile=None, doraise=False, optimize=-1, invalidation_mode=PycInvalidationMode.TIMESTAMP, *, noopt=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimize
and noopt
. It looks slightly weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know but I failed to find better names.
PyCompilerFlags *flags, | ||
int optimization_level, | ||
PyArena *arena, | ||
int noopt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not it be controlled by flags
or optimization_level
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimization_level=0 still means having optimizations enabled. I cannot change to keep the backward compatibility.
Do you think that it would be better to add a new PyCF_xxx
flag to avoid adding this new function?
@@ -158,7 +158,8 @@ struct compiler { | |||
PyFutureFeatures *c_future; /* pointer to module's __future__ */ | |||
PyCompilerFlags *c_flags; | |||
|
|||
int c_optimize; /* optimization level */ | |||
int c_optimize; /* optimize bytecode? */ | |||
int c_optimization_level; /* optimization level */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use -1
for noopt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 has a special meaning for compile functions. I prefer to have a separated field to avoid confusion.
@serhiy-storchaka: "This is a very large change. Are all of them necessary? Could we encode this option as special optimization level or compiler flag? This might keep more code unchanged." In GCC, I dislike |
Add -X noopt command line option to disable compiler optimizations. distutils ignores noopt: always enable compiler optimizations. * Add sys.flags.noopt flag. * Add 'noopt' keyword-only parameter to builtin compile(), importlib.util.cache_from_source() and py_compile.compile(). * importlib: SourceLoader gets an additional keyword-only '_noopt' parameter. It is used by py_compile.compile(). * importlib uses ``.noopt.pyc`` suffix for .pyc files if sys.flags.noopt is true. * Add PyConfig.optimize parameter. * compiler: rename c_optimize to c_optimization_level, add c_optimize. * Update subprocess._optim_args_from_interpreter_flags(). * Add support.requires_compiler_optimizations() * Update unit tests which rely on compiler optimizations for noopt: add @support.requires_compiler_optimizations. * Add _PyAST_Compile() and _Py_CompileString() private functions: they have an additional 'noopt' parameter. * Set _Py_CONFIG_VERSION to 2 Co-Authored-By: Yury Selivanov <yury@magic.io>
I rebased my PR:
Latest commit message:
|
Open questions:
This PR is quite large, but I'm not sure how to split it into smaller changes. I'm not sure that it can be splitted into smaller atomic changes, since all changes are related. |
I understand why you prefered that option, but I find it very confusing. I agree with Serhiy in that it would be ideal if we can use |
So I tested and ... it didn't work at all :-( The PEP 587 had a flaw which prevented that! I just fixed the implementation to add a "struct_size" field to PyConfig. So it becomes possible to add new fields to PyConfig in Python 3.9, and be ABI compatible with Python 3.8. The fix: https://bugs.python.org/issue38304 |
New update: the whole idea of a stable ABI for PyConfig has been abandoned. We can freely add new fields in Python 3.9 without having to care about backward compatibility. |
I'm no longer interesting to push this feature. The implementation is quite intrusive and @brettcannon didn't like that I passed the "no optimization" flag to so many places. I don't need this feature myself, so I'm not really motivated to fight each individual issue. If someone wants to complete this change, feel free to copy/fork this PR. You can start from https://github.com/python/cpython/pull/13600.patch for example. By the way, this PR was created from an old patch by Yury Selivanov. |
Add -X noopt command line option to disable compiler optimizations.
.noopt.pyc
suffix for .pyc filesif sys.flags.noopt is true.
add c_optimize.
Co-Authored-By: Yury Selivanov yury@magic.io
https://bugs.python.org/issue2506