gh-87092: remove unused SET_LOC/UNSET_LOC macros (GH-98914)

This commit is contained in:
Irit Katriel 2022-11-02 15:52:11 +00:00 committed by GitHub
parent 0a806f2684
commit df84b7b0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 73 deletions

View File

@ -1001,20 +1001,6 @@ basicblock_next_instr(basicblock *b)
return b->b_iused++; return b->b_iused++;
} }
/* Set the line number and column offset for the following instructions.
The line number is reset in the following cases:
- when entering a new scope
- on each statement
- on each expression and sub-expression
- before the "except" and "finally" clauses
*/
#define SET_LOC(c, x)
// Artificial instructions
#define UNSET_LOC(c)
/* Return the stack effect of opcode with argument oparg. /* Return the stack effect of opcode with argument oparg.
@ -2021,7 +2007,6 @@ compiler_unwind_fblock(struct compiler *c, location *ploc,
/* The finally block should appear to execute after the /* The finally block should appear to execute after the
* statement causing the unwinding, so make the unwinding * statement causing the unwinding, so make the unwinding
* instruction artificial */ * instruction artificial */
UNSET_LOC(c);
*ploc = NO_LOCATION; *ploc = NO_LOCATION;
return 1; return 1;
@ -2039,7 +2024,6 @@ compiler_unwind_fblock(struct compiler *c, location *ploc,
case WITH: case WITH:
case ASYNC_WITH: case ASYNC_WITH:
SET_LOC(c, (stmt_ty)info->fb_datum);
*ploc = LOC((stmt_ty)info->fb_datum); *ploc = LOC((stmt_ty)info->fb_datum);
ADDOP(c, *ploc, POP_BLOCK); ADDOP(c, *ploc, POP_BLOCK);
if (preserve_tos) { if (preserve_tos) {
@ -2057,7 +2041,6 @@ compiler_unwind_fblock(struct compiler *c, location *ploc,
/* The exit block should appear to execute after the /* The exit block should appear to execute after the
* statement causing the unwinding, so make the unwinding * statement causing the unwinding, so make the unwinding
* instruction artificial */ * instruction artificial */
UNSET_LOC(c);
*ploc = NO_LOCATION; *ploc = NO_LOCATION;
return 1; return 1;
@ -2134,7 +2117,6 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
If body is empty, then lineno will be set later in assemble. */ If body is empty, then lineno will be set later in assemble. */
if (c->u->u_scope_type == COMPILER_SCOPE_MODULE && asdl_seq_LEN(stmts)) { if (c->u->u_scope_type == COMPILER_SCOPE_MODULE && asdl_seq_LEN(stmts)) {
st = (stmt_ty)asdl_seq_GET(stmts, 0); st = (stmt_ty)asdl_seq_GET(stmts, 0);
SET_LOC(c, st);
loc = LOC(st); loc = LOC(st);
} }
/* Every annotated class and module should have __annotations__. */ /* Every annotated class and module should have __annotations__. */
@ -2151,7 +2133,6 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
st = (stmt_ty)asdl_seq_GET(stmts, 0); st = (stmt_ty)asdl_seq_GET(stmts, 0);
assert(st->kind == Expr_kind); assert(st->kind == Expr_kind);
VISIT(c, expr, st->v.Expr.value); VISIT(c, expr, st->v.Expr.value);
UNSET_LOC(c);
if (!compiler_nameop(c, NO_LOCATION, &_Py_ID(__doc__), Store)) if (!compiler_nameop(c, NO_LOCATION, &_Py_ID(__doc__), Store))
return 0; return 0;
} }
@ -2316,7 +2297,6 @@ compiler_apply_decorators(struct compiler *c, asdl_expr_seq* decos)
return 1; return 1;
for (Py_ssize_t i = asdl_seq_LEN(decos) - 1; i > -1; i--) { for (Py_ssize_t i = asdl_seq_LEN(decos) - 1; i > -1; i--) {
SET_LOC(c, (expr_ty)asdl_seq_GET(decos, i));
location loc = LOC((expr_ty)asdl_seq_GET(decos, i)); location loc = LOC((expr_ty)asdl_seq_GET(decos, i));
ADDOP_I(c, loc, CALL, 0); ADDOP_I(c, loc, CALL, 0);
} }
@ -2725,7 +2705,6 @@ compiler_class(struct compiler *c, stmt_ty s)
return 0; return 0;
} }
/* The following code is artificial */ /* The following code is artificial */
UNSET_LOC(c);
/* Return __classcell__ if it is referenced, otherwise return None */ /* Return __classcell__ if it is referenced, otherwise return None */
if (c->u->u_ste->ste_needs_class_closure) { if (c->u->u_ste->ste_needs_class_closure) {
/* Store __classcell__ into class namespace & return it */ /* Store __classcell__ into class namespace & return it */
@ -3098,7 +3077,6 @@ compiler_for(struct compiler *c, stmt_ty s)
VISIT(c, expr, s->v.For.target); VISIT(c, expr, s->v.For.target);
VISIT_SEQ(c, stmt, s->v.For.body); VISIT_SEQ(c, stmt, s->v.For.body);
/* Mark jump as artificial */ /* Mark jump as artificial */
UNSET_LOC(c);
ADDOP_JUMP(c, NO_LOCATION, JUMP, start); ADDOP_JUMP(c, NO_LOCATION, JUMP, start);
USE_LABEL(c, cleanup); USE_LABEL(c, cleanup);
@ -3145,7 +3123,6 @@ compiler_async_for(struct compiler *c, stmt_ty s)
VISIT(c, expr, s->v.AsyncFor.target); VISIT(c, expr, s->v.AsyncFor.target);
VISIT_SEQ(c, stmt, s->v.AsyncFor.body); VISIT_SEQ(c, stmt, s->v.AsyncFor.body);
/* Mark jump as artificial */ /* Mark jump as artificial */
UNSET_LOC(c);
ADDOP_JUMP(c, NO_LOCATION, JUMP, start); ADDOP_JUMP(c, NO_LOCATION, JUMP, start);
compiler_pop_fblock(c, FOR_LOOP, start); compiler_pop_fblock(c, FOR_LOOP, start);
@ -3155,7 +3132,6 @@ compiler_async_for(struct compiler *c, stmt_ty s)
/* Use same line number as the iterator, /* Use same line number as the iterator,
* as the END_ASYNC_FOR succeeds the `for`, not the body. */ * as the END_ASYNC_FOR succeeds the `for`, not the body. */
SET_LOC(c, s->v.AsyncFor.iter);
loc = LOC(s->v.AsyncFor.iter); loc = LOC(s->v.AsyncFor.iter);
ADDOP(c, loc, END_ASYNC_FOR); ADDOP(c, loc, END_ASYNC_FOR);
@ -3219,13 +3195,11 @@ compiler_return(struct compiler *c, stmt_ty s)
} else { } else {
/* Emit instruction with line number for return value */ /* Emit instruction with line number for return value */
if (s->v.Return.value != NULL) { if (s->v.Return.value != NULL) {
SET_LOC(c, s->v.Return.value);
loc = LOC(s->v.Return.value); loc = LOC(s->v.Return.value);
ADDOP(c, loc, NOP); ADDOP(c, loc, NOP);
} }
} }
if (s->v.Return.value == NULL || s->v.Return.value->lineno != s->lineno) { if (s->v.Return.value == NULL || s->v.Return.value->lineno != s->lineno) {
SET_LOC(c, s);
loc = LOC(s); loc = LOC(s);
ADDOP(c, loc, NOP); ADDOP(c, loc, NOP);
} }
@ -3352,7 +3326,6 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
USE_LABEL(c, end); USE_LABEL(c, end);
UNSET_LOC(c);
loc = NO_LOCATION; loc = NO_LOCATION;
ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup); ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup);
ADDOP(c, loc, PUSH_EXC_INFO); ADDOP(c, loc, PUSH_EXC_INFO);
@ -3404,7 +3377,6 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s)
/* `finally` block */ /* `finally` block */
USE_LABEL(c, end); USE_LABEL(c, end);
UNSET_LOC(c);
loc = NO_LOCATION; loc = NO_LOCATION;
ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup); ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup);
ADDOP(c, loc, PUSH_EXC_INFO); ADDOP(c, loc, PUSH_EXC_INFO);
@ -3480,7 +3452,6 @@ compiler_try_except(struct compiler *c, stmt_ty s)
USE_LABEL(c, except); USE_LABEL(c, except);
UNSET_LOC(c);
ADDOP_JUMP(c, NO_LOCATION, SETUP_CLEANUP, cleanup); ADDOP_JUMP(c, NO_LOCATION, SETUP_CLEANUP, cleanup);
ADDOP(c, NO_LOCATION, PUSH_EXC_INFO); ADDOP(c, NO_LOCATION, PUSH_EXC_INFO);
/* Runtime will push a block here, so we need to account for that */ /* Runtime will push a block here, so we need to account for that */
@ -3489,7 +3460,6 @@ compiler_try_except(struct compiler *c, stmt_ty s)
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET( excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET(
s->v.Try.handlers, i); s->v.Try.handlers, i);
SET_LOC(c, handler);
location loc = LOC(handler); location loc = LOC(handler);
if (!handler->v.ExceptHandler.type && i < n-1) { if (!handler->v.ExceptHandler.type && i < n-1) {
return compiler_error(c, loc, "default 'except:' must be last"); return compiler_error(c, loc, "default 'except:' must be last");
@ -3531,7 +3501,6 @@ compiler_try_except(struct compiler *c, stmt_ty s)
VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body); compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
/* name = None; del name; # Mark as artificial */ /* name = None; del name; # Mark as artificial */
UNSET_LOC(c);
ADDOP(c, NO_LOCATION, POP_BLOCK); ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP(c, NO_LOCATION, POP_BLOCK); ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP(c, NO_LOCATION, POP_EXCEPT); ADDOP(c, NO_LOCATION, POP_EXCEPT);
@ -3543,9 +3512,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
/* except: */ /* except: */
USE_LABEL(c, cleanup_end); USE_LABEL(c, cleanup_end);
/* name = None; del name; # Mark as artificial */ /* name = None; del name; # artificial */
UNSET_LOC(c);
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None); ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store); compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store);
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del); compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del);
@ -3562,7 +3529,6 @@ compiler_try_except(struct compiler *c, stmt_ty s)
return 0; return 0;
VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body); compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
UNSET_LOC(c);
ADDOP(c, NO_LOCATION, POP_BLOCK); ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP(c, NO_LOCATION, POP_EXCEPT); ADDOP(c, NO_LOCATION, POP_EXCEPT);
ADDOP_JUMP(c, NO_LOCATION, JUMP, end); ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
@ -3570,8 +3536,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
USE_LABEL(c, except); USE_LABEL(c, except);
} }
/* Mark as artificial */ /* artificial */
UNSET_LOC(c);
compiler_pop_fblock(c, EXCEPTION_HANDLER, NO_LABEL); compiler_pop_fblock(c, EXCEPTION_HANDLER, NO_LABEL);
ADDOP_I(c, NO_LOCATION, RERAISE, 0); ADDOP_I(c, NO_LOCATION, RERAISE, 0);
@ -3657,7 +3622,6 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
USE_LABEL(c, except); USE_LABEL(c, except);
UNSET_LOC(c);
ADDOP_JUMP(c, NO_LOCATION, SETUP_CLEANUP, cleanup); ADDOP_JUMP(c, NO_LOCATION, SETUP_CLEANUP, cleanup);
ADDOP(c, NO_LOCATION, PUSH_EXC_INFO); ADDOP(c, NO_LOCATION, PUSH_EXC_INFO);
/* Runtime will push a block here, so we need to account for that */ /* Runtime will push a block here, so we need to account for that */
@ -3668,7 +3632,6 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
for (Py_ssize_t i = 0; i < n; i++) { for (Py_ssize_t i = 0; i < n; i++) {
excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET( excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET(
s->v.TryStar.handlers, i); s->v.TryStar.handlers, i);
SET_LOC(c, handler);
location loc = LOC(handler); location loc = LOC(handler);
NEW_JUMP_TARGET_LABEL(c, next_except); NEW_JUMP_TARGET_LABEL(c, next_except);
except = next_except; except = next_except;
@ -3732,8 +3695,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
/* second # body */ /* second # body */
VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body); compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
/* name = None; del name; # Mark as artificial */ /* name = None; del name; # artificial */
UNSET_LOC(c);
ADDOP(c, NO_LOCATION, POP_BLOCK); ADDOP(c, NO_LOCATION, POP_BLOCK);
if (handler->v.ExceptHandler.name) { if (handler->v.ExceptHandler.name) {
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None); ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
@ -3745,9 +3707,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
/* except: */ /* except: */
USE_LABEL(c, cleanup_end); USE_LABEL(c, cleanup_end);
/* name = None; del name; # Mark as artificial */ /* name = None; del name; # artificial */
UNSET_LOC(c);
if (handler->v.ExceptHandler.name) { if (handler->v.ExceptHandler.name) {
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None); ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store); compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store);
@ -3767,8 +3727,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
ADDOP_JUMP(c, NO_LOCATION, JUMP, reraise_star); ADDOP_JUMP(c, NO_LOCATION, JUMP, reraise_star);
} }
} }
/* Mark as artificial */ /* artificial */
UNSET_LOC(c);
compiler_pop_fblock(c, EXCEPTION_GROUP_HANDLER, NO_LABEL); compiler_pop_fblock(c, EXCEPTION_GROUP_HANDLER, NO_LABEL);
NEW_JUMP_TARGET_LABEL(c, reraise); NEW_JUMP_TARGET_LABEL(c, reraise);
@ -4855,7 +4814,6 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
} }
/* Alright, we can optimize the code. */ /* Alright, we can optimize the code. */
VISIT(c, expr, meth->v.Attribute.value); VISIT(c, expr, meth->v.Attribute.value);
SET_LOC(c, meth);
location loc = LOC(meth); location loc = LOC(meth);
loc = update_start_location_to_match_attr(c, loc, meth); loc = update_start_location_to_match_attr(c, loc, meth);
ADDOP_NAME(c, loc, LOAD_METHOD, meth->v.Attribute.attr, names); ADDOP_NAME(c, loc, LOAD_METHOD, meth->v.Attribute.attr, names);
@ -4867,9 +4825,7 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
return 0; return 0;
}; };
} }
SET_LOC(c, e); loc = update_start_location_to_match_attr(c, LOC(e), meth);
loc = LOC(e);
loc = update_start_location_to_match_attr(c, loc, meth);
ADDOP_I(c, loc, CALL, argsl + kwdsl); ADDOP_I(c, loc, CALL, argsl + kwdsl);
return 1; return 1;
} }
@ -4890,7 +4846,6 @@ validate_keywords(struct compiler *c, asdl_keyword_seq *keywords)
for (Py_ssize_t j = i + 1; j < nkeywords; j++) { for (Py_ssize_t j = i + 1; j < nkeywords; j++) {
keyword_ty other = ((keyword_ty)asdl_seq_GET(keywords, j)); keyword_ty other = ((keyword_ty)asdl_seq_GET(keywords, j));
if (other->arg && !PyUnicode_Compare(key->arg, other->arg)) { if (other->arg && !PyUnicode_Compare(key->arg, other->arg)) {
SET_LOC(c, other);
compiler_error(c, LOC(other), "keyword argument repeated: %U", key->arg); compiler_error(c, LOC(other), "keyword argument repeated: %U", key->arg);
return -1; return -1;
} }
@ -4912,10 +4867,8 @@ compiler_call(struct compiler *c, expr_ty e)
if (!check_caller(c, e->v.Call.func)) { if (!check_caller(c, e->v.Call.func)) {
return 0; return 0;
} }
SET_LOC(c, e->v.Call.func);
location loc = LOC(e->v.Call.func); location loc = LOC(e->v.Call.func);
ADDOP(c, loc, PUSH_NULL); ADDOP(c, loc, PUSH_NULL);
SET_LOC(c, e);
VISIT(c, expr, e->v.Call.func); VISIT(c, expr, e->v.Call.func);
loc = LOC(e); loc = LOC(e);
return compiler_call_helper(c, loc, 0, return compiler_call_helper(c, loc, 0,
@ -5442,7 +5395,6 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
{ {
goto error; goto error;
} }
SET_LOC(c, e);
location loc = LOC(e); location loc = LOC(e);
is_async_generator = c->u->u_ste->ste_coroutine; is_async_generator = c->u->u_ste->ste_coroutine;
@ -5582,7 +5534,6 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k)
static int static int
compiler_with_except_finish(struct compiler *c, jump_target_label cleanup) { compiler_with_except_finish(struct compiler *c, jump_target_label cleanup) {
UNSET_LOC(c);
NEW_JUMP_TARGET_LABEL(c, suppress); NEW_JUMP_TARGET_LABEL(c, suppress);
ADDOP_JUMP(c, NO_LOCATION, POP_JUMP_IF_TRUE, suppress); ADDOP_JUMP(c, NO_LOCATION, POP_JUMP_IF_TRUE, suppress);
ADDOP_I(c, NO_LOCATION, RERAISE, 2); ADDOP_I(c, NO_LOCATION, RERAISE, 2);
@ -5680,7 +5631,6 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
compiler_pop_fblock(c, ASYNC_WITH, block); compiler_pop_fblock(c, ASYNC_WITH, block);
SET_LOC(c, s);
ADDOP(c, loc, POP_BLOCK); ADDOP(c, loc, POP_BLOCK);
/* End of body; start the cleanup */ /* End of body; start the cleanup */
@ -5774,9 +5724,6 @@ compiler_with(struct compiler *c, stmt_ty s, int pos)
else if (!compiler_with(c, s, pos)) else if (!compiler_with(c, s, pos))
return 0; return 0;
/* Mark all following code as artificial */
UNSET_LOC(c);
ADDOP(c, NO_LOCATION, POP_BLOCK); ADDOP(c, NO_LOCATION, POP_BLOCK);
compiler_pop_fblock(c, WITH, block); compiler_pop_fblock(c, WITH, block);
@ -5785,7 +5732,6 @@ compiler_with(struct compiler *c, stmt_ty s, int pos)
/* For successful outcome: /* For successful outcome:
* call __exit__(None, None, None) * call __exit__(None, None, None)
*/ */
SET_LOC(c, s);
loc = LOC(s); loc = LOC(s);
if (!compiler_call_exit_with_nones(c, loc)) if (!compiler_call_exit_with_nones(c, loc))
return 0; return 0;
@ -5949,7 +5895,6 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
static int static int
compiler_visit_expr(struct compiler *c, expr_ty e) compiler_visit_expr(struct compiler *c, expr_ty e)
{ {
SET_LOC(c, e);
int res = compiler_visit_expr1(c, e); int res = compiler_visit_expr1(c, e);
return res; return res;
} }
@ -5968,7 +5913,6 @@ compiler_augassign(struct compiler *c, stmt_ty s)
expr_ty e = s->v.AugAssign.target; expr_ty e = s->v.AugAssign.target;
location loc = LOC(e); location loc = LOC(e);
SET_LOC(c, e);
switch (e->kind) { switch (e->kind) {
case Attribute_kind: case Attribute_kind:
@ -6011,7 +5955,6 @@ compiler_augassign(struct compiler *c, stmt_ty s)
VISIT(c, expr, s->v.AugAssign.value); VISIT(c, expr, s->v.AugAssign.value);
ADDOP_INPLACE(c, loc, s->v.AugAssign.op); ADDOP_INPLACE(c, loc, s->v.AugAssign.op);
SET_LOC(c, e);
loc = LOC(e); loc = LOC(e);
switch (e->kind) { switch (e->kind) {
@ -6566,7 +6509,6 @@ validate_kwd_attrs(struct compiler *c, asdl_identifier_seq *attrs, asdl_pattern_
Py_ssize_t nattrs = asdl_seq_LEN(attrs); Py_ssize_t nattrs = asdl_seq_LEN(attrs);
for (Py_ssize_t i = 0; i < nattrs; i++) { for (Py_ssize_t i = 0; i < nattrs; i++) {
identifier attr = ((identifier)asdl_seq_GET(attrs, i)); identifier attr = ((identifier)asdl_seq_GET(attrs, i));
SET_LOC(c, ((pattern_ty) asdl_seq_GET(patterns, i)));
location loc = LOC((pattern_ty) asdl_seq_GET(patterns, i)); location loc = LOC((pattern_ty) asdl_seq_GET(patterns, i));
if (forbidden_name(c, loc, attr, Store)) { if (forbidden_name(c, loc, attr, Store)) {
return -1; return -1;
@ -6575,7 +6517,6 @@ validate_kwd_attrs(struct compiler *c, asdl_identifier_seq *attrs, asdl_pattern_
identifier other = ((identifier)asdl_seq_GET(attrs, j)); identifier other = ((identifier)asdl_seq_GET(attrs, j));
if (!PyUnicode_Compare(attr, other)) { if (!PyUnicode_Compare(attr, other)) {
location loc = LOC((pattern_ty) asdl_seq_GET(patterns, j)); location loc = LOC((pattern_ty) asdl_seq_GET(patterns, j));
SET_LOC(c, ((pattern_ty) asdl_seq_GET(patterns, j)));
compiler_error(c, loc, "attribute name repeated in class pattern: %U", attr); compiler_error(c, loc, "attribute name repeated in class pattern: %U", attr);
return -1; return -1;
} }
@ -6607,7 +6548,6 @@ compiler_pattern_class(struct compiler *c, location *ploc,
} }
if (nattrs) { if (nattrs) {
RETURN_IF_FALSE(!validate_kwd_attrs(c, kwd_attrs, kwd_patterns)); RETURN_IF_FALSE(!validate_kwd_attrs(c, kwd_attrs, kwd_patterns));
SET_LOC(c, p);
} }
VISIT(c, expr, p->v.MatchClass.cls); VISIT(c, expr, p->v.MatchClass.cls);
PyObject *attr_names; PyObject *attr_names;
@ -6704,7 +6644,6 @@ compiler_pattern_mapping(struct compiler *c, location *ploc,
const char *e = "can't use NULL keys in MatchMapping " const char *e = "can't use NULL keys in MatchMapping "
"(set 'rest' parameter instead)"; "(set 'rest' parameter instead)";
location loc = LOC((pattern_ty) asdl_seq_GET(patterns, i)); location loc = LOC((pattern_ty) asdl_seq_GET(patterns, i));
SET_LOC(c, (pattern_ty) asdl_seq_GET(patterns, i));
compiler_error(c, loc, e); compiler_error(c, loc, e);
goto error; goto error;
} }
@ -6804,7 +6743,6 @@ compiler_pattern_or(struct compiler *c, location *ploc,
// NOTE: We can't use returning macros anymore! goto error on error. // NOTE: We can't use returning macros anymore! goto error on error.
for (Py_ssize_t i = 0; i < size; i++) { for (Py_ssize_t i = 0; i < size; i++) {
pattern_ty alt = asdl_seq_GET(p->v.MatchOr.patterns, i); pattern_ty alt = asdl_seq_GET(p->v.MatchOr.patterns, i);
SET_LOC(c, alt);
PyObject *pc_stores = PyList_New(0); PyObject *pc_stores = PyList_New(0);
if (pc_stores == NULL) { if (pc_stores == NULL) {
goto error; goto error;
@ -7031,7 +6969,6 @@ static int
compiler_pattern(struct compiler *c, location *ploc, compiler_pattern(struct compiler *c, location *ploc,
pattern_ty p, pattern_context *pc) pattern_ty p, pattern_context *pc)
{ {
SET_LOC(c, p);
*ploc = LOC(p); *ploc = LOC(p);
switch (p->kind) { switch (p->kind) {
case MatchValue_kind: case MatchValue_kind:
@ -7068,7 +7005,6 @@ compiler_match_inner(struct compiler *c, stmt_ty s, pattern_context *pc)
int has_default = WILDCARD_CHECK(m->pattern) && 1 < cases; int has_default = WILDCARD_CHECK(m->pattern) && 1 < cases;
for (Py_ssize_t i = 0; i < cases - has_default; i++) { for (Py_ssize_t i = 0; i < cases - has_default; i++) {
m = asdl_seq_GET(s->v.Match.cases, i); m = asdl_seq_GET(s->v.Match.cases, i);
SET_LOC(c, m->pattern);
// Only copy the subject if we're *not* on the last case: // Only copy the subject if we're *not* on the last case:
location loc = LOC(m->pattern); location loc = LOC(m->pattern);
if (i != cases - has_default - 1) { if (i != cases - has_default - 1) {
@ -7110,14 +7046,12 @@ compiler_match_inner(struct compiler *c, stmt_ty s, pattern_context *pc)
// If the pattern fails to match, we want the line number of the // If the pattern fails to match, we want the line number of the
// cleanup to be associated with the failed pattern, not the last line // cleanup to be associated with the failed pattern, not the last line
// of the body // of the body
SET_LOC(c, m->pattern);
RETURN_IF_FALSE(emit_and_reset_fail_pop(c, LOC(m->pattern), pc)); RETURN_IF_FALSE(emit_and_reset_fail_pop(c, LOC(m->pattern), pc));
} }
if (has_default) { if (has_default) {
// A trailing "case _" is common, and lets us save a bit of redundant // A trailing "case _" is common, and lets us save a bit of redundant
// pushing and popping in the loop above: // pushing and popping in the loop above:
m = asdl_seq_GET(s->v.Match.cases, cases - 1); m = asdl_seq_GET(s->v.Match.cases, cases - 1);
SET_LOC(c, m->pattern);
location loc = LOC(m->pattern); location loc = LOC(m->pattern);
if (cases == 1) { if (cases == 1) {
// No matches. Done with the subject: // No matches. Done with the subject:
@ -8787,7 +8721,6 @@ assemble(struct compiler *c, int addNone)
/* Make sure every block that falls off the end returns None. */ /* Make sure every block that falls off the end returns None. */
if (!basicblock_returns(CFG_BUILDER(c)->g_curblock)) { if (!basicblock_returns(CFG_BUILDER(c)->g_curblock)) {
UNSET_LOC(c);
if (addNone) { if (addNone) {
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None); ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
} }