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

Id improvements #21

Merged
merged 16 commits into from
Sep 9, 2021
Merged

Id improvements #21

merged 16 commits into from
Sep 9, 2021

Conversation

madsmtm
Copy link
Owner

@madsmtm madsmtm commented Sep 5, 2021

Replaces upstream SSheldon/rust-objc#98 and SSheldon/rust-objc#95.

We want to avoid having users specify their own X + XRef types. Instead they should use Id<X> + &X.

TODO:

  • Use null-pointer optimization
  • Ownership trait should be sealed.
  • Restrict to only Message / "ObjectType" / "RetainAble" types? It was already restricted to Message, the rest is postponed.
  • Consider if UnsafeCell is appropriate.
  • &'pool mut X -> Id<X, Owned>?
  • &'pool X -> Id<X, Shared>?
  • &X -> Id<X, Shared>?
    • All of the above not possible, because &X could come from Id<X, Owned>, since lifetime information is discarded!
  • Consider adding lifetime info to Id, see above. Postponed to investigation in Fix ownership in objc2-foundation #29.
  • What about when X is actually Sized? Is Id<X, O> even valid?
  • Rename Id -> Retain/Retained/... Postponed, this seems overly disruptive, just for disruptiveness' sake.
  • Add Id::autorelease
  • Make this work different "backends" like block, libdispatch, CoreFoundation; see fruity's approach. Future.
  • Add retain_count function. Not desired on Id, this should instead be available on all objects.

References:

@madsmtm madsmtm mentioned this pull request Sep 5, 2021
80 tasks
@madsmtm madsmtm added the enhancement New feature or request label Sep 5, 2021
These names are shorter and more pretty clearly signifies the intention. We also now take `NonNull` arguments so that there's less stuff we have to verify.
- Eq
- PartialOrd
- Ord
- Display
- Iterator
- DoubleEndedIterator
- ExactSizeIterator
- FusedIterator
- Borrow
- BorrowMut
- AsRef
- AsMut
- Unpin
Because I want to get rid of objc2::rc::WeakPtr.

WeakId can now also use the null-pointer optimization, and it has a Default implementation.
@madsmtm madsmtm force-pushed the id-improvements branch 2 times, most recently from e7ffccb to e36b8de Compare September 9, 2021 10:46
Will allow us to do some nice things when/if GATs stabilize
Id is such a vital requirement for applications that there's no need to make it a "second class citizen". If we really feel it's too much of an experiment, we can always feature-flag it later.

Also, there's might be traits I'd like to implement for e.g. Option<Id> that is not possible if it lives in it's own crate!
We want to encourage users to use Id and WeakId, because they provide much stronger guarantees. The other types can in most cases be emulated as:
type StrongPtr = Option<Id<Object, Shared>>
type WeakPtr = WeakId<Object>

And for the cases where they can't, their implementation is pretty simple anyhow, so advanced users can just use objc2_sys to implement the functionality they need themselves.
This is a usability degradation, but before we know more about actual usage patterns this is the safer option; users will have to explicitly specify the ownership they're expecting.

See SSheldon/rust-objc-id#4
@madsmtm madsmtm merged commit 923b893 into master Sep 9, 2021
@madsmtm madsmtm deleted the id-improvements branch September 9, 2021 13:50
madsmtm added a commit that referenced this pull request Oct 1, 2021
@madsmtm madsmtm added this to the objc2 v0.3 milestone Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant