-
Notifications
You must be signed in to change notification settings - Fork 792
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
Add lifetime to PyAny
etc
#885
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kngwyu
reviewed
May 1, 2020
Amazing, thank you!
About this, I'll make a draft implementation. Please wait for a bit. |
I'm going to close this PR; it's a big pile of changes which I think we decided we don't want right now (instead opting for #887 as fast enough for now). This PR is so big it will fall out of date quickly and become hard to rebase. Some things I think I learned from this PR:
|
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a working implementation of
PyAny<'a>
.By working - I mean tests pass on my machine (except doctests). I think the code is still heavily WIP, because I ended up making a few hacks to make things compile. I wanted to get to a point where we could have something to play with to assess ergonomics, and how it feels versus the new proposal in #679.
Some initial observations:
Owned, Borrowed and Lifetimes
PyAny<'py>
&'a PyAny<'py>
'a
is the lifetime of thePyAny
we're borrowing from.Because there are now more input lifetimes to functions, there are a few more cases where Rust asks for lifetime annotations. We might want to make the recommendation that users return
Py<T>
owned pointers always to avoid lifetime complexity.Reference counting
As well as ownership above, incrementing and decrementing reference counts is done by
PyAny::clone()
andPyAny::drop()
respectively.PyAny deref
After making
PyAny<'py>
, I also was able to make e.g.This means that all native types now implement deref to
PyAny
. I think this provides an opportunity for us to removeObjectProtocol
and put all its methods directly onPyAny
, which is a nice API simplification.Py<T>
Py<PyTuple>
broke by adding lifetimes, and not evenPy<PyTuple<'static>>
worked. To solve this problem, I added type markers, which are ZSTs without lifetimes which take on the role of type information forPy
. Now you can write.To avoid confusion with
PyTuple
andPy<Tuple>
I think it would be wise to renamePy
toPyRc
(maybe not right now, but in the near future).To avoid needing complex lifetime rules in the proc macros, I also had to change it so that you write
#[extends=Dict]
instead of#[extends=PyDict]
. We might be able to undo this change with some careful implementation in the proc macros.I rather hacked together the type marker idea in general because I wanted to get to a point where things compile. There's a lot of cleanup I think can be done here.
TODO:
GILPool
's owned and borrowed tracking.