Skip to content

bpo-37500: Make sure dead code does not generate bytecode but also detect syntax errors #14612

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

Merged
merged 9 commits into from
Jul 15, 2019

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Jul 5, 2019

https://bugs.python.org/issue37500

Add a new field to the compiler structure that allows to be configured
so no bytecode is emitted. In this way is possible to detect errors by
walking the nodes while preserving optimizations.

https://bugs.python.org/issue37500

@pablogsal pablogsal requested a review from tim-one July 5, 2019 22:38
@pablogsal pablogsal changed the title bpo-37500: Revert commit 85ed1712e428f93408f56fc684816f9a85b0ebc0 bpo-37500: Make sure bytecode for always false conditional is not emmited Jul 5, 2019
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Does this change still mark a function as a generator when using "if 0: yield"? Does it still detect syntax errors?

@tim-one
Copy link
Member

tim-one commented Jul 6, 2019

Does this change still mark a function as a generator when using "if 0: yield"?

Victor, test_generators.py has always had a test to make sure that's so - so the test suite will catch that if it breaks.

@pablogsal
Copy link
Member Author

Does this change still mark a function as a generator when using "if 0: yield"? Does it still detect syntax errors?

Yes and yes.

@pablogsal pablogsal self-assigned this Jul 6, 2019
…tted

Add a new field to the compiler structure that allows to be configured
so no bytecode is emitted. In this way is possible to detect errors by
walking the nodes while preserving optimizations.

Add a specific tests for dead blocks being optimized.
@pablogsal pablogsal changed the title bpo-37500: Make sure bytecode for always false conditional is not emmited bpo-37500: Make sure dead code does not generate bytecode Jul 6, 2019
@pablogsal pablogsal changed the title bpo-37500: Make sure dead code does not generate bytecode bpo-37500: Make sure dead code does not generate bytecode but also detect syntax errors Jul 6, 2019
@pablogsal
Copy link
Member Author

I have updated the PR adding more tests

@bedevere-bot
Copy link

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

I am not sure that this is the best way, at least it is not simple, so I suggest to wait with its merging until we try other approaches.

* while visiting nodes.
*/

#define BEGIN_DO_NOT_EMIT_BYTECODE { \
Copy link
Member

Choose a reason for hiding this comment

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

BEGIN_DO_NOT_EMIT_BYTECODE and END_DO_NOT_EMIT_BYTECODE always surround VISIT_SEQ. I would add a new macros which expands to

c->c_do_not_emit_bytecode++;
VISIT_SEQ(...);
c->c_do_not_emit_bytecode--;

instead of BEGIN_DO_NOT_EMIT_BYTECODE and END_DO_NOT_EMIT_BYTECODE.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will update the PR soon.

@pablogsal
Copy link
Member Author

so I suggest to wait with its merging until we try other approaches.

If you think there are better ways, I am happy to try them out :)

@serhiy-storchaka Could you elaborate a bit more what you don't like about this approach?

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM. I dislike the macros, but you keep them if you prefer.

This change looks like a nice way to fix https://bugs.python.org/issue37500

@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 15, 2019
…tect syntax errors (pythonGH-14612)

https://bugs.python.org/issue37500

Add a new field to the compiler structure that allows to be configured
so no bytecode is emitted. In this way is possible to detect errors by
walking the nodes while preserving optimizations.

https://bugs.python.org/issue37500
(cherry picked from commit 18c5f9d)

Co-authored-by: Pablo Galindo <[email protected]>
@bedevere-bot
Copy link

GH-14780 is a backport of this pull request to the 3.8 branch.

@vstinner
Copy link
Member

Oh, I didn't want to merge directly the change, only say that it LGTM. I didn't want to merge it since @serhiy-storchaka seems to want to experiment another approach (that he didn't mention). I dislike automerge :-(

@vstinner
Copy link
Member

I closed the 3.8 backport (without merging it), until we agree on what should be done.

@vstinner
Copy link
Member

I am not sure that this is the best way, at least it is not simple, so I suggest to wait with its merging until we try other approaches.

@serhiy-storchaka: Would you mind to elaborate why you consider that this change is "not simple"? It sounds like a simple and working solution to me. It don't see how we can produce SyntaxError without this approach (visit all nodes even the ones that we remove).

@markshannon
Copy link
Member

I see no reason not to merge this into 3.8.
We need to fix https://bugs.python.org/issue37500 and I can't envisage any simpler fix.
Longer term we will want to improve the compiler, but that would be too big a change for 3.8.
@vstinner any objections to reopening #14780?

@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-15002 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 29, 2019
…tect syntax errors (pythonGH-14612)

https://bugs.python.org/issue37500

Add a new field to the compiler structure that allows to be configured
so no bytecode is emitted. In this way is possible to detect errors by
walking the nodes while preserving optimizations.

https://bugs.python.org/issue37500
(cherry picked from commit 18c5f9d)

Co-authored-by: Pablo Galindo <[email protected]>
@pablogsal
Copy link
Member Author

pablogsal commented Jul 29, 2019

I am going to reopen the backport to 3.8 as I think is very important to test this before b4 so we can react accordingly if something goes wrong. If we discover a better version to do this, we can always backport it on top, but I think is very important to give the solution some exposure before the release candidates and the last beta.

I will keep investigating for better solutions and maybe will do some refactors with some of the proposed ideas (like creating a wrapper for VISIT_SEQ instead).

miss-islington added a commit that referenced this pull request Jul 29, 2019
…tect syntax errors (GH-14612)

https://bugs.python.org/issue37500

Add a new field to the compiler structure that allows to be configured
so no bytecode is emitted. In this way is possible to detect errors by
walking the nodes while preserving optimizations.

https://bugs.python.org/issue37500
(cherry picked from commit 18c5f9d)

Co-authored-by: Pablo Galindo <[email protected]>
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
…tect syntax errors (pythonGH-14612)

https://bugs.python.org/issue37500

Add a new field to the compiler structure that allows to be configured
so no bytecode is emitted. In this way is possible to detect errors by
walking the nodes while preserving optimizations.


https://bugs.python.org/issue37500
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
…tect syntax errors (pythonGH-14612)

https://bugs.python.org/issue37500

Add a new field to the compiler structure that allows to be configured
so no bytecode is emitted. In this way is possible to detect errors by
walking the nodes while preserving optimizations.


https://bugs.python.org/issue37500
@pablogsal pablogsal deleted the fix_opt2 branch May 19, 2021 18:57
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.

8 participants