The Wayback Machine - https://web.archive.org/web/20211008230035/https://github.com/RustPython/RustPython/issues/2810
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

Refactor descriptor types. #2810

Open
youknowone opened this issue Aug 8, 2021 · 5 comments
Open

Refactor descriptor types. #2810

youknowone opened this issue Aug 8, 2021 · 5 comments

Comments

@youknowone
Copy link
Member

@youknowone youknowone commented Aug 8, 2021

ref: #2808 (comment)

In RustPython, we have different class structures to CPython. Simply describing, RustPython doesn't have a type corresponding to PyDescrObject and wrapper types using it like PyMethodDescrObject, PyGetSetDescrObject and PyWrapperDescrObject.

@sobolevn
Copy link
Contributor

@sobolevn sobolevn commented Aug 12, 2021

Let's start with the CPython hierarchy (name => text repr):

Our structure is nothing near. It consists of:

  • trait SlotDescriptor, which defines __get__. It is used for all descriptors like methods, properties
  • PyGetSet which is used for @property declarations, it also defines __set__ and __delete__
  • PyBuiltinMethod, right now it looks like PyMethodDescrObject and PyCMethodObject at the same time

My plan (I might be wrong):

  1. Create PyDescrObject with d_type, d_name, d_qualname fields (names would be without prefixes)
  2. Create PyWrapperDescrObject and PyMemberDescrObject with PyDescrObject field
  3. Create PyGetSetDescrObject with PyDescrObject and PyGetSet fields
  4. Add PyDescObject field to PyBuiltinMethod, do we really need an extra wrapper here?
  5. Change new_getset and new_readonly_getset methods in ctx to use new descriptor types and new names
  6. Change how we create builtin methods
  7. Add proper repr to new types to match CPython, refs #2811 and #2809
  8. Document our descriptor hierarchy and compare it with CPython

Any other things I've missed?

@youknowone
Copy link
Member Author

@youknowone youknowone commented Aug 12, 2021

It doesn't look important, but PyGetSet and PyProperty(@property) are different. PyGetSet is a sort of internal property, but their detailed behaviours are not the same.

About plans:

  1. Sounds perfect
  2. is this #2842?
  3. great
  4. If CPython does, let's just go like that. nothing to lose. So PyMethodDescrObject here with additional field vectorcall(what's this?).
  5. good. but what you meant by 'new names'?
  6. no idea yet

@DimitrisJim
Copy link
Member

@DimitrisJim DimitrisJim commented Aug 12, 2021

I think #2842 is just type.__new__ not looking for a __slots__ present. __slot__ entries turn into members if I remember correctly we just don't currently do it.

@sobolevn
Copy link
Contributor

@sobolevn sobolevn commented Aug 12, 2021

@youknowone

  1. Yes, sounds related. I will keep this in mind. Does RustPython have any optimizations (similar to CPython) right now for __slots__ attribute access?
  2. Ok. vectorcall is an optimization for faster calling: https://www.python.org/dev/peps/pep-0590/ I think it safe to leave this out of scope for now
  3. New names that do not reference getset, because it is going to be "more internal"
  4. It will be required if we change how PyBuiltinMethod works in 4.

@youknowone
Copy link
Member Author

@youknowone youknowone commented Aug 12, 2021

  1. No, we don't have any optimizations for __slots__.
    4/5. I think we just need new_getset. We only use it to create classes and modules. The name just need to show we are creating a getset object. The annotation name is even #[pyproperty] which is not property at all, but to fit mental model for people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants