Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursion and for loops interact badly in Rakudo #284

Closed
p6rt opened this issue Aug 27, 2008 · 14 comments
Closed

Recursion and for loops interact badly in Rakudo #284

p6rt opened this issue Aug 27, 2008 · 14 comments

Comments

@p6rt
Copy link

p6rt commented Aug 27, 2008

Migrated from rt.perl.org#58392 (status was 'resolved')

Searchable as RT58392$

@p6rt
Copy link
Author

p6rt commented Aug 27, 2008

From @masak

r30589​:
$ cat for-loop-recursion.bug
sub f($l) {
  return() if $l <= 0;
  say "entering $l";
  for 1..3 {
  f($l-1);
  say "looping in $l";
  }
}
f(2);

$ ./perl6 for-loop-recursion.bug
entering 2
entering 1
looping in 1
looping in 0
looping in -1
looping in 2
looping in -2
looping in -3

Something to do with local pads, perhaps?

FWIW, I can trace the bug back to r29884, the first revision that
gives any output at all on the above script.

Here's a Perl 5 comparison​:

$ cat for-loop-recursion.p5
use strict;
use warnings;

sub f {
  my $l = shift;
  return if $l <= 0;
  print "entering $l\n";
  for (1..3) {
  f($l-1);
  print "looping in $l\n";
  }
}
f(2);

$ perl for-loop-recursion.p5
entering 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2

@p6rt
Copy link
Author

p6rt commented Aug 27, 2008

From @moritz

Carl MXXsak (via RT) wrote​:

r30589​:
$ cat for-loop-recursion.bug
sub f($l) {
return() if $l <= 0;
say "entering $l";
for 1..3 {
f($l-1);
say "looping in $l";
}
}
f(2);

I re-worked that as a test and added it to t/spec/S04-statements/for.t

Moritz
--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/

@p6rt
Copy link
Author

p6rt commented Aug 27, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 3, 2008

From @chromatic

On Wednesday 27 August 2008 07​:26​:00 Moritz Lenz wrote​:

Carl MXXsak (via RT) wrote​:

r30589​:
$ cat for-loop-recursion.bug
sub f($l) {
return() if $l <= 0;
say "entering $l";
for 1..3 {
f($l-1);
say "looping in $l";
}
}
f(2);

I re-worked that as a test and added it to t/spec/S04-statements/for.t

If you or Carl can provide a PIR program which exhibits he problem, I'll fix
it.

-- c

@p6rt
Copy link
Author

p6rt commented Sep 3, 2008

From @masak

Attaching stripped-down PIR code -- this may or may not be what you
requested, chromatic. (There are still a few Rakudo dependencies left in
the PIR code. But these are all simple things, so people more versed in
PIR might be able to remove these.)

We can run it through Rakudo as follows​:

$ ./perl6 -e 'use recbug'

and it produces as output

2
1

when it should really be producing

2
1
1
1

@p6rt
Copy link
Author

p6rt commented Sep 3, 2008

From @masak

recbug.pir

@p6rt
Copy link
Author

p6rt commented Sep 4, 2008

From @pmichaud

On Wed, Sep 03, 2008 at 11​:22​:42AM -0700, chromatic wrote​:

On Wednesday 27 August 2008 07​:26​:00 Moritz Lenz wrote​:

Carl MXXsak (via RT) wrote​:

r30589​:
$ cat for-loop-recursion.bug
sub f($l) {
return() if $l <= 0;
say "entering $l";
for 1..3 {
f($l-1);
say "looping in $l";
}
}
f(2);

I re-worked that as a test and added it to t/spec/S04-statements/for.t

If you or Carl can provide a PIR program which exhibits he problem, I'll fix
it.

As of r37064, it's now possible to do this using the --target=pir
option to rakudo​:

  $ cat for-loop-recursion.bug
  sub f($l) {
  return() if $l <= 0;
  say "entering $l";
  for 1..3 {
  f($l-1);
  say "looping in $l";
  }
  }
  f(2);
 
 
  $ ./parrot perl6.pbc --target=pir --output=for.pir for-loop-recursion.bug
  $ ./parrot for.pir
  entering 2
  entering 1
  looping in 1
  looping in 0
  looping in -1
  looping in 2
  looping in -2
  looping in -3
  $

Currently the perl6.pbc has to be somewhere where load_bytecode can
find it (current directory or runtime/parrot/library) -- I'm still
thinking about RT #​47992 before deciding when/how I want it to be
installed somewhere.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 4, 2008

From @pmichaud

On Thu, Sep 04, 2008 at 02​:25​:45PM -0500, Patrick R. Michaud wrote​:

As of r37064, it's now possible to do this using the --target=pir
option to rakudo​:

[...]

Also, it may be worth adding judicious calls to parrot_trace(1)
(a rakudo built-in function) to enable/disable tracing at
appropriate points in the code.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 11, 2008

From @jnthn

Hi,

Here is a pure PIR example that doesn't depend on Rakudo at all.

.sub main :main
  $P0 = new 'Integer'
  $P0 = 2
  'f'($P0)
.end

.sub 'f'
  .param pmc l
  .lex "$l", l
  $P0 = find_lex "$l"
  if $P0 <= 0 goto ret

  print "entering "
  $P1 = find_lex "$l"
  say $P1

  $I0 = 1
  for​:
  if $I0 > 3 goto for_end
  '_block1'()
  inc $I0
  goto for
  for_end​:
  ret​:
.end

.sub '_block1' :outer('f')
  $P2 = find_lex "$l"
  $P3 = new 'Integer'
  $P3 = $P2 - 1
  'f'($P3)
  print "looping in "
  $P4 = find_lex "$l"
  say $P4
.end

Gives the same erroneous output as the Rakudo program.

Jonathan

@p6rt
Copy link
Author

p6rt commented Oct 24, 2008

From @ilyabelikin

Hi there!
First of all, please, excuse my bad English. Again :)

This bug still there, in spate of two stable realize of the Parrot.
It`s block our progress on the HTML​::Template porting in November
project and correct realization of is_deeply in our Test.pm :(
Unfortunately I am not pir or C or anything but Perl programmer(not
the professional one). I can wright test for that if need.

If any one have time and can help with that, please annihilate that pesky bug.

Thank you!

Ilya

2008/9/12 jnthn@​jnthn.net via RT <perl6-bugs-followup@​perl.org>​:

Hi,

Here is a pure PIR example that doesn't depend on Rakudo at all.

.sub main :main
$P0 = new 'Integer'
$P0 = 2
'f'($P0)
.end

.sub 'f'
.param pmc l
.lex "$l", l
$P0 = find_lex "$l"
if $P0 <= 0 goto ret

print "entering "
$P1 = find_lex "$l"
say $P1

$I0 = 1
for​:
if $I0 > 3 goto for_end
'_block1'()
inc $I0
goto for
for_end​:
ret​:
.end

.sub '_block1' :outer('f')
$P2 = find_lex "$l"
$P3 = new 'Integer'
$P3 = $P2 - 1
'f'($P3)
print "looping in "
$P4 = find_lex "$l"
say $P4
.end

Gives the same erroneous output as the Rakudo program.

Jonathan

@p6rt
Copy link
Author

p6rt commented Oct 24, 2008

From @moritz

Ð�лÑ�Ñ� wrote​:

Hi there!
First of all, please, excuse my bad English. Again :)

This bug still there, in spate of two stable realize of the Parrot.
It`s block our progress on the HTML​::Template porting in November
project and correct realization of is_deeply in our Test.pm :(
Unfortunately I am not pir or C or anything but Perl programmer(not
the professional one). I can wright test for that if need.

If any one have time and can help with that, please annihilate that pesky bug.

To the best of my knowledge Patrick is working on this one on a branch
called `lex'.

Cheers,
Moritz

--
Moritz Lenz
http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/

@p6rt
Copy link
Author

p6rt commented Nov 25, 2008

From @pmichaud

Now fixed in r33193​:

$ cat 58392
sub f($l) {
  return() if $l <= 0;
  say "entering $l";
  for 1..3 {
  f($l-1);
  say "looping in $l";
  }
}
f(2);
$ ./parrot perl6.pbc 58392
entering 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2
$

Thanks,

Pm

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 25, 2008

From @pmichaud

Now fixed in r33193​:

$ cat 58392
sub f($l) {
  return() if $l <= 0;
  say "entering $l";
  for 1..3 {
  f($l-1);
  say "looping in $l";
  }
}
f(2);
$ ./parrot perl6.pbc 58392
entering 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2
entering 1
looping in 1
looping in 1
looping in 1
looping in 2
$

Thanks,

Pm

@p6rt
Copy link
Author

p6rt commented Nov 25, 2008

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Nov 25, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant