diff options
author | Yan Yanchii <yyanchiy@gmail.com> | 2025-03-12 21:45:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-12 21:45:54 (GMT) |
commit | 3618240624d98de2a68a79dc174d49efb96cc2e6 (patch) | |
tree | c4a2f6cb72985a0885d8ed99ec2342fd3c6d98a4 /Python/codegen.c | |
parent | b52866953a64c5e0fe57784fbcfc6bec87861563 (diff) | |
download | cpython-3618240624d98de2a68a79dc174d49efb96cc2e6.zip cpython-3618240624d98de2a68a79dc174d49efb96cc2e6.tar.gz cpython-3618240624d98de2a68a79dc174d49efb96cc2e6.tar.bz2 |
gh-126835: Avoid creating unnecessary tuple when looking for constant sequence during constant folding (#131054)
Diffstat (limited to 'Python/codegen.c')
-rw-r--r-- | Python/codegen.c | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/Python/codegen.c b/Python/codegen.c index 9087112..6ef3c63 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -37,15 +37,6 @@ #define COMP_SETCOMP 2 #define COMP_DICTCOMP 3 -/* A soft limit for stack use, to avoid excessive - * memory use for large constants, etc. - * - * The value 30 is plucked out of thin air. - * Code that could use more stack than this is - * rare, so the exact value is unimportant. - */ -#define STACK_USE_GUIDELINE 30 - #undef SUCCESS #undef ERROR #define SUCCESS 0 @@ -3209,7 +3200,7 @@ starunpack_helper_impl(compiler *c, location loc, int build, int add, int extend, int tuple) { Py_ssize_t n = asdl_seq_LEN(elts); - int big = n + pushed + (injected_arg ? 1 : 0) > STACK_USE_GUIDELINE; + int big = n + pushed + (injected_arg ? 1 : 0) > _PY_STACK_USE_GUIDELINE; int seen_star = 0; for (Py_ssize_t i = 0; i < n; i++) { expr_ty elt = asdl_seq_GET(elts, i); @@ -3364,7 +3355,7 @@ static int codegen_subdict(compiler *c, expr_ty e, Py_ssize_t begin, Py_ssize_t end) { Py_ssize_t i, n = end - begin; - int big = n*2 > STACK_USE_GUIDELINE; + int big = n*2 > _PY_STACK_USE_GUIDELINE; location loc = LOC(e); if (big) { ADDOP_I(c, loc, BUILD_MAP, 0); @@ -3411,7 +3402,7 @@ codegen_dict(compiler *c, expr_ty e) ADDOP_I(c, loc, DICT_UPDATE, 1); } else { - if (elements*2 > STACK_USE_GUIDELINE) { + if (elements*2 > _PY_STACK_USE_GUIDELINE) { RETURN_IF_ERROR(codegen_subdict(c, e, i - elements, i + 1)); if (have_dict) { ADDOP_I(c, loc, DICT_UPDATE, 1); @@ -3752,7 +3743,7 @@ maybe_optimize_method_call(compiler *c, expr_ty e) /* Check that there aren't too many arguments */ argsl = asdl_seq_LEN(args); kwdsl = asdl_seq_LEN(kwds); - if (argsl + kwdsl + (kwdsl != 0) >= STACK_USE_GUIDELINE) { + if (argsl + kwdsl + (kwdsl != 0) >= _PY_STACK_USE_GUIDELINE) { return 0; } /* Check that there are no *varargs types of arguments. */ @@ -3849,7 +3840,7 @@ codegen_joined_str(compiler *c, expr_ty e) { location loc = LOC(e); Py_ssize_t value_count = asdl_seq_LEN(e->v.JoinedStr.values); - if (value_count > STACK_USE_GUIDELINE) { + if (value_count > _PY_STACK_USE_GUIDELINE) { _Py_DECLARE_STR(empty, ""); ADDOP_LOAD_CONST_NEW(c, loc, Py_NewRef(&_Py_STR(empty))); ADDOP_NAME(c, loc, LOAD_METHOD, &_Py_ID(join), names); @@ -3928,7 +3919,7 @@ codegen_subkwargs(compiler *c, location loc, Py_ssize_t i, n = end - begin; keyword_ty kw; assert(n > 0); - int big = n*2 > STACK_USE_GUIDELINE; + int big = n*2 > _PY_STACK_USE_GUIDELINE; if (big) { ADDOP_I(c, NO_LOCATION, BUILD_MAP, 0); } @@ -3981,7 +3972,7 @@ codegen_call_helper_impl(compiler *c, location loc, nelts = asdl_seq_LEN(args); nkwelts = asdl_seq_LEN(keywords); - if (nelts + nkwelts*2 > STACK_USE_GUIDELINE) { + if (nelts + nkwelts*2 > _PY_STACK_USE_GUIDELINE) { goto ex_call; } for (i = 0; i < nelts; i++) { |