lang: Shorten invariant lifetimes during Context creation - #4363
Conversation
|
@acheroncrypto is attempting to deploy a commit to the Solana Foundation Team on Vercel. A member of the Team first needs to authorize it. |
|
Just bumping on this, are you able to fix the compile errors? |
|
There seems to be only one compile error coming from that cursed generics accounts struct. It should be fixable. I'll take a look later this week. |
|
Sorry for the delay. Should be fixed now. |
|
@jamie-osec bump |
|
I don't feel strongly about the concerns raised so I think we can merge if you disagree; it's just that we'd be adding unnecessary (if theoretical) breakage |
|
I think this is an important fix because we're actually extending the borrow lifetime instead of shortening it. This is not only incorrect based on what it says it does, but it might even be bordering the UB territory. I think a theoretical breakage is justified in a situation like this. However, feel free to cover those other generic cases if you think they could be problematic. |
jamie-osec
left a comment
There was a problem hiding this comment.
We can revisit in the unlikely case this breaks anyone
Problem
As mentioned in #3340 (comment), the helper function
__shrink_lifetimeactually extends the mutable borrow lifetime instead of shrinking the inner lifetime:https://github.com/solana-foundation/anchor/blob/62865c636aecc6974fc9cfebfc6cf08ca4f0bb72/lang/syn/src/codegen/program/handlers.rs#L130-L132
This is not the desired behavior, and it also conflicts with its safety comments:
https://github.com/solana-foundation/anchor/blob/62865c636aecc6974fc9cfebfc6cf08ca4f0bb72/lang/syn/src/codegen/program/handlers.rs#L138-L142
Summary of changes
Shorten invariant lifetimes rather than extending the mutable borrow lifetime during
Contextcreation.