Skip to content

When, if ever, are extern "Rust" ABIs compatible with each other? #280

Open
@joshlf

Description

@joshlf

This question was originally discussed on Twitter here.

I'm trying to write a library to stack-allocate dyn Future objects. The core of this code is the following:

const N: usize = 8;

pub struct DynamicFuture<O> {
    data: [u8; N], // NOTE: Alignment is handled, but I've elided it here for simplicity
    poll_fn: for<'r, 's, 't0> fn(Pin<&'r mut ()>, &'s mut Context<'t0>) -> Poll<_>,
    _marker: PhantomData<O>,
}

When a DynamicFuture is created, the static type of the future is known, and poll_fn is set to <F as Future>::poll. Then, in the implementation of Future for DynamicFuture, the data field is converted to a Pin<&mut ()>, and poll_fn is called on it.

My question is: Is the ABI of <F as Future>::poll (type signature: for<'r, 's, 't0> fn(Pin<&'r mut F>, &'s mut Context<'t0>) -> Poll<_> guaranteed to be the same as the ABI of poll_fn (identical type signature except for Pin<&'r mut ()> instead of Pin<&'r mut F>)? If so, is it sound to call poll_fn by constructing a Pin<&mut ()> from the data field?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-abiS-pending-designStatus: Resolving this issue requires addressing some open design questions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions