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

Re-work support of var-positional parameters in Argument Clinic #122943

Closed
serhiy-storchaka opened this issue Aug 12, 2024 · 1 comment
Closed

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Aug 12, 2024

When fixing some bugs (#118814, #122688) I noticed also design problems in _PyArg_UnpackKeywordsWithVararg().

  • Its vararg parameter is always equal to maxpos, therefore it is redundant.
  • Inserting a new tuple between values for positional and keyword-only parameters adds complexity in the _PyArg_UnpackKeywordsWithVararg() code which caused bugs.
  • Since it is the only argument value which is a strong reference, it adds complexity for cleanup after calling _PyArg_UnpackKeywordsWithVararg().
  • This large code is mostly a duplication of _PyArg_UnpackKeywords().
  • But it lacks some microoptimizations.
  • And produces wrong error messages in some corner cases.
  • Also some cases (like var-positional parameter after optional parameters) were not supported.

So I re-worked it in several steps:

  • Removed the vararg parameter from _PyArg_UnpackKeywordsWithVararg().
  • Moved creation of the tuple for var-positional parameter out from _PyArg_UnpackKeywordsWithVararg().
  • Refactored Argument Clinic code: it now generates similar code for var-positional parameter in functions with and without keyword parameters. The generated code is now more optimal and more cases are now supported. This is a large step.
  • Finally, _PyArg_UnpackKeywordsWithVararg() was merged with _PyArg_UnpackKeywords() which now got a new flag.

Linked PRs

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 12, 2024
…nt Clinic

Move creation of a tuple for var-positional parameter out of
_PyArg_UnpackKeywordsWithVararg().
Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords().
Add a new parameter in _PyArg_UnpackKeywords().

The "parameters" and "converters" attributes of ParseArgsCodeGen no
longer contain the var-positional parameter. It is now available as the
"varpos" attribute. Optimize code generation for var-positional
parameter and reuse the same generating code for functions with and without
keyword parameters.
@serhiy-storchaka
Copy link
Member Author

Changes in most of Argument Clinic generated files (which correspond to unchanged source files) can be ignored. Sorry, all these review requests are false.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 12, 2024
…nt Clinic

Move creation of a tuple for var-positional parameter out of
_PyArg_UnpackKeywordsWithVararg().
Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords().
Add a new parameter in _PyArg_UnpackKeywords().

The "parameters" and "converters" attributes of ParseArgsCodeGen no
longer contain the var-positional parameter. It is now available as the
"varpos" attribute. Optimize code generation for var-positional
parameter and reuse the same generating code for functions with and without
keyword parameters.
serhiy-storchaka added a commit that referenced this issue Nov 7, 2024
…nic (GH-122945)

Move creation of a tuple for var-positional parameter out of
_PyArg_UnpackKeywordsWithVararg().
Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords().
Add a new parameter in _PyArg_UnpackKeywords().

The "parameters" and "converters" attributes of ParseArgsCodeGen no
longer contain the var-positional parameter. It is now available as the
"varpos" attribute. Optimize code generation for var-positional
parameter and reuse the same generating code for functions with and without
keyword parameters.

Add special converters for var-positional parameter. "tuple" represents it as
a Python tuple and "array" represents it as a continuous array of PyObject*.
"object" is a temporary alias of "tuple".
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 7, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 7, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 8, 2024
Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 8, 2024
Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 8, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 8, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 8, 2024
serhiy-storchaka added a commit that referenced this issue Nov 8, 2024
Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 8, 2024
…nt Clinic (pythonGH-122945)

Move creation of a tuple for var-positional parameter out of
_PyArg_UnpackKeywordsWithVararg().
Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords().
Add a new parameter in _PyArg_UnpackKeywords().

The "parameters" and "converters" attributes of ParseArgsCodeGen no
longer contain the var-positional parameter. It is now available as the
"varpos" attribute. Optimize code generation for var-positional
parameter and reuse the same generating code for functions with and without
keyword parameters.

Add special converters for var-positional parameter. "tuple" represents it as
a Python tuple and "array" represents it as a continuous array of PyObject*.
"object" is a temporary alias of "tuple".
picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 8, 2024
picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 8, 2024
picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 8, 2024
…ythonGH-126564)

Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
…nt Clinic (pythonGH-122945)

Move creation of a tuple for var-positional parameter out of
_PyArg_UnpackKeywordsWithVararg().
Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords().
Add a new parameter in _PyArg_UnpackKeywords().

The "parameters" and "converters" attributes of ParseArgsCodeGen no
longer contain the var-positional parameter. It is now available as the
"varpos" attribute. Optimize code generation for var-positional
parameter and reuse the same generating code for functions with and without
keyword parameters.

Add special converters for var-positional parameter. "tuple" represents it as
a Python tuple and "array" represents it as a continuous array of PyObject*.
"object" is a temporary alias of "tuple".
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
…ythonGH-126564)

Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant