RE: [perl #129321] [BUG] deepmap can recurse indefinitely under some circumstances
Here's what I found in S32: deepmap multi method deepmap ( @values: Code * --> Any ) multi deepmap ( Code $expression, *@values --> Any ) Like map and duckmap, deepmap evaluates the expression for each of the values you give it. Unlike map and duckmap, an element is considered a value only if it does not do the Iterable role. If the element is iterable, the algorithm recurses to produce an identical structure to its input. Elements that are not iterable are considered leaf values and mapped through the supplied expression. Because deepmap is defined as a recursive implicit loop, loop controls apply only to the current level of the tree. /dogbert17 -Original Message- From: Zoffix Znet via RT [mailto:perl6-bugs-follo...@perl.org] Sent: den 23 september 2016 18:39 To: jan-olof.hen...@bredband.net Subject: [perl #129321] [BUG] deepmap can recurse indefinitely under some circumstances On Tue Sep 20 13:54:33 2016, jan-olof.hen...@bredband.net wrote: > # tested with > > dogbert@dogbert-VirtualBox ~ $ perl6 -v This is Rakudo version > 2016.09-19-g8be36b1 built on MoarVM version 2016.09 implementing Perl > 6.c > > # the following two examples behave quite differently > > dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],4]; dd > @a.duckmap({ $_ ~~ Int ?? $_ !! Any })' # this works as expected > (1, (2, 3), 4) > > dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],"a"]; dd > @a.duckmap({ $_ ~~ Int ?? $_ !! Any })' # this will hang or return > 'Memory allocation failed; could not allocate xx bytes' > > /dogbert17 > I see why the issue occurs, but have no idea what the correct behaviour should be. The docs for .duckmap read "For undefined return values, duckmap will try to descend into the element if that element implements Iterable." but when would an undefined Iterable would ever be descendable? The hang itself happens here: https://github.com/rakudo/rakudo/blob/e12ebb9/src/core/metaops.pm#L685 The Any returned from your condition is undefined, so duckmap calls the block with it again, resulting in an infiniloop. Based on the docs, a check for an Iterable is missing, but it feels wrong to me that we'd be attempting to "descend" into an undefined Iterable :S
[perl #129321] [BUG] deepmap can recurse indefinitely under some circumstances
On Tue Sep 20 13:54:33 2016, jan-olof.hen...@bredband.net wrote: > # tested with > > dogbert@dogbert-VirtualBox ~ $ perl6 -v > This is Rakudo version 2016.09-19-g8be36b1 built on MoarVM version 2016.09 > implementing Perl 6.c > > # the following two examples behave quite differently > > dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],4]; dd > @a.duckmap({ $_ ~~ Int ?? $_ !! Any })' # this works as expected > (1, (2, 3), 4) > > dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],"a"]; dd > @a.duckmap({ $_ ~~ Int ?? $_ !! Any })' # this will hang or return 'Memory > allocation failed; could not allocate xx bytes' > > /dogbert17 > I see why the issue occurs, but have no idea what the correct behaviour should be. The docs for .duckmap read "For undefined return values, duckmap will try to descend into the element if that element implements Iterable." but when would an undefined Iterable would ever be descendable? The hang itself happens here: https://github.com/rakudo/rakudo/blob/e12ebb9/src/core/metaops.pm#L685 The Any returned from your condition is undefined, so duckmap calls the block with it again, resulting in an infiniloop. Based on the docs, a check for an Iterable is missing, but it feels wrong to me that we'd be attempting to "descend" into an undefined Iterable :S
[perl #129321] [BUG] deepmap can recurse indefinitely under some circumstances
# New Ticket Created by Jan-Olof Hendig # Please include the string: [perl #129321] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=129321 > # tested with dogbert@dogbert-VirtualBox ~ $ perl6 -v This is Rakudo version 2016.09-19-g8be36b1 built on MoarVM version 2016.09 implementing Perl 6.c # the following two examples behave quite differently dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],4]; dd @a.duckmap({ $_ ~~ Int ?? $_ !! Any })' # this works as expected (1, (2, 3), 4) dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],"a"]; dd @a.duckmap({ $_ ~~ Int ?? $_ !! Any })' # this will hang or return 'Memory allocation failed; could not allocate xx bytes' /dogbert17