For functions that take `already_AddRefed<T>&&`, change to `already_AddRefed<T>` (pass by value instead of by rvalue reference), to force an ownership-transfer into the function
Categories
(Core :: XPCOM, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox153 | --- | fixed |
People
(Reporter: dholbert, Assigned: dholbert)
References
(Blocks 2 open bugs)
Details
Attachments
(16 files, 3 obsolete files)
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review |
We've got quite a few cases of functions that take an rvalue reference to an already_AddRefed type - this searchfox captures some (maybe all?) of them:
https://searchfox.org/firefox-main/search?q=%5C%28.*already_AddRefed.*%26%26&path=&case=false®exp=true
Excluding the smart-pointer-internal ones (maybe?), I think none of the others should actually take an rvalue reference at all. The parameter type should just be already_AddRefed<T>, not already_AddRefed<T>&&.
By taking already_AddRefed<T>&&, we're giving too much leeway -- we're allowing the function to not-consume the passed-in value (and leave the caller's already_AddRefed untouched). And that's generally not the semantics that we're looking for. The fact that we're passing an already_AddRefed implies that we're intentionally trying to transfer ownership into the function, and passing-by-value forces that ownership-transfer to happen (by making the parameter take ownership of the reference when it's copy-constructed, and then forcing the function to take ownership from that parameter before the parameter gets destructed, by virtue of how ~already_AddRefed works).
In cases where we forget to consume the passed-in reference: if we use already_AddRefed<T> (passing by value instead of by rvalue reference), that should result in easier-to-understand error output -- the parameter will fatally assert when it goes out of scope, instead of the caller's value (a temporary or a passed-in local variable, some arbitrary distance up the stack) fatally asserting, as would happen right now.
| Assignee | ||
Updated•3 months ago
|
| Assignee | ||
Comment 1•3 months ago
|
||
I've got a patch that claude helped me write. Will post later on.
| Assignee | ||
Comment 2•3 months ago
|
||
| Assignee | ||
Comment 3•3 months ago
|
||
| Assignee | ||
Comment 4•3 months ago
|
||
(Given the size of this bug's patch, maybe it's best for me to split into per-component parts, since it's reviewable/landable in a piece-wise fashion...)
| Assignee | ||
Updated•3 months ago
|
| Assignee | ||
Comment 6•3 months ago
|
||
(In reply to Daniel Holbert [:dholbert] from comment #4)
(Given the size of this bug's patch, maybe it's best for me to split into per-component parts, since it's reviewable/landable in a piece-wise fashion...)
I started to do this in separate bugs (bug 2044569) but I realized that I should probably not land parts separately in case there are inheritance relationships between different functions. So I'm just going to split the original patch into multiple patches and post them all here as a stack to be landed atomically.
Updated•3 months ago
|
| Assignee | ||
Comment 7•3 months ago
|
||
See https://bugzilla.mozilla.org/show_bug.cgi?id=2044510#c0 for more details.
| Assignee | ||
Comment 8•3 months ago
|
||
Updated•3 months ago
|
| Assignee | ||
Comment 9•3 months ago
|
||
| Assignee | ||
Comment 10•3 months ago
|
||
| Assignee | ||
Comment 11•3 months ago
|
||
| Assignee | ||
Comment 12•3 months ago
|
||
| Assignee | ||
Comment 13•3 months ago
|
||
| Assignee | ||
Comment 14•3 months ago
|
||
| Assignee | ||
Comment 15•3 months ago
|
||
| Assignee | ||
Comment 16•3 months ago
|
||
| Assignee | ||
Comment 17•3 months ago
|
||
| Assignee | ||
Comment 18•3 months ago
|
||
| Assignee | ||
Comment 19•3 months ago
|
||
| Assignee | ||
Comment 20•3 months ago
|
||
| Assignee | ||
Comment 21•3 months ago
|
||
| Assignee | ||
Comment 22•3 months ago
|
||
| Assignee | ||
Comment 23•3 months ago
|
||
| Assignee | ||
Comment 24•3 months ago
|
||
Updated•3 months ago
|
Comment 25•3 months ago
|
||
Consider also writing a clang-plugin to prevent this pattern coming back in the future.
Updated•3 months ago
|
Comment 26•3 months ago
|
||
Comment on attachment 9592909 [details]
Bug 2044510: Pass already_AddRefed types by-value instead of by rvalue reference, in image/. r?tnikkel
Revision D304366 was moved to bug 2045352. Setting attachment 9592909 [details] to obsolete.
Comment 27•3 months ago
|
||
Comment 28•3 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/08bb32707816
https://hg.mozilla.org/mozilla-central/rev/5bb9e4d50fe1
https://hg.mozilla.org/mozilla-central/rev/7b7fd5636306
https://hg.mozilla.org/mozilla-central/rev/881cf0929ca2
https://hg.mozilla.org/mozilla-central/rev/b7c18a980296
https://hg.mozilla.org/mozilla-central/rev/b3135760ba66
https://hg.mozilla.org/mozilla-central/rev/32438b1c051d
https://hg.mozilla.org/mozilla-central/rev/73da4d62f357
https://hg.mozilla.org/mozilla-central/rev/e3072a946510
https://hg.mozilla.org/mozilla-central/rev/bc7da0b6b808
https://hg.mozilla.org/mozilla-central/rev/5cb97c62a3e6
https://hg.mozilla.org/mozilla-central/rev/85e8755ef3d8
https://hg.mozilla.org/mozilla-central/rev/9c54ebfd2257
https://hg.mozilla.org/mozilla-central/rev/d9032c0a6075
https://hg.mozilla.org/mozilla-central/rev/b51ea2b34280
https://hg.mozilla.org/mozilla-central/rev/965658c44af0
https://hg.mozilla.org/mozilla-central/rev/bfe5b60f478c
Description
•