Skip to content

LOAD_CONST_IMMORTAL #584

@markshannon

Description

@markshannon

Constants are, um, constant. So if the argument of LOAD_CONST is immortal is will always be immortal.

We could add a specialization of LOAD_CONST, LOAD_CONST_IMMORTAL, which doesn't do any refcount modification.

The neatest way to do this would be in the compiler, but it can be done at runtime:

inst(LOAD_CONST, (-- value)) {
    value = GETITEM(frame->f_code->co_consts, oparg);
    if (_Py_IsImmortal(value)) {
        next_instr[-1].op.code = LOAD_CONST_IMMORTAL;
    }
    else {
        Py_INCREF_UNCONDITIONAL(value);
    }
}

A LOAD_CONST_MORTAL specialization is not possible, as PEP 683 allows mortal object to become immortal.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions