FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-123958: move assert optimization from codegen to ast_opt by iritkatriel · Pull Request #124143 · python/cpython · GitHub

/ cpython Public

gh-123958: move assert optimization from codegen to ast_opt - #124143

Closed
iritkatriel wants to merge 4 commits into
python:mainfrom
iritkatriel:assert
Closed

gh-123958: move assert optimization from codegen to ast_opt#124143
iritkatriel wants to merge 4 commits into
python:mainfrom
iritkatriel:assert

Conversation

iritkatriel commented Sep 16, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Comment thread Python/codegen.c
if (OPTIMIZATION_LEVEL(c)) {
return SUCCESS;
}
assert(!OPTIMIZATION_LEVEL(c));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Left this here to convince ourselves of correctness. I'll remove it before committing.

Eclips4 self-requested a review September 16, 2024 22:16
Comment thread Python/ast_opt.c
Comment on lines +1035 to +1036
if (state->optimize) {
make_pass(node_);

Eclips4 Sep 17, 2024
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Technically speaking, this is not the removal of the assert statement; it's replacement of assert with pass statement. Is it possible to completely remove the assert node? Or will it break some existing code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pass becomes a NOP, which gets removed later. This is how we get rid of code. However, I did forget to wipe out the location information (a NOP is not removed if it's the only instruction from its line in the source code).

Comment thread Lib/test/test_builtin.py Outdated
Comment thread Lib/test/test_builtin.py Outdated
Comment thread Lib/test/test_builtin.py
if (optimize):
co = compile(source, '?', mode, optimize=optimize)
co_expected = compile('pass', '?', mode, optimize=optimize)
self.assertEqual(list(co.co_lines()), list(co_expected.co_lines()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks like we no longer raise an error in optimized mode if there is an invalid await. That seems wrong and doesn't align with what we decided on in #121637.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If we want to stick with this then we probably can't optimise the assertions in ast_opt.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL