Skip to content

Conversation

kkysen
Copy link
Collaborator

@kkysen kkysen commented Jul 14, 2024

I'm struggling to figure out the lifetimes here, even though I think they should work. The 'buf lifetime, i.e. the lifetime of Rav1dPictureDataComponentInner::buf, should outlive 'a, where 'a is in &'a Rav1dPictureDataComponent<'buf> when stored in Rav1dPictureDataComponentOffset::data. But things aren't working out. Can anyone else help and figure this out?

@kkysen kkysen requested review from rinon and randomPoison July 14, 2024 08:14
@kkysen kkysen marked this pull request as draft July 14, 2024 08:17
@rinon
Copy link
Collaborator

rinon commented Jul 16, 2024

It's not that it needs to outlive 'a there, it's that you're assigning a Rav1dPictureComponent<'buf> and a Rav1dPictureComponent<'static> to the same variable, so the lifetimes in those two types must match (because DisjointMut is invariant).

Sorry I don't have a solution tonight, gonna get to bed, but I'll think on it.

@kkysen
Copy link
Collaborator Author

kkysen commented Jul 16, 2024

It's not that it needs to outlive 'a there, it's that you're assigning a Rav1dPictureComponent<'buf> and a Rav1dPictureComponent<'static> to the same variable, so the lifetimes in those two types must match (because DisjointMut is invariant).

Sorry I don't have a solution tonight, gonna get to bed, but I'll think on it.

Yeah, I realized that. But I don't know how to make the lifetimes exactly the same, or how to not have the lifetime be invariant. But as far as I can tell, the UnsafeCell<T> forces it to be invariant since &mut Ts can be made from it and &mut T is invariant over T. That's my current understanding at least.

kkysen added a commit that referenced this pull request May 27, 2025
…uf` outlives `Self`

Adding proper lifetimes is difficult (see #1317),
so we instead make this an `unsafe` precondition,
that `buf` must outlive the returned `Self`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants