diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2022-11-02 15:52:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 15:52:11 (GMT) |
commit | df84b7b0bce36d94e90f368b55c9268d5b641dc9 (patch) | |
tree | 803c24f9e1db569bf1d1b83ca9f73a735773152d | |
parent | 0a806f2684779e35b0b8c78b3a9052e08a301d18 (diff) | |
download | cpython-df84b7b0bce36d94e90f368b55c9268d5b641dc9.zip cpython-df84b7b0bce36d94e90f368b55c9268d5b641dc9.tar.gz cpython-df84b7b0bce36d94e90f368b55c9268d5b641dc9.tar.bz2 |
gh-87092: remove unused SET_LOC/UNSET_LOC macros (GH-98914)
-rw-r--r-- | Python/compile.c | 79 |
1 files changed, 6 insertions, 73 deletions
diff --git a/Python/compile.c b/Python/compile.c index 2ab20a8..bc44bd9 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1001,20 +1001,6 @@ basicblock_next_instr(basicblock *b) 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. @@ -2021,7 +2007,6 @@ compiler_unwind_fblock(struct compiler *c, location *ploc, /* The finally block should appear to execute after the * statement causing the unwinding, so make the unwinding * instruction artificial */ - UNSET_LOC(c); *ploc = NO_LOCATION; return 1; @@ -2039,7 +2024,6 @@ compiler_unwind_fblock(struct compiler *c, location *ploc, case WITH: case ASYNC_WITH: - SET_LOC(c, (stmt_ty)info->fb_datum); *ploc = LOC((stmt_ty)info->fb_datum); ADDOP(c, *ploc, POP_BLOCK); if (preserve_tos) { @@ -2057,7 +2041,6 @@ compiler_unwind_fblock(struct compiler *c, location *ploc, /* The exit block should appear to execute after the * statement causing the unwinding, so make the unwinding * instruction artificial */ - UNSET_LOC(c); *ploc = NO_LOCATION; 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 (c->u->u_scope_type == COMPILER_SCOPE_MODULE && asdl_seq_LEN(stmts)) { st = (stmt_ty)asdl_seq_GET(stmts, 0); - SET_LOC(c, st); loc = LOC(st); } /* 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); assert(st->kind == Expr_kind); VISIT(c, expr, st->v.Expr.value); - UNSET_LOC(c); if (!compiler_nameop(c, NO_LOCATION, &_Py_ID(__doc__), Store)) return 0; } @@ -2316,7 +2297,6 @@ compiler_apply_decorators(struct compiler *c, asdl_expr_seq* decos) return 1; 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)); ADDOP_I(c, loc, CALL, 0); } @@ -2725,7 +2705,6 @@ compiler_class(struct compiler *c, stmt_ty s) return 0; } /* The following code is artificial */ - UNSET_LOC(c); /* Return __classcell__ if it is referenced, otherwise return None */ if (c->u->u_ste->ste_needs_class_closure) { /* 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_SEQ(c, stmt, s->v.For.body); /* Mark jump as artificial */ - UNSET_LOC(c); ADDOP_JUMP(c, NO_LOCATION, JUMP, start); 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_SEQ(c, stmt, s->v.AsyncFor.body); /* Mark jump as artificial */ - UNSET_LOC(c); ADDOP_JUMP(c, NO_LOCATION, JUMP, 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, * as the END_ASYNC_FOR succeeds the `for`, not the body. */ - SET_LOC(c, s->v.AsyncFor.iter); loc = LOC(s->v.AsyncFor.iter); ADDOP(c, loc, END_ASYNC_FOR); @@ -3219,13 +3195,11 @@ compiler_return(struct compiler *c, stmt_ty s) } else { /* Emit instruction with line number for return value */ if (s->v.Return.value != NULL) { - SET_LOC(c, s->v.Return.value); loc = LOC(s->v.Return.value); ADDOP(c, loc, NOP); } } if (s->v.Return.value == NULL || s->v.Return.value->lineno != s->lineno) { - SET_LOC(c, s); loc = LOC(s); ADDOP(c, loc, NOP); } @@ -3352,7 +3326,6 @@ compiler_try_finally(struct compiler *c, stmt_ty s) USE_LABEL(c, end); - UNSET_LOC(c); loc = NO_LOCATION; ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup); ADDOP(c, loc, PUSH_EXC_INFO); @@ -3404,7 +3377,6 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s) /* `finally` block */ USE_LABEL(c, end); - UNSET_LOC(c); loc = NO_LOCATION; ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup); ADDOP(c, loc, PUSH_EXC_INFO); @@ -3480,7 +3452,6 @@ compiler_try_except(struct compiler *c, stmt_ty s) USE_LABEL(c, except); - UNSET_LOC(c); ADDOP_JUMP(c, NO_LOCATION, SETUP_CLEANUP, cleanup); ADDOP(c, NO_LOCATION, PUSH_EXC_INFO); /* 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++) { excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET( s->v.Try.handlers, i); - SET_LOC(c, handler); location loc = LOC(handler); if (!handler->v.ExceptHandler.type && i < n-1) { 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); compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body); /* 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_EXCEPT); @@ -3543,9 +3512,7 @@ compiler_try_except(struct compiler *c, stmt_ty s) /* except: */ USE_LABEL(c, cleanup_end); - /* name = None; del name; # Mark as artificial */ - UNSET_LOC(c); - + /* name = None; del name; # artificial */ 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, Del); @@ -3562,7 +3529,6 @@ compiler_try_except(struct compiler *c, stmt_ty s) return 0; VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body); - UNSET_LOC(c); ADDOP(c, NO_LOCATION, POP_BLOCK); ADDOP(c, NO_LOCATION, POP_EXCEPT); ADDOP_JUMP(c, NO_LOCATION, JUMP, end); @@ -3570,8 +3536,7 @@ compiler_try_except(struct compiler *c, stmt_ty s) USE_LABEL(c, except); } - /* Mark as artificial */ - UNSET_LOC(c); + /* artificial */ compiler_pop_fblock(c, EXCEPTION_HANDLER, NO_LABEL); 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); - UNSET_LOC(c); ADDOP_JUMP(c, NO_LOCATION, SETUP_CLEANUP, cleanup); ADDOP(c, NO_LOCATION, PUSH_EXC_INFO); /* 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++) { excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET( s->v.TryStar.handlers, i); - SET_LOC(c, handler); location loc = LOC(handler); NEW_JUMP_TARGET_LABEL(c, next_except); except = next_except; @@ -3732,8 +3695,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s) /* second # body */ VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body); - /* name = None; del name; # Mark as artificial */ - UNSET_LOC(c); + /* name = None; del name; # artificial */ ADDOP(c, NO_LOCATION, POP_BLOCK); if (handler->v.ExceptHandler.name) { ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None); @@ -3745,9 +3707,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s) /* except: */ USE_LABEL(c, cleanup_end); - /* name = None; del name; # Mark as artificial */ - UNSET_LOC(c); - + /* name = None; del name; # artificial */ if (handler->v.ExceptHandler.name) { ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None); 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); } } - /* Mark as artificial */ - UNSET_LOC(c); + /* artificial */ compiler_pop_fblock(c, EXCEPTION_GROUP_HANDLER, NO_LABEL); 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. */ VISIT(c, expr, meth->v.Attribute.value); - SET_LOC(c, meth); location loc = LOC(meth); loc = update_start_location_to_match_attr(c, loc, meth); 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; }; } - SET_LOC(c, e); - loc = LOC(e); - loc = update_start_location_to_match_attr(c, loc, meth); + loc = update_start_location_to_match_attr(c, LOC(e), meth); ADDOP_I(c, loc, CALL, argsl + kwdsl); 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++) { keyword_ty other = ((keyword_ty)asdl_seq_GET(keywords, j)); if (other->arg && !PyUnicode_Compare(key->arg, other->arg)) { - SET_LOC(c, other); compiler_error(c, LOC(other), "keyword argument repeated: %U", key->arg); return -1; } @@ -4912,10 +4867,8 @@ compiler_call(struct compiler *c, expr_ty e) if (!check_caller(c, e->v.Call.func)) { return 0; } - SET_LOC(c, e->v.Call.func); location loc = LOC(e->v.Call.func); ADDOP(c, loc, PUSH_NULL); - SET_LOC(c, e); VISIT(c, expr, e->v.Call.func); loc = LOC(e); return compiler_call_helper(c, loc, 0, @@ -5442,7 +5395,6 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, { goto error; } - SET_LOC(c, e); location loc = LOC(e); is_async_generator = c->u->u_ste->ste_coroutine; @@ -5582,7 +5534,6 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k) static int compiler_with_except_finish(struct compiler *c, jump_target_label cleanup) { - UNSET_LOC(c); NEW_JUMP_TARGET_LABEL(c, suppress); ADDOP_JUMP(c, NO_LOCATION, POP_JUMP_IF_TRUE, suppress); 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); - SET_LOC(c, s); ADDOP(c, loc, POP_BLOCK); /* 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)) return 0; - - /* Mark all following code as artificial */ - UNSET_LOC(c); ADDOP(c, NO_LOCATION, POP_BLOCK); compiler_pop_fblock(c, WITH, block); @@ -5785,7 +5732,6 @@ compiler_with(struct compiler *c, stmt_ty s, int pos) /* For successful outcome: * call __exit__(None, None, None) */ - SET_LOC(c, s); loc = LOC(s); if (!compiler_call_exit_with_nones(c, loc)) return 0; @@ -5949,7 +5895,6 @@ compiler_visit_expr1(struct compiler *c, expr_ty e) static int compiler_visit_expr(struct compiler *c, expr_ty e) { - SET_LOC(c, e); int res = compiler_visit_expr1(c, e); return res; } @@ -5968,7 +5913,6 @@ compiler_augassign(struct compiler *c, stmt_ty s) expr_ty e = s->v.AugAssign.target; location loc = LOC(e); - SET_LOC(c, e); switch (e->kind) { case Attribute_kind: @@ -6011,7 +5955,6 @@ compiler_augassign(struct compiler *c, stmt_ty s) VISIT(c, expr, s->v.AugAssign.value); ADDOP_INPLACE(c, loc, s->v.AugAssign.op); - SET_LOC(c, e); loc = LOC(e); 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); for (Py_ssize_t i = 0; i < nattrs; 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)); if (forbidden_name(c, loc, attr, Store)) { 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)); if (!PyUnicode_Compare(attr, other)) { 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); return -1; } @@ -6607,7 +6548,6 @@ compiler_pattern_class(struct compiler *c, location *ploc, } if (nattrs) { RETURN_IF_FALSE(!validate_kwd_attrs(c, kwd_attrs, kwd_patterns)); - SET_LOC(c, p); } VISIT(c, expr, p->v.MatchClass.cls); 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 " "(set 'rest' parameter instead)"; 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); 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. for (Py_ssize_t i = 0; i < size; i++) { pattern_ty alt = asdl_seq_GET(p->v.MatchOr.patterns, i); - SET_LOC(c, alt); PyObject *pc_stores = PyList_New(0); if (pc_stores == NULL) { goto error; @@ -7031,7 +6969,6 @@ static int compiler_pattern(struct compiler *c, location *ploc, pattern_ty p, pattern_context *pc) { - SET_LOC(c, p); *ploc = LOC(p); switch (p->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; for (Py_ssize_t i = 0; i < cases - has_default; 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: location loc = LOC(m->pattern); 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 // cleanup to be associated with the failed pattern, not the last line // of the body - SET_LOC(c, m->pattern); RETURN_IF_FALSE(emit_and_reset_fail_pop(c, LOC(m->pattern), pc)); } if (has_default) { // A trailing "case _" is common, and lets us save a bit of redundant // pushing and popping in the loop above: m = asdl_seq_GET(s->v.Match.cases, cases - 1); - SET_LOC(c, m->pattern); location loc = LOC(m->pattern); if (cases == 1) { // 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. */ if (!basicblock_returns(CFG_BUILDER(c)->g_curblock)) { - UNSET_LOC(c); if (addNone) { ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None); } |