Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disable specialization for free-threaded build
  • Loading branch information
markshannon committed Jan 10, 2025
commit d342864a1407151bae8d6b93864d298eb884a91f
2 changes: 2 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,11 @@ dummy_func(
* marshalling can intern strings and make them immortal. */
PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg);
value = PyStackRef_FromPyObjectNew(obj);
#ifdef ENABLE_SPECIALIZATION
if (this_instr->op.code == LOAD_CONST) {
this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
}
#endif
}
Comment on lines +292 to +302
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the check for this_instr->op.code == LOAD_CONST?

Also, minor, but maybe a bit more idiomatic with the rest of the bytecode definitions to split the specializing part out and reuse the code for loading the const? I think this would also make LOAD_CONST a viable tier two instruction (which it currently isn't). Though actually tracing through one should be rare, I can think of cases where it might happen.

Suggested change
inst(LOAD_CONST, (-- value)) {
/* We can't do this in the bytecode compiler as
* marshalling can intern strings and make them immortal. */
PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg);
value = PyStackRef_FromPyObjectNew(obj);
#if ENABLE_SPECIALIZATION
if (this_instr->op.code == LOAD_CONST) {
this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
}
#endif
}
specializing op(_SPECIALIZE_LOAD_CONST, (--)) {
/* We can't do this in the bytecode compiler as
* marshalling can intern strings and make them immortal. */
#if ENABLE_SPECIALIZATION
this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
#endif
}
macro(LOAD_CONST) = _SPECIALIZE_LOAD_CONST + LOAD_CONST_MORTAL;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the check for this_instr->op.code == LOAD_CONST?

Instrumentation. The opcode might be INSTRUMENTED_LINE for example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split the specializing part out

The specializing part needs to load the value to test it, so separating out the specialization just duplicates that.


inst(LOAD_CONST_MORTAL, (-- value)) {
Expand Down
2 changes: 2 additions & 0 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.