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

PEP 757: edits, based on C-API WG feedback #4026

Merged
merged 18 commits into from
Oct 15, 2024

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Oct 8, 2024

  • Change is either:
    • To a Draft PEP
    • To an Accepted or Final PEP, with Steering Council approval
    • To fix an editorial issue (markup, typo, link, header, etc)
  • PR title prefixed with PEP number (e.g. PEP 123: Summary of changes)

// capi-workgroup/decisions#45


📚 Documentation preview 📚: https://pep-previews--4026.org.readthedocs.build/

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @skirpichev.

peps/pep-0757.rst Outdated Show resolved Hide resolved
peps/pep-0757.rst Outdated Show resolved Hide resolved
peps/pep-0757.rst Outdated Show resolved Hide resolved
peps/pep-0757.rst Outdated Show resolved Hide resolved
peps/pep-0757.rst Outdated Show resolved Hide resolved
peps/pep-0757.rst Outdated Show resolved Hide resolved
peps/pep-0757.rst Outdated Show resolved Hide resolved
@skirpichev skirpichev marked this pull request as ready for review October 13, 2024 05:23
@skirpichev
Copy link
Member Author

PEP updated to roughly follow @encukou proposal in the d.p.o thread. Accompanying change in the implementation: vstinner/cpython#7 (this uses anonymous union for now). Just one export "view" kept: a digit array, valid for all integers for now.

The export benchmark should be unaffected.

PS: It would be nice if we could put an upper bound on size of integers in the default branch. Then instead of abort() or raising an exception - we could fall back on PyLong_AsNativeBytes() to do successful conversion.

peps/pep-0757.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address feedback related to "big enough" integers.

@willingc willingc requested a review from pitrou October 13, 2024 19:06
Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @skipichev. I really like the latest commit from you. The concepts are now much more understandable. Great job.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the PEP co-author, I'm against removing PyLongExport.value member.

@skirpichev
Copy link
Member Author

Ok, Victor, but please listen first to my arguments.

  1. PyLong_Export API should provide maximally transparent access to internals of int's, especially in case of "big" integers (where currently no public API exists);
  2. the "array of digits" view is valid now for all integers;
  3. the int64_t value view currently is redundant and is a kind of optimization, that has some benefits on some workloads and some drawbacks on others; pros and cons also will depend on the used bigint library;
  4. neither gmpy2, nor Sage currently use PyLong_AsLongAndOverflow "hack" (in fact, my patch with such optimization was rejected before);
  5. so, I think it's better to leave users with a simple export format and let them make suitable optimizations explicitly;
  6. things slightly simpler on the CPython side: we have just one export type.

@pitrou
Copy link
Member

pitrou commented Oct 14, 2024

@skirpichev You've already said so a number of times on Discourse, how is it useful to rehash it here? You're not the only potential consumer for this API, and you're also not a CPython maintainer AFAIK.

Copy link

@efimov-mikhail efimov-mikhail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification about using PyLongWriter_Discard.

@skirpichev skirpichev marked this pull request as draft October 14, 2024 17:28
@skirpichev skirpichev requested a review from vstinner October 15, 2024 09:35
@skirpichev
Copy link
Member Author

Now changes in the PyLongExport struct and PyLong_Export API (return type) - reverted.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I cannot merge your PR since it's a draft.

FYI export_long name is needed in the implementation because export is a reserved keyword in C++ (I don't recall in which C++ version, maybe C++20). But for the PEP, we can use export name.

@skirpichev skirpichev marked this pull request as ready for review October 15, 2024 09:42
@vstinner vstinner merged commit 68413fa into python:main Oct 15, 2024
5 of 6 checks passed
@skirpichev skirpichev deleted the pep757-edits branch October 15, 2024 09:46
gvanrossum pushed a commit to gvanrossum/peps that referenced this pull request Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants