Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iritkatriel opened this issue May 13, 2022 · 1 comment
Closed

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

iritkatriel opened this issue May 13, 2022 · 1 comment
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@iritkatriel
Copy link
Member

iritkatriel commented May 13, 2022

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.
@iritkatriel iritkatriel added the type-feature A feature request or enhancement label May 13, 2022
@iritkatriel iritkatriel self-assigned this May 13, 2022
@erlend-aasland erlend-aasland added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label May 16, 2022
@iritkatriel
Copy link
Member Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants