python / python/cpython

We need unambiguous, meaningful naming of stack reference operations dependent on how counting is done

Đang mở
#130,789 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

interpreter-core
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

https://github.com/faster-cpython/ideas/issues/700 describes three ways to count references:

  • Virtual,
  • Embedded, and
  • Immediate

Virtual references are references that are know to exist to the relevant code generator, but are elided at runtime, so no API is needed for them.
Embedded references are marked by bit(s) in the reference and not in the ob_refcount field of the object.
Immediate references are counted in the ob_refcount (or free-threading equivalent) field of the object.

To this we should add uncounted which are references to immortal objects (including NULL).
Note that it is possible to have embedded or immediate references to immortal objects if the object was mortal when the reference, or reference this reference was created from, was created.

Why this matters

It is important that the use of references is understandable without referring to the implementation and we have multiple implementations of stackrefs, so the interface needs to be clear.

Multiple implementations

Even when we merge the free-threading and default implementations of stackrefs, we will still have the Py_STACKREF_DEBUG implementation which is very different and vital to finding reference errors.

Examples:

When creating an embedded stackref from another stackref, we should use PyStackRef_DUP_Embedded which has the same semantics as PyStackRef_DUP but creates an embedded reference if the implementation supports it.

There are circumstance when a method of counting is not safe. E.g. using embedded references in the heap is not safe. For that we will want to physically transform a reference without a logic change in ownership.
E.g. PyStackRef_ToNonEmbedded. In terms of ownership, this a no-op, PyStackRef_ToNonEmbedded(ref) is equivalent ref, but ensures that any embedded count is turned into an immediate count.

We probably should only use uncounted when referring to references in docs and comments, as we already have PyStackRef_FromPyObjectImmortal, there is no need for PyStackRef_FromPyObjectUncounted as well.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Issue không nêu tên tệp hay test nào, vì vậy trước tiên hãy xác định các API tham chiếu stack và so sánh những triển khai hiện có của chúng, bao gồm cả triển khai debug. Xem xét thuật ngữ được đề xuất cho Virtual, Embedded, Immediate và uncounted, cũng như các ví dụ như PyStackRef_DUP_Embedded và PyStackRef_ToNonEmbedded. Công việc được xem là hoàn tất khi các thao tác có tên không mơ hồ và ngữ nghĩa về quyền sở hữu và việc đếm của chúng rõ ràng giữa các triển khai.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Tái cấu trúc
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.