| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 356a88c commit 83f22a5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -505,6 +505,21 @@ no_redundant_jumps(cfg_builder *g) { | |||
| 505 | 505 | return true; | |
| 506 | 506 | } | |
| 507 | 507 | ||
| 508 | + static bool | ||
| 509 | + all_exits_have_lineno(basicblock *entryblock) { | ||
| 510 | + for (basicblock *b = entryblock; b != NULL; b = b->b_next) { | ||
| 511 | + for (int i = 0; i < b->b_iused; i++) { | ||
| 512 | + cfg_instr *instr = &b->b_instr[i]; | ||
| 513 | + if (instr->i_opcode == RETURN_VALUE) { | ||
| 514 | + if (instr->i_loc.lineno < 0) { | ||
| 515 | + assert(0); | ||
| 516 | + return false; | ||
| 517 | + } | ||
| 518 | + } | ||
| 519 | + } | ||
| 520 | + } | ||
| 521 | + return true; | ||
| 522 | + } | ||
| 508 | 523 | #endif | |
| 509 | 524 | ||
| 510 | 525 | /***** CFG preprocessing (jump targets and exceptions) *****/ | |
@@ -2378,34 +2393,6 @@ propagate_line_numbers(basicblock *entryblock) { | |||
| 2378 | 2393 | } | |
| 2379 | 2394 | } | |
| 2380 | 2395 | ||
| 2381 | - /* Make sure that all returns have a line number, even if early passes | ||
| 2382 | - * have failed to propagate a correct line number. | ||
| 2383 | - * The resulting line number may not be correct according to PEP 626, | ||
| 2384 | - * but should be "good enough", and no worse than in older versions. */ | ||
| 2385 | - static void | ||
| 2386 | - guarantee_lineno_for_exits(basicblock *entryblock, int firstlineno) { | ||
| 2387 | - int lineno = firstlineno; | ||
| 2388 | - assert(lineno > 0); | ||
| 2389 | - for (basicblock *b = entryblock; b != NULL; b = b->b_next) { | ||
| 2390 | - cfg_instr *last = basicblock_last_instr(b); | ||
| 2391 | - if (last == NULL) { | ||
| 2392 | - continue; | ||
| 2393 | - } | ||
| 2394 | - if (last->i_loc.lineno < 0) { | ||
| 2395 | - if (last->i_opcode == RETURN_VALUE) { | ||
| 2396 | - for (int i = 0; i < b->b_iused; i++) { | ||
| 2397 | - assert(b->b_instr[i].i_loc.lineno < 0); | ||
| 2398 | - | ||
| 2399 | - b->b_instr[i].i_loc.lineno = lineno; | ||
| 2400 | - } | ||
| 2401 | - } | ||
| 2402 | - } | ||
| 2403 | - else { | ||
| 2404 | - lineno = last->i_loc.lineno; | ||
| 2405 | - } | ||
| 2406 | - } | ||
| 2407 | - } | ||
| 2408 | - | ||
| 2409 | 2396 | static int | |
| 2410 | 2397 | resolve_line_numbers(cfg_builder *g, int firstlineno) | |
| 2411 | 2398 | { | |
@@ -2434,7 +2421,7 @@ _PyCfg_OptimizeCodeUnit(cfg_builder *g, PyObject *consts, PyObject *const_cache, | |||
| 2434 | 2421 | insert_superinstructions(g); | |
| 2435 | 2422 | ||
| 2436 | 2423 | RETURN_IF_ERROR(push_cold_blocks_to_end(g)); | |
| 2437 | - guarantee_lineno_for_exits(g->g_entryblock, firstlineno); | ||
| 2424 | + assert(all_exits_have_lineno(g->g_entryblock)); | ||
| 2438 | 2425 | RETURN_IF_ERROR(resolve_line_numbers(g, firstlineno)); | |
| 2439 | 2426 | return SUCCESS; | |
| 2440 | 2427 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments