From ba7af14f16cdc6063f008823ab572b08bfc151dd Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Thu, 16 Jun 2022 20:24:00 +0800 Subject: [PATCH 1/3] Fix BINARY_SUBSCR stats --- Python/ceval.c | 10 +++++----- Python/specialize.c | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index f9ec640ef1722a..71f16688f667ba 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2242,14 +2242,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PyCodeObject *code = (PyCodeObject *)getitem->func_code; size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE; assert(code->co_argcount == 2); - _PyInterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size); + STAT_INC(BINARY_SUBSCR, hit); + + Py_INCREF(getitem); + _PyInterpreterFrame *new_frame = _PyFrame_Push(tstate, getitem); if (new_frame == NULL) { goto error; } - CALL_STAT_INC(frames_pushed); - Py_INCREF(getitem); - _PyFrame_InitializeSpecials(new_frame, getitem, - NULL, code->co_nlocalsplus); + CALL_STAT_INC(inlined_py_calls); STACK_SHRINK(2); new_frame->localsplus[0] = container; new_frame->localsplus[1] = sub; diff --git a/Python/specialize.c b/Python/specialize.c index a3be97d40dfb5b..a8c725e74e2a80 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1212,7 +1212,8 @@ _Py_Specialize_BinarySubscr( write_u32(cache->type_version, cls->tp_version_tag); int version = _PyFunction_GetVersionForCurrentState(func); if (version == 0 || version != (uint16_t)version) { - SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_VERSIONS); + SPECIALIZATION_FAIL(BINARY_SUBSCR, version == 0 ? + SPEC_FAIL_OUT_OF_VERSIONS: SPEC_FAIL_OUT_OF_RANGE); goto fail; } cache->func_version = version; From 5349d8a3eb1fb7cfafd2c6beba1eb8f90657224e Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Thu, 16 Jun 2022 20:24:46 +0800 Subject: [PATCH 2/3] fix formatting --- Python/specialize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/specialize.c b/Python/specialize.c index a8c725e74e2a80..24fbe2f426cbdf 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1213,7 +1213,7 @@ _Py_Specialize_BinarySubscr( int version = _PyFunction_GetVersionForCurrentState(func); if (version == 0 || version != (uint16_t)version) { SPECIALIZATION_FAIL(BINARY_SUBSCR, version == 0 ? - SPEC_FAIL_OUT_OF_VERSIONS: SPEC_FAIL_OUT_OF_RANGE); + SPEC_FAIL_OUT_OF_VERSIONS : SPEC_FAIL_OUT_OF_RANGE); goto fail; } cache->func_version = version; From 91f7e41dd85b35219dd19b5cf22296eb15fca312 Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Thu, 16 Jun 2022 20:59:32 +0800 Subject: [PATCH 3/3] Remove unused variable --- Python/ceval.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 71f16688f667ba..ca3797c2160945 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2240,7 +2240,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PyFunctionObject *getitem = (PyFunctionObject *)cached; DEOPT_IF(getitem->func_version != cache->func_version, BINARY_SUBSCR); PyCodeObject *code = (PyCodeObject *)getitem->func_code; - size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE; assert(code->co_argcount == 2); STAT_INC(BINARY_SUBSCR, hit);