| Summary: | Move-constructing NeverDestroyed should move construct underlying object instead of copy constructing it | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Daniel Bates <dbates> | ||||||||||||
| Component: | Web Template Framework | Assignee: | Daniel Bates <dbates> | ||||||||||||
| Status: | RESOLVED FIXED | ||||||||||||||
| Severity: | Normal | CC: | andersca, benjamin, cdumez, cmarcelo, darin, ews-watchlist, ross.kirsling, saam, webkit-bug-importer | ||||||||||||
| Priority: | P2 | Keywords: | InRadar | ||||||||||||
| Version: | WebKit Nightly Build | ||||||||||||||
| Hardware: | All | ||||||||||||||
| OS: | All | ||||||||||||||
| See Also: | https://bugs.webkit.org/show_bug.cgi?id=188244 | ||||||||||||||
| Attachments: |
|
||||||||||||||
|
Description
Daniel Bates
2018-07-24 13:43:55 PDT
The issue is that the NeverDestroyed move constructor is moving the passed NeverDestroyed object instead of the underlying storage when placement-newing T. As a result, the compiler implicitly converts the to-be-moved-from NeverDestroyed to const T& and invokes T's copy constructor. I suspect the reason this does not effect Windows is because MS Visual Studio has a more aggressive optimizer that elides the call to the NeverDestroyed move constructor. Such aggressive eliding is allowed to be performed even if the move constructor has side effects in C++14, but not required. As of C++17 such an optimization is required by all compiler writers and is consistent with my observation that I do not get a compile-time error when compiling the code in comment #0 with clang using C++17. Created attachment 345709 [details]
Patch and tests
Attachment 345709 [details] did not pass style-queue:
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:74: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:77: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:80: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:54: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:74: More than one command on the same line [whitespace/newline] [4]
Total errors found: 5 in 7 files
If any of these errors are false positives, please file a bug against check-webkit-style.
Created attachment 345710 [details]
Patch and tests
Created attachment 345712 [details]
Patch and tests
Attachment 345712 [details] did not pass style-queue:
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:74: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:77: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:80: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:54: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:74: More than one command on the same line [whitespace/newline] [4]
Total errors found: 5 in 8 files
If any of these errors are false positives, please file a bug against check-webkit-style.
Created attachment 345715 [details]
Patch and tests
Make move constructing NeverDestroyed<const T> work and add a test.
Attachment 345715 [details] did not pass style-queue:
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:74: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:77: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:80: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:54: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:81: More than one command on the same line [whitespace/newline] [4]
Total errors found: 5 in 8 files
If any of these errors are false positives, please file a bug against check-webkit-style.
Comment on attachment 345715 [details] Patch and tests View in context: https://bugs.webkit.org/attachment.cgi?id=345715&action=review r=me > Tools/ChangeLog:9 > + Fixes an issue where move constructing a NeverDestroyed<T> would always copy construct T into > + the destination storage buffer regardless of whether T is move constructable. For example: Do we really need this changelog copied here too? Created attachment 345716 [details]
Patch and tests
Attachment 345716 [details] did not pass style-queue:
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:74: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:77: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/MoveOnlyLifecycleLogger.cpp:80: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:54: More than one command on the same line [whitespace/newline] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:81: More than one command on the same line [whitespace/newline] [4]
Total errors found: 5 in 8 files
If any of these errors are false positives, please file a bug against check-webkit-style.
(In reply to Saam Barati from comment #10) > > Tools/ChangeLog:9 > > + Fixes an issue where move constructing a NeverDestroyed<T> would always copy construct T into > > + the destination storage buffer regardless of whether T is move constructable. For example: > > Do we really need this changelog copied here too? Will consider writing a more specific description for Tools/ChangeLog. I do not see an issue with duplicating the ChangeLog description in multiple ChangeLog files so long as it is descriptive. I use script commit-log-editor as my Git editor (this is part of the standard WebKit OpenSource Project setup). So, the commit message when I land the change will not contain duplication as commit-log-editor automatically collapses duplicate ChangeLog descriptions to create the commit message. Committed r234179: <https://trac.webkit.org/changeset/234179> It turns out that the two tests checking for... > "construct(name) set-name(x) move-construct(x) destruct(<default>) " ...are failed by MSVC in Debug mode, where "move-construct(x) destruct(<default>) " appears an extra time. (https://build.webkit.org/builders/WinCairo%2064-bit%20WKL%20Debug%20%28Tests%29/builds/703/steps/run-api-tests/logs/stdio) This seems like a valid thing for a compiler to do when optimizations are off though, given that there's an immediately-invoked lambda followed by a makeNeverDestroyed call. What do you think we should do about this? (In reply to Ross Kirsling from comment #16) > It turns out that the two tests checking for... > > "construct(name) set-name(x) move-construct(x) destruct(<default>) " > > ...are failed by MSVC in Debug mode, where "move-construct(x) > destruct(<default>) " appears an extra time. > (https://build.webkit.org/builders/WinCairo%2064- > bit%20WKL%20Debug%20%28Tests%29/builds/703/steps/run-api-tests/logs/stdio) > > This seems like a valid thing for a compiler to do when optimizations are > off though, given that there's an immediately-invoked lambda followed by a > makeNeverDestroyed call. > > What do you think we should do about this? Can we add a compiler-specific result for this test? (In reply to Daniel Bates from comment #17) > (In reply to Ross Kirsling from comment #16) > > It turns out that the two tests checking for... > > > "construct(name) set-name(x) move-construct(x) destruct(<default>) " > > > > ...are failed by MSVC in Debug mode, where "move-construct(x) > > destruct(<default>) " appears an extra time. > > (https://build.webkit.org/builders/WinCairo%2064- > > bit%20WKL%20Debug%20%28Tests%29/builds/703/steps/run-api-tests/logs/stdio) > > > > This seems like a valid thing for a compiler to do when optimizations are > > off though, given that there's an immediately-invoked lambda followed by a > > makeNeverDestroyed call. > > > > What do you think we should do about this? > > Can we add a compiler-specific result for this test? Works for me! Patch submitted: https://bugs.webkit.org/show_bug.cgi?id=188244 |