-
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
make get parent pointer consistent #974
Conversation
…turn a raw pointer, making it look the same as with MeshData.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, I completely support switching to raw pointers where functions don't need to take ownership. Thanks for going through and making those changes, I am not sure why I ended up going with smart pointers in the boundary stuff in the first place.
Given that this is potentially API breaking, should we wait for the next release or should we already get this in (and I'll update the changelog when I make the release)? |
Ah good point. I say make a release first then this goes in immediately after release. |
Since this is a breaking change dealing with how we manage pointers (and removing |
IMO the weak pointers don't buy us a whole lot, but they're more defensible in the internals of the code. The main place they're used is as back-pointers for objects owned by I'm fine keeping them or removing them---I don't feel strongly. That said, since this PR already works, I'd rather get it in and then remove the |
Thanks for clarifying. Given your points that the weak pointers are internal and that they do protect against cyclic dependencies, I'm fine to defer thinking about our weak pointer usage to later/never. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two non-blocking comments you're welcome to ignore, just mentioning them in case you think they are worth the effort to make the changes.
@@ -97,10 +97,10 @@ class MeshBlockData { | |||
SetBlockPointer(other.get()); | |||
} | |||
void SetBlockPointer(const MeshBlockData<T> &other) { | |||
pmy_block = other.GetBlockPointer(); | |||
pmy_block = other.GetBlockSharedPointer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since pointers and shared pointers are coexisting more closely in some cases clarity might be improved by naming shared points spmy_*
and naming pointers pmy_*
. I don't think this is blocking but I'm just bringing it up in case you agree.
@@ -751,7 +751,7 @@ void Mesh::RedistributeAndRefineMeshBlocks(ParameterInput *pin, ApplicationInput | |||
auto pmb = FindMeshBlock(on); | |||
for (auto &var : pmb->vars_cc_) { | |||
restriction_cache.RegisterRegionHost( | |||
irestrict++, ProResInfo::GetInteriorRestrict(pmb, NeighborBlock(), var), | |||
irestrict++, ProResInfo::GetInteriorRestrict(pmb.get(), NeighborBlock(), var), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would FindMeshBlock
returning a pointer rather than a shared pointer be more in the spirit of this PR?
Now we're post release, I'm clicking the button |
PR Summary
For the longest time now,
MeshData::GetParentPointer
has returned aMesh*
object, whileMeshBlockData::GetParentPointer
has returned astd::shared_ptr<MeshBlock>
. This inconsistency is annoying to deal with in templated code that uses both levels of the abstraction hierarchy. It's also bad practice to pass aroundstd::shared_ptr<T>&
everywhere, which this return value encourages.In this PR I Make
MeshBlockData::GetParentPointer
return aMeshBlock*
. This required a few things:weak_ptr
logic used forMeshBlockData
, I needed to add a funciton that still returned a shared pointer. So there are now two underlying fundamental functions:GetBlockSharedPointer
andGetBlockPointer
.GetBlockPointer
orGetParentPointer
to expect aMeshBlock*
instead of astd::shared_ptr<MeshBlock>
. The main places this showed up are in boundary comms.This is a very small change that touches a lot of code, but it should be a quick review. @lroberts36 I mostly touched your code, so I think it's important you review this one.
Note that this may be a breaking change downstream, but the fix would be as simple as find-replace
std::shared_ptr<MeshBlock>
withMeshBlock*
and maybe not even that if you're usingauto
.PR Checklist