[cfe-dev] objc++ enhancements for new c++ features

James Gregurich via cfe-dev cfe-dev at lists.llvm.org
Tue Mar 20 14:08:52 PDT 2018



> On Mar 20, 2018, at 3:46 PM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:
> 
> On 20 Mar 2018, at 20:06, James Gregurich <bayoubengalml at mac.com <mailto:bayoubengalml at mac.com>> wrote:
>> 
>> 
>> 
>>> On Mar 20, 2018, at 1:09 PM, David Chisnall <David.Chisnall at cl.cam.ac.uk <mailto:David.Chisnall at cl.cam.ac.uk>> wrote:
>>>> 
>>>> 1) making blocks movable so that they can capture things like unique_ptr<> and still be moved off the stack 
>>> 
>>> This should be relatively simple.  Although the interface is a copy, it is effectively a move operation (it either increments a reference count or modifies the source to use forwarding pointers).  I don’t see why blocks in C++11 or later shouldn’t always use move constructors for __block-qualified variables where available.
>> 
>> What would need to happen to push the concept forward?
> 
> Someone to actually do the work.

I could do it with some hand holding. I have no experience with compiler development or the clang codebase, but pointed in the right direction, I could figure it out.

> 
> Objective-C methods don’t support overloading (with Apple runtimes, at least), so you’d need to generate only one.

which is the answer I expected. One could still manually implement the other if needed.

> 
> Why do you use std:: pointers for this?  Before ARC existed, I created a C++ smart pointer class that just called retain / release. When ARC was introduced, I extended it to use the same functions that ARC uses, so you can use ARC-like smart pointers in a non-ARC codebase.  Is there a reason why you need these to be std::shared / weak pointers, which imply some different semantics?

why roll my own when I can use the standard ones? they work perfectly fine with custom deallocators to call [release] in the non-arc case.

you can't do threading-friendly weak pointers without ARC using only retain/release. Why write some new mechanism when the standard one works fine and makes for wonderfully maintainable code? The only issue remaining is making weak_ptr<> a little smarter to handle ARC correctly.


>> 
>> 
>> https://gist.github.com/bayoubengal/e4877efd84b32fb48b4fb00fb1e4a5c9
> 
> There isn’t enough information in that gist for me to understand what the desired behaviour is.


the idea is to change the compiler to handle the following syntax:


auto tmpCalcuStringLmbda = @lambda( -[cMyClass calculateStringValue:withNumber:]  );


the compiler would automatically generate the following code:


   auto tmpCalcuStringLmbda = [](cMyClass* theObjPtr, NSString* theValue1Ptr, size_t theValue)
   {
      return [theObjPtr calculateStringValue: theValue1Ptr withNumber: theValue];
   };


in essence, the compiler would create a lambda whose signature matches the signature of the selector declaration.  calling the lambda calls the selector passing in the arguments.

once you have a lambda declared, that could be passed to template machinery in the usual way.


> 
> A SEL typed parameter.
> 

that isn't a convenient mechanism as the template machinery has no way to deduce the signature of the method. you end up have to manually cast the IMP. having the compiler handle the type checking on the invocation would be much preferable.







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180320/149078c6/attachment.html>


More information about the cfe-dev mailing list