Skip to content

Commit 3163d9b

Browse files
Fix a bug in dependencies detected by CI
1 parent 33cf287 commit 3163d9b

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

Python/optimizer.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,10 @@ _PyJit_translate_single_bytecode_to_trace(
588588
PyCodeObject *old_code = _tstate->jit_tracer_state.prev_state.instr_code;
589589
bool progress_needed = (_tstate->jit_tracer_state.initial_state.chain_depth % MAX_CHAIN_DEPTH) == 0;
590590
_PyBloomFilter *dependencies = &_tstate->jit_tracer_state.prev_state.dependencies;
591-
_Py_BloomFilter_Add(dependencies, old_code);
591+
// Can be NULL for the entry frame.
592+
if (old_code != NULL) {
593+
_Py_BloomFilter_Add(dependencies, old_code);
594+
}
592595
int trace_length = _tstate->jit_tracer_state.prev_state.code_curr_size;
593596
_PyUOpInstruction *trace = _tstate->jit_tracer_state.code_buffer;
594597
int max_length = _tstate->jit_tracer_state.prev_state.code_max_size;
@@ -1348,17 +1351,7 @@ uop_optimize(
13481351
bool progress_needed)
13491352
{
13501353
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
1351-
// Note: the executor has a slightly different set of dependencies than the tracer.
1352-
// For example: the tracer depends on function and code objects.
1353-
// The executor may only depend on the code object.
1354-
// Furthermore, it may decide to cut the trace early, meaning it does not depend on the rest
1355-
// of the code objects in the trace.
1356-
// It is crucial we differentiate them for performance reasons.
1357-
// This prevents endless re-tracing for nested functions.
1358-
// It is the optimizer's responsibility to add the dependencies it requires on its own.
1359-
_PyBloomFilter new_dependencies;
1360-
_Py_BloomFilter_Init(&new_dependencies);
1361-
_Py_BloomFilter_Add(&new_dependencies, _tstate->jit_tracer_state.initial_state.code);
1354+
_PyBloomFilter *dependencies = &_tstate->jit_tracer_state.prev_state.dependencies;
13621355
_PyUOpInstruction *buffer = _tstate->jit_tracer_state.code_buffer;
13631356
OPT_STAT_INC(attempts);
13641357
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
@@ -1378,7 +1371,7 @@ uop_optimize(
13781371
length = _Py_uop_analyze_and_optimize(
13791372
_tstate->jit_tracer_state.initial_state.func,
13801373
buffer,length,
1381-
curr_stackentries, &new_dependencies);
1374+
curr_stackentries, dependencies);
13821375
if (length <= 0) {
13831376
return length;
13841377
}
@@ -1402,7 +1395,7 @@ uop_optimize(
14021395
length = prepare_for_execution(buffer, length);
14031396
assert(length <= UOP_MAX_TRACE_LENGTH);
14041397
_PyExecutorObject *executor = make_executor_from_uops(
1405-
buffer, length, &new_dependencies, _tstate->jit_tracer_state.initial_state.chain_depth);
1398+
buffer, length, dependencies, _tstate->jit_tracer_state.initial_state.chain_depth);
14061399
if (executor == NULL) {
14071400
return -1;
14081401
}

Python/optimizer_bytecodes.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ dummy_func(void) {
796796
ctx->done = true;
797797
break;
798798
}
799-
_Py_BloomFilter_Add(dependencies, returning_code);
800799
int returning_stacklevel = this_instr->operand1;
801800
if (ctx->curr_frame_depth >= 2) {
802801
PyCodeObject *expected_code = ctx->frames[ctx->curr_frame_depth - 2].code;
@@ -900,8 +899,8 @@ dummy_func(void) {
900899
}
901900
if (!(operand & 1)) {
902901
PyFunctionObject *func = (PyFunctionObject *)operand;
903-
PyCodeObject *co = (PyCodeObject *)func->func_code;
904-
_Py_BloomFilter_Add(dependencies, co);
902+
// No need to re-add to dependencies here. Already
903+
// handled by the tracer.
905904
ctx->frame->func = func;
906905
}
907906
// Fixed calls don't need IP guards.

Python/optimizer_cases.c.h

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)