Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Brady Eidson
> On Jun 13, 2017, at 12:37 PM, Alex Christensen wrote: > > I’d be opposed to adding a copy constructor to WTF::Function because the > non-copyability of WTF::Function is why we made it, and it has prevented many > bugs. Ditto. The lack of a copy c’tor in WTF::Function turns the compiler int

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Filip Pizlo
> On Jun 13, 2017, at 1:00 PM, Chris Dumez wrote: > > >> On Jun 13, 2017, at 12:51 PM, Filip Pizlo > > wrote: >> >>> >>> On Jun 13, 2017, at 12:37 PM, Alex Christensen >> > wrote: >>> >>> Ok, maybe we can get rid of std::function, then!

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Chris Dumez
> On Jun 13, 2017, at 12:51 PM, Filip Pizlo wrote: > >> >> On Jun 13, 2017, at 12:37 PM, Alex Christensen > > wrote: >> >> Ok, maybe we can get rid of std::function, then! I hadn’t used BlockPtr as >> much as Chris. I’d be opposed to adding a copy constructor

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Filip Pizlo
> On Jun 13, 2017, at 12:37 PM, Alex Christensen wrote: > > Ok, maybe we can get rid of std::function, then! I hadn’t used BlockPtr as > much as Chris. I’d be opposed to adding a copy constructor to WTF::Function > because the non-copyability of WTF::Function is why we made it, and it has >

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Alex Christensen
Ok, maybe we can get rid of std::function, then! I hadn’t used BlockPtr as much as Chris. I’d be opposed to adding a copy constructor to WTF::Function because the non-copyability of WTF::Function is why we made it, and it has prevented many bugs. I’ve also seen many cases where I have a WTF::

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Chris Dumez
We already have BlockPtr for passing a Function as a lambda block. Chris Dumez > On Jun 13, 2017, at 12:29 PM, Alex Christensen wrote: > > std::function, c++ lambda, and objc blocks are all interchangeable. > WTF::Functions cannot be used as objc blocks because the latter must be > copyable.

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Filip Pizlo
And ObjC blocks share instead of copying, which is more like SharedTask. I think that’s another reason why adding copy constructors to WTF::Function that do block-like sharing under the hood is rather attractive. -Filip > On Jun 13, 2017, at 12:29 PM, Alex Christensen wrote: > > std::functi

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Alex Christensen
std::function, c++ lambda, and objc blocks are all interchangeable. WTF::Functions cannot be used as objc blocks because the latter must be copyable. Until that changes or we stop using objc, we cannot completely eliminate std::function from WebKit.

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Filip Pizlo
> On Jun 13, 2017, at 11:56 AM, Brady Eidson wrote: > >> >> On Jun 13, 2017, at 9:55 AM, Filip Pizlo > > wrote: >> >> Would SharedTask’s sharing be semantically incorrect for users of >> WTF::Function? In other words, do you rely on the compiler error that says >> t

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Brady Eidson
> On Jun 13, 2017, at 9:55 AM, Filip Pizlo wrote: > > Would SharedTask’s sharing be semantically incorrect for users of > WTF::Function? In other words, do you rely on the compiler error that says > that there is no copy constructor? WTF::Function is used in cross-thread dispatching, where

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Filip Pizlo
I like these renamings. I’m also ok with renaming Function to UniqueFunction but I’m also ok with keeping the current name. -Filip > On Jun 13, 2017, at 10:12 AM, Konstantin Tokarev wrote: > > > > 13.06.2017, 20:08, "Maciej Stachowiak" : >> In case it turns out not to be possible to reduce

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Konstantin Tokarev
13.06.2017, 20:08, "Maciej Stachowiak" : > In case it turns out not to be possible to reduce the number of concepts > (besides eliminating std::function), maybe it would help to change the names > and behaviors of these classes to match better. Function, SharedFunction and > ScopedFunction wou

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Maciej Stachowiak
In case it turns out not to be possible to reduce the number of concepts (besides eliminating std::function), maybe it would help to change the names and behaviors of these classes to match better. Function, SharedFunction and ScopedFunction would have a much more obvious relationship to each o

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Filip Pizlo
Would SharedTask’s sharing be semantically incorrect for users of WTF::Function? In other words, do you rely on the compiler error that says that there is no copy constructor? I’m imagining that if WTF::Function was backed by SharedTask that it would not result in any behavior change for exist

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Chris Dumez
In most cases in WebCore at least, we don’t actually want to share ownership of the lambda so we don’t need RefCounting / SharedTask. Because of this, I don’t think we should merge SharedTask into Function. I think that as it stands, WTF::Function is a suitable replacement for most uses in WebCo

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Filip Pizlo
We should have a better story here. Right now the story is too complicated. We have: - ScopedLambda or ScopedLambdaRef if you have a stack-allocated function that outlives its user - SharedTask if you have a heap-allocated function that you want to share and ref-count - WTF::Function if you h

Re: [webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Chris Dumez
The only advantage of std::function that I know of is that it is copyable. Unless you really need to copy your lambda for a reason or another, I don’t see a good reason to ever use std::function instead of WTF::Function. I have been slowly replacing std::function by WTF::Function in the code bas

[webkit-dev] Should we ever use std::function instead of WTF::Function?

2017-06-13 Thread Darin Adler
I’ve noticed many patches switching us from std::function to WTF::Function recently, to fix problems with copying and thread safety. Does std::function have any advantages over WTF::Function? Should we ever prefer std::function, or should we use WTF::Function everywhere in WebKit where we would