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

Handles / Opaque linear references #7

Open
encukou opened this issue Oct 10, 2023 · 3 comments
Open

Handles / Opaque linear references #7

encukou opened this issue Oct 10, 2023 · 3 comments

Comments

@encukou
Copy link

encukou commented Oct 10, 2023

Reference counting (incref/decref) is replaced by what HPy calls handles, and Mark's proposal Opaque, linear references:

  • Each handle has exctly one owner.
  • Handles are destroyed by PyRef_Close.
  • Handles are duplicated using PyRef_Dup. Each must be destroyed (i.e. you can't Close one of them twice).
  • There can be multiple handles for a single object.
  • Object identity is compared using PyRef_Is, not by a pointer comparison

HPy shows that this enables a moving GC.
It does need all users to update all their code, so CPython probably can't ever require this. But we could provide PyRef_Dup/PyRef_Close/PyRef_Is (implemented as Py_INCREF/Py_DECREF/Py_Is) to allow users to signal that they're using handle semantics, and are (theoretically) compatible with implementations that use a moving GC.

@gvanrossum
Copy link
Contributor

Why are these called "linear references"? Is there a common definition of that term?

@encukou
Copy link
Author

encukou commented Oct 11, 2023

@markshannon, there's some academic background for the term, right? I hope I'm using it correctly :)

@jeanas
Copy link

jeanas commented Oct 13, 2023

Why are these called "linear references"? Is there a common definition of that term?

See https://en.wikipedia.org/wiki/Substructural_type_system#Linear_type_systems

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

No branches or pull requests

3 participants