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
WeakPtrFactory should be destroyed before any other members. #29402
Conversation
4e3096e
to
3043cc2
Compare
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
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.
We should not move ivars below methods/friend declarations for testing. That goes against the style guide.
There are two "real" instances here where it could matter: accessibility_bridge.h
and rasterizer.h
. We're lucky in that neither of those declare an ivar that actually uses the weak pointer that the factory would vend.
Given that, we should definitely take whatever time needed to add analysis/tests for this.
Thank you for your reply. As per Declaration Order, all data members should be last. Another purpose here is to alleviate the risk of new members being mistakenly inserted after |WeakPtrFactory|. |
So I learned! But if we're moving them we should move all of them. I also see that there are some objc files that are impacted by this but not fixed. |
Please have another look at it, Thanks. |
This still needs some kind of test (static analysis would be fine) to make sure that these rules are followed. |
Got it. Are there any examples I can refer to? |
I'm not sure. We do run clang-tidy but I don't think that can detect this. |
OK, thanks anyway. :) |
I found that chromium has a clang plugin to check the WeakPtrFactory class member order. Maybe we can port the clang plugin to flutter. See FindBadConstructsConsumer::CheckWeakPtrFactoryMembers for details. I want to finish it. However, I am not familiar with the build system, nor do I have time to dig into it recently. Any bits of advice? Thanks. |
Talked to some Fuchsia Toolchain folks, and they suggested implementing these as clang-tidy checks. Fuchsia already has some at https://github.com/llvm/llvm-project/tree/main/clang-tools-extra/clang-tidy/fuchsia I am not clear on who might be available to do this, if anyone is right now, or if this is something @0xZOne would be interestedin trying, but just trying to leave some more breadcrumbs here. |
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 but will need a test exemption from @Hixie to land.
Also, per our updated policy, this needs a review from someone else with commit access to the repo before landing. |
test-exempt: only affects analysis Please document the desired analysis in an issue and link that issue here. Thanks. |
Related issue: #93039 |
WeakPtrFactory should remain the last member so it'll be destroyed and invalidate its weak pointers before any other members are destroyed.
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.