bpo-1875, bpo-32477: Raise SyntaxError in invalid blocks that will be optimized away. by serhiy-storchaka · Pull Request #14116 · python/cpython

@serhiy-storchaka

@serhiy-storchaka

… optimized away.

Also simplify the code generator and peepholer for "if" and "while" with
constant condition.
Also optimize more cases of conditional jumps with constant condition.

pablogsal

Choose a reason for hiding this comment

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

Thanks Serhiy!

I left some minor comments

@@ -0,0 +1,3 @@
A :exc:`SyntaxError` is now always raised if a code blocks that will be

Choose a reason for hiding this comment

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

'if code blocks' or 'if a code block'

@pablogsal

It seems that this is causing some errors with trace functions

pablogsal

Choose a reason for hiding this comment

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

@bedevere-bot

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

pablogsal

}
default:
default: {
if (e->kind == Constant_kind) {

Choose a reason for hiding this comment

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

Shouldn't this be it's on case in the previous switch?

(case Constant_kind: )

Choose a reason for hiding this comment

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

Good point!

@pablogsal

@serhiy-storchaka

No, this PR is not ready yet.

@serhiy-storchaka

@serhiy-storchaka

pablogsal

* constant = 1: "if 1", "if 2", ...
* constant = -1: rest */
if (constant == 0) {
BEGIN_DO_NOT_EMIT_BYTECODE

Choose a reason for hiding this comment

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

You can remove this macro and the attribute in the compiler struct if is not used anymore

@markshannon

This change was implemented as part of PEP 626, so this PR is now obsolete.