RESOLVED FIXED 186526
[Cocoa] Make some RetainPtr refinements to get more ready for ARC
https://bugs.webkit.org/show_bug.cgi?id=186526
Summary [Cocoa] Make some RetainPtr refinements to get more ready for ARC
Darin Adler
Reported 2018-06-11 10:00:57 PDT
[Cocoa] Make some RetainPtr refinements to get more ready for ARC
Attachments
Patch (14.84 KB, patch)
2018-06-11 10:05 PDT, Darin Adler
no flags
Patch (15.21 KB, patch)
2018-06-12 09:20 PDT, Darin Adler
no flags
Patch (15.25 KB, patch)
2018-06-12 09:25 PDT, Darin Adler
ews-watchlist: commit-queue-
Archive of layout-test-results from ews116 for mac-sierra (3.02 MB, application/zip)
2018-06-12 12:24 PDT, EWS Watchlist
no flags
Patch (20.66 KB, patch)
2018-06-12 22:27 PDT, Darin Adler
no flags
Patch (21.23 KB, patch)
2018-06-13 19:47 PDT, Darin Adler
andersca: review+
darin: commit-queue-
Darin Adler
Comment 1 2018-06-11 10:05:45 PDT Comment hidden (obsolete)
Darin Adler
Comment 2 2018-06-11 10:06:27 PDT
As part of review, I’d like feedback on whether I should be adding these new RetainPtr members or not.
Darin Adler
Comment 3 2018-06-12 09:20:38 PDT Comment hidden (obsolete)
Darin Adler
Comment 4 2018-06-12 09:22:51 PDT
I think Anders is probably the one who should review this. New patch fixes const-correctness of cast inside RetainPtr::autoreleaseCF as well as making it work correctly with nullptr, and uses autoreleaseCF in one place in iOS-specific code that I had missed in WebKitLegacy.
Darin Adler
Comment 5 2018-06-12 09:25:40 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 6 2018-06-12 12:24:54 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 7 2018-06-12 12:24:55 PDT Comment hidden (obsolete)
Darin Adler
Comment 8 2018-06-12 22:27:34 PDT Comment hidden (obsolete)
Anders Carlsson
Comment 9 2018-06-13 08:20:49 PDT
Comment on attachment 342632 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=342632&action=review > Source/WTF/ChangeLog:13 > + * wtf/RetainPtr.h: Added autoreleaseCF and bridgingAutorelease. > + The existing autorelease is for autorelease of an Objective-C type. > + The two new ones are for autorelease of CF types: We can use > + autoreleaseCF when we want an autoreleased CF type, and we can > + use bridgingAutorelease when we want to autorelease as part of > + converting from a CF type to an Objective-C type. I think these (autoreleaseCF anyway) adds some confusion. Would it be possible to use std::enable_if to just pick the right autorelease based on the type?
Darin Adler
Comment 10 2018-06-13 09:20:37 PDT
(In reply to Anders Carlsson from comment #9) > I think these (autoreleaseCF anyway) adds some confusion. Would it be > possible to use std::enable_if to just pick the right autorelease based on > the type? I don’t know; I’ll try.
Darin Adler
Comment 11 2018-06-13 19:47:39 PDT
EWS Watchlist
Comment 12 2018-06-13 19:50:36 PDT
Attachment 342720 [details] did not pass style-queue: ERROR: Source/WTF/wtf/RetainPtr.h:194: This { should be at the end of the previous line [whitespace/braces] [4] ERROR: Source/WTF/wtf/RetainPtr.h:199: This { should be at the end of the previous line [whitespace/braces] [4] Total errors found: 2 in 21 files If any of these errors are false positives, please file a bug against check-webkit-style.
Darin Adler
Comment 13 2018-06-13 19:51:09 PDT
Comment on attachment 342720 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=342720&action=review > Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm:147 > +#if 0 && (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED == 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED == 120000) Oops, did not mean to post patch with this in it.
Darin Adler
Comment 14 2018-06-13 20:07:59 PDT
(In reply to Anders Carlsson from comment #9) > Would it be > possible to use std::enable_if to just pick the right autorelease based on > the type? Yes, I did this in the latest patch, which no longer adds autoreleaseCF.
Anders Carlsson
Comment 15 2018-06-16 09:33:18 PDT
Comment on attachment 342720 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=342720&action=review > Source/WTF/wtf/RetainPtr.h:150 > +#ifdef __OBJC__ > + template<typename U> typename std::enable_if<std::is_convertible<U, id>::value, PtrType>::type autoreleaseHelper(); > + template<typename U> typename std::enable_if<!std::is_convertible<U, id>::value, PtrType>::type autoreleaseHelper(); > +#endif You can use std::enable_if_t here, and if WebKit requires C++17 you should be able to use std::is_convertible_v as well.
Darin Adler
Comment 16 2018-06-16 21:16:25 PDT
Comment on attachment 342720 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=342720&action=review >> Source/WTF/wtf/RetainPtr.h:150 >> +#endif > > You can use std::enable_if_t here, and if WebKit requires C++17 you should be able to use std::is_convertible_v as well. Great, thanks for the suggestion. I will switch to those and retest before landing. Roughly speaking, WebKit does require C++17 now, but there are many exceptions to that general rule. However, since this is ObjC-only code, all that really matters is the level of support we have in clang with the option we specify (which is now C++17) and we don’t need to worry about gcc or MSVC for this code.
Darin Adler
Comment 17 2018-06-16 23:54:31 PDT
Radar WebKit Bug Importer
Comment 18 2018-06-16 23:55:25 PDT
Darin Adler
Comment 19 2018-06-16 23:59:55 PDT
I was unable to use std::is_convertible_v at this time because we are not yet passing in C++17 as our dialect for clang.
Note You need to log in before you can comment on or make changes to this bug.