-
Notifications
You must be signed in to change notification settings - Fork 37
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
[Breaking change][WIP] Disallow accessing mutable param by value #1109
Conversation
This is a reasonable restriction, I think... But it might be desirable to add a non-reference version without this restriction. If you pull a param with no intent to change it, it shouldn't necessarily be a problem. |
I'm now confused (trying to understand the original issue that cause this PR). |
If that's the case, I don't understand why this change fixed the problem either: I changed this from |
Ah I see. I would argue this is expected and reasonable behavior. Sometimes you will want to get the value of a mutable param without being able to update it. |
Ah... I understand now. Yes, I agree that is reasonable. @pgrete I think the correct thing to do to avoid this problem in the future would be to delete the copy constructor and copy assignment operator of the |
Closing in favor of parthenon-hpc-lab/athenapk#110. |
Hmm, that doesn't actually work, since the copy constructor is used by Params:
@Yurlungur @pgrete is there an obvious solution I'm overlooking? |
@Yurlungur why does Params copy-construct? That does not make sense to me. |
One solution would be to give |
Making |
It's because the object is passed in so it needs to be copied. Actually we could maybe change this to a move. That would probably be fine. |
What do you mean @BenWibking ? I'm not sure I follow the suggestion. |
I just mean @Yurlungur's suggestion: "You could play some dirty games under the hood and make your FewModesFT own pointers or references to things inside it you want to modify... then it wouldn't matter whether it's a mutable param or not." But that might not be worth it, or useful in general. I think the main issue is that the ownership semantics were not clear to me when I wrote the code. |
PR Summary
Throw an exception if a mutable parameter is accessed by value.
This means that mutable parameters must be accessed with
StateDescriptor::MutableParam
and non-mutable parameters must be accessed withStateDescriptor::Param
. This helps to avoid bugs in downstream application codes due to accidental use ofpkg->Param
with mutable params.PR Checklist