Skip to content

Alternatives to ProtocolObject #686

Open
@madsmtm

Description

@madsmtm

I suspect it may be possible for us to basically never need to use ProtocolObject, but instead rely on the compiler to do the work of figuring out which traits are valid for which objects.

I've experimented a bit with #[derive(CoercePointee)] in bb1ae6f, to show that some of it can indeed work through that. If we also changed message sending such that &dyn NSObjectProtocol translates to NonNull<AnyObject>, then using protocol objects would look very, very similar to normal Rust code (methods take &dyn MyProtocol and end up returning Retained<dyn MyProtocol>).

One worry is that the vtable may be included in the final binary, that would have to be thoroughly tested beforehand.

We also need to do a more detailed soundness analysis before all this is over.

Another venue to investigate is the relationship between Message and RefEncode, and if we could possibly make the Message trait be dyn-compatible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesenhancementNew feature or requestquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions