-
Notifications
You must be signed in to change notification settings - Fork 952
Description
Apparently this is a follow-up issue of #210 and here goes a small TODO list for getting rid of specialization.
Yeah, but... please understand opening this means we are ready to resolve this soon!
I'll be busy for a while.
- ObjectProtocol
- Conversion
- Sequence
-
ObjectProtocol
This is the main use of specialization.
To resolve this we can use @konstin 's inventory trick(Poc dunder without specialization #552) or my dirty trick with provider trait. -
Conversion
Like this.
It is good that New #[pyclass] system that is aware of its concrete layout #683 makes pyclass detection easier and I think we can resolve this with not so complex implementation.
But what can be problematic is some conversion traits depend onToPyObjecttrait, which I really don't like.
Now we can distinguish Rust-native and Python-native objects if we haveT: TypeInfo, but, forToPyObject, we cannot do it.
Just addingPyTypeInfobound might work, but I really don't like this situation.
In my new semantics proposed in New #[pyclass] system that is aware of its concrete layout #683, our conversion hierarchy is like this:
| Rust-native | Python-native | |
|---|---|---|
| In Rust | T: PyClass |
Cannot exist! |
| In Python | PyClassShell<T> |
<T as PyTypeInfo>::ConcreteLayout |
| Rust reference to the object in Python heap | &T or &PyClassShell<T> |
&T |
So, yeah, we can convert T: PyClass to Python objects..., but we should not treat them and their pointer (in Python heap) same as Python native types!
Currently, this kind of too general conversion trait needs specialization and ... I'm not sure how to resolve this.
Honestly, I want to create a new trait for the 'In Python' layer in the above table, but it'll be a breaking change and careful design change.
- Sequence
https://github.com/PyO3/pyo3/blob/v0.8.4/src/types/sequence.rs#L248
It's a problem with speed and efficiency.
No technical problem is other than that.