Skip to content
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

Code generator: support variable stack effects in macros #106812

Closed
gvanrossum opened this issue Jul 16, 2023 · 1 comment
Closed

Code generator: support variable stack effects in macros #106812

gvanrossum opened this issue Jul 16, 2023 · 1 comment
Labels
type-bug An unexpected behavior, bug, or error

Comments

@gvanrossum
Copy link
Member

gvanrossum commented Jul 16, 2023

Currently you can't split e.g.

inst(CALL_PY_EXACT_ARGS, (unused/1, func_version/2, method, callable, args[oparg] -- unused))
{ ... }

into two micro-ops

op(_CHECK_PY_FUNCTION, (func_version/2, method, callable, args[oparg] -- method, callable, args[oparg]))
{ ... }
op(_CALL_PY_EXACT_ARGS, (method, callable, args[oparg] -- unused))
{ ... }
macro(CALL_PY_EXACT_ARGS) = unused/1 + _CHECK_PY_FUNCTION + _CALL_PY_EXACT_ARGS;

We need at least to handle micro-ops that have the same variable-length input effect as output effect, and a final (action) op that has a variable-length stack input effect and a fixed output effect. This should handle all the CALL specializations. (For UNPACK_SEQUENCE we also need to support a fixed input effect and a variable output effect, in he action op.)

Linked PRs

@gvanrossum gvanrossum added the type-bug An unexpected behavior, bug, or error label Jul 16, 2023
@gvanrossum
Copy link
Member Author

This is turning into a bit of a research project. I would like to refactor all the handling of stack effects in the generator.

I'm thinking of having an algorithm that takes a sequence of operations such as pop/push, peek/poke, shrink/grow, and copy, and which applies certain transformations (e.g. push+pop can be replaced by copy under certain conditions), trying to reach an optimal end state, which can then be turned into optimal C code.

But the right set of operations, transformations and conditions is still elusive.

gvanrossum added a commit that referenced this issue Aug 4, 2023
…fects (#107564)

Introducing a new file, stacking.py, that takes over several responsibilities related to symbolic evaluation of push/pop operations, with more generality.
gvanrossum added a commit that referenced this issue Aug 5, 2023
This fixes two tiny defects in analysis.py that I didn't catch on time in #107564:

- `get_var_names` in `check_macro_consistency` should skip `UNUSED` names.
- Fix an occurrence of `is UNUSED` (should be `==`).
gvanrossum added a commit that referenced this issue Aug 8, 2023
- Generalize the syntax for the type of a stack effect to allow a trailing `*`,
  so we can declare something as e.g. `PyCodeObject *`.

- When generating assignments for stack effects,
  the type of the value on the stack should be the default (i.e., `PyObject *`)
  even when the variable copied to/from it has a different type,
  so that an appropriate cast is generated
  However, not when the variable is an array --
  then the type is taken from the variable (as it is always `PyObject **`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant