digitalmars.D - Closures issues
- Andrei Khropov (27/27) Jul 22 2006 Hello everybody.
- Andrei Khropov (5/9) Jul 22 2006 I'm sorry, upwards of course
- Walter Bright (3/4) Jul 22 2006 I think it's a 2.0 issue. Adding this won't break 1.0 code, so I don't
- Andrei Khropov (6/11) Jul 22 2006 Thanks for rapid response. Looking forward to see it in 2.0.
- Andrei Khropov (6/24) Jul 24 2006 I recently read that C# 2.0 does that:
Hello everybody. There's a reoccuring issue with closures, i.e. downwards FunArg problem (http://en.wikipedia.org/wiki/Funarg_problem#Downwards_funarg_problem). In simple terms delegates that contain pointer to function that has exited are actually point to some garbage. This leads to UB. So I would like to clarify situation a bit: 1) I.e. should D support full closures (like functional languages do)? Solution is actually simple - allocate local variables that are used by a delegate in a heap object (of course only if it is actually necessary) ( like here: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/39525 ). This will actually enable truly functions as first-class objects and higher-order functions (because we could return delegates from functions) That would be great (IMHO). Of course there are some issues with RAII objects - when should they be destroyed - after frame is collected or delegates should simply be prohibited to use them. 2) If D is not intended to support full closures: 2.1) Prohibit return of delegates with stack frames 2.2) there should be a mechanism to detect this kind of errors (at least in Debug). A sort of garbage collection cycle should be performed at the function exit that detects if there are any delegates that point to this function's stack frame and throws an exception in this case. P.S. I'd like this to be decided before 1.0 comes out. -- AKhropov
Jul 22 2006
Andrei Khropov wrote:Hello everybody. There's a reoccuring issue with closures, i.e. downwards FunArg problemI'm sorry, upwards of course (http://en.wikipedia.org/wiki/Funarg_problem#Upwards_funarg_problem) -- AKhropov
Jul 22 2006
Andrei Khropov wrote:P.S. I'd like this to be decided before 1.0 comes out.I think it's a 2.0 issue. Adding this won't break 1.0 code, so I don't think it'll be a problem.
Jul 22 2006
Walter Bright wrote:Andrei Khropov wrote:Thanks for rapid response. Looking forward to see it in 2.0. But for now some warning/error when we try to return a delegate pointing to a local frame from a function won't hurt. -- AKhropovP.S. I'd like this to be decided before 1.0 comes out.I think it's a 2.0 issue. Adding this won't break 1.0 code, so I don't think it'll be a problem.
Jul 22 2006
Andrei Khropov wrote:Hello everybody. There's a reoccuring issue with closures, i.e. downwards FunArg problem (http://en.wikipedia.org/wiki/Funarg_problem#Downwards_funarg_problem). In simple terms delegates that contain pointer to function that has exited are actually point to some garbage. This leads to UB. So I would like to clarify situation a bit: 1) I.e. should D support full closures (like functional languages do)? Solution is actually simple - allocate local variables that are used by a delegate in a heap object (of course only if it is actually necessary) ( like here: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/39525 ). This will actually enable truly functions as first-class objects and higher-order functions (because we could return delegates from functions)http://msdn.microsoft.com/msdnmag/issues/06/00/C20/default.aspx#S7 Better keep up with the competition... -- AKhropov
Jul 24 2006