Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flip default for return_ref #719

Open
MichaReiser opened this issue Feb 23, 2025 · 3 comments
Open

Flip default for return_ref #719

MichaReiser opened this issue Feb 23, 2025 · 3 comments

Comments

@MichaReiser
Copy link
Contributor

MichaReiser commented Feb 23, 2025

This has come up in #718.

It's very easy to forget a return_ref on a non-copy type. On the other hand, returning a ref for a copy type may be undesired, but the performance consequences are often negligible.

Should we change the default for return_ref to be true and instead introduce a return_cloned.

Related: Should we introduce a return_deref? There have been a few occasions where I had an Option<T> and I ended up writing a manual accessor to get the deref behavior. That might also suggest that the syntax should be return(cloned), return(deref) return(ref)?

This is a rather subtle breaking change. We should change/decide on this before the first "stable" release.

@Veykril
Copy link
Member

Veykril commented Feb 24, 2025

For the Copy case I'd also expect the compiler to change the ref-passing to copy passing in some occasions on its own so I think the "risk" there of that being less efficient is negligible. The bigger annoyance is that you in fact now have a reference to your type which means you need to deref it manually, but that can be worked around by well putting the marker attribute on it.

Generalizing it via return(<action>) seems to generally be a good move for future extensions imo. Either way 👍 from me for flipping the default, it sounds like what one would expect in terms of default behavior.

In an ideal world with specialization we could work around this via a trait with an assoc type that marks the return type and specializing on Copy to reduce the annotation burden entirely (I think).

@Veykril
Copy link
Member

Veykril commented Feb 25, 2025

#582 related

@davidbarsky
Copy link
Contributor

I'm glad you opened this issue: I strongly think Salsa should default to #[return_ref] and I'm onboard with generalizing via return(<action>).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants