Skip to content

Unify the style of CFG traversal algorithms in the compiler #92782

Closed
@iritkatriel

Description

@iritkatriel

The compiler has several CFG traversal functions, which repeat some code with minor variations.

  • the stack is sometimes allocated with PyObject_Malloc and sometimes with PyMem_Malloc
  • the size of the stack is sometimes calculated from the b_list list and sometimes from the b_next list (and in one case a potentially stale value from the assembler is used).

I suggest to refactor as follows:

  • always use PyMem_Malloc
  • always count using the b_next list (the difference is that by using b_list links we count also some unreachable empty blocks, which we won't traverse through anyway, so we over-allocate the stack a bit).
  • refactor the whole thing into a function that also zeroes the b_visited field, and use it consistently.

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions