Skip to content

Change vtable code generation to use pointers instead of references for this #2163

Closed
@Tazdevil971

Description

@Tazdevil971

The current vtable code generation uses references instead of pointers for this.

I think this should be changed as C++ mutable references are semantically different from rust's ones. And with the current implementation it's impossible to avoid UB in certain edge cases.

Multithreaded C++ code calling rust always results in the creation of a mutable reference unless the function is marked const, if multiple calls happen at once we would have more than one mutable reference around. Mutable aliasing here is unavoidable.

The solution would be to use pointers instead of references, as they have basically the same semantics as C++ mutable references and don't create such problems.

Also, pointers offer greater flexibility when it comes to casting between types, which happens a lot around rust implemented C++ interfaces.

The only disadvantage is loosing the guarantee that this must always be not null. A possible fix would be to use NonNull<T> for this, but since there is no const equivalent of NonNull<T> I don't think this is a viable solution.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions