python / python/cpython

Redundant stack spills on subsequent escaping calls separated by comments

Open
#128,760 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Tier 1 case generator emits stack spill for every subsequent escaping call, when subsequent escaping calls are separated by comment(s). Example:

Subsequent escaping calls without comments in between:

Bytecode definition:

pure inst(NOP, (--)) {
    escaping_call1();
    escaping_call2();
    escaping_call3();
}

Generated case:

TARGET(NOP) {
    frame->instr_ptr = next_instr;
    next_instr += 1;
    INSTRUCTION_STATS(NOP);
    _PyFrame_SetStackPointer(frame, stack_pointer);
    escaping_call1();
    escaping_call2();
    escaping_call3();
    stack_pointer = _PyFrame_GetStackPointer(frame);
    DISPATCH();
}
Subsequent escaping calls with comments in between:

Bytecode definition:

pure inst(NOP, (--)) {
    escaping_call1();
    // comment1
    escaping_call2();
    // comment2
    escaping_call3();
}

Generated case:

TARGET(NOP) {
    frame->instr_ptr = next_instr;
    next_instr += 1;
    INSTRUCTION_STATS(NOP);
    _PyFrame_SetStackPointer(frame, stack_pointer);
    escaping_call1();
    stack_pointer = _PyFrame_GetStackPointer(frame);
    // comment1
    _PyFrame_SetStackPointer(frame, stack_pointer);
    escaping_call2();
    stack_pointer = _PyFrame_GetStackPointer(frame);
    // comment2
    _PyFrame_SetStackPointer(frame, stack_pointer);
    escaping_call3();
    stack_pointer = _PyFrame_GetStackPointer(frame);
    DISPATCH();
}
CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-128761

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Tier 1 case generator and the bytecode definition shown in the report, then review linked PR gh-128761 for the current work. Reproduce the examples with comments between escaping calls and verify that the generated case emits only the necessary stack-pointer operations.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.