gh-92228: disable the compiler's 'small exit block inlining' optimization for blocks that have a line number (GH-94592)

Inlining of code that corresponds to source code lines, can make it hard to distinguish later between code which is only reachable from except handlers, and that which is reachable in normal control flow. This caused problems with the debugger's jump feature.

This PR turns off the inlining optimisation for code which has line numbers. We still inline things like the implicit "return None".
This commit is contained in:
Irit Katriel 2022-07-07 07:38:36 +01:00 committed by GitHub
parent 94988603f3
commit bde06e1b83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 20 deletions

View file

@ -9224,6 +9224,16 @@ error:
return -1;
}
static bool
basicblock_has_lineno(const basicblock *bb) {
for (int i = 0; i < bb->b_iused; i++) {
if (bb->b_instr[i].i_loc.lineno > 0) {
return true;
}
}
return false;
}
/* If this block ends with an unconditional jump to an exit block,
* then remove the jump and extend this block with the target.
*/
@ -9240,6 +9250,10 @@ extend_block(basicblock *bb) {
}
if (basicblock_exits_scope(last->i_target) && last->i_target->b_iused <= MAX_COPY_SIZE) {
basicblock *to_copy = last->i_target;
if (basicblock_has_lineno(to_copy)) {
/* copy only blocks without line number (like implicit 'return None's) */
return 0;
}
last->i_opcode = NOP;
for (int i = 0; i < to_copy->b_iused; i++) {
int index = basicblock_next_instr(bb);