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

Lexical weirdness from blocks inside re-entrant subs in Rakudo #2628

Closed
p6rt opened this issue Jan 29, 2012 · 11 comments
Closed

Lexical weirdness from blocks inside re-entrant subs in Rakudo #2628

p6rt opened this issue Jan 29, 2012 · 11 comments

Comments

@p6rt
Copy link

p6rt commented Jan 29, 2012

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

Searchable as RT109322$

@p6rt
Copy link
Author

p6rt commented Jan 29, 2012

From @masak

<Radvendii> is it *remotely* possible that given $i {} is changing the
value of $i?
<masak> nom​: my $i = 5; given $i { $_ = 42 }; say $i
<p6eval> nom 9719f7​: OUTPUT«42␤»
<Radvendii> that's not what i'm saying
<Radvendii> nom​: my $i=5; $i.say; given $i { $i.say};
<p6eval> nom 9719f7​: OUTPUT«5␤5␤»
<Radvendii> and those two are different in my program
<Radvendii> feel free to golf a short example of it.
<Radvendii> masak​: i'll try...
<Radvendii> YAY
<Radvendii> masak​: i distilled the error down
<Radvendii> nom​: sub foo ($a, $f) { if $f { foo('z', 0) }; given $a
{say $a; say $_} }; foo('x', 1)
<p6eval> nom 9719f7​: OUTPUT«z␤z␤z␤x␤»
<masak> Radvendii++
<masak> that is the real deal.
* masak submits rakudobug
<Radvendii> masak​: yay :D
<moritz> perl6​: sub foo ($a, $f) { if $f { foo('z', 0) }; given $a
{say $a; say $_} }; foo('x', 1)
<p6eval> rakudo 9719f7​: OUTPUT«z␤z␤z␤x␤»
<p6eval> ..pugs b927740, niecza v13-381-g4158fa9​: OUTPUT«z␤z␤x␤x␤»
* masak is surprised we still have this kind of lexpad bug
* Radvendii assumes lexpad has to do with lexical scopes?
<moritz> yes
<Radvendii> cool
<masak> Radvendii​: if I had to guess, what you're seeing is the given
block anchoring to the lexpad of the first invocation, and then when
the lookup for $a is done in the second invocation, it finds the wrong
-- the old -- OUTER for the given block.
<masak> at least that's a hypothesis consistent with the data.

@p6rt
Copy link
Author

p6rt commented Jan 29, 2012

From @masak

<Radvendii> nom​: sub foo ($a, $f) { if $f { foo('z', 0) }; {$_=$a; say
$a; say $_} }; foo('x', 1) #does it work explicitly?
<p6eval> nom 9719f7​: OUTPUT«z␤z␤z␤z␤»
<Radvendii> ooh. that's even worse...
<masak> Radvendii​: but it has exactly the same cause.
<Radvendii> masak​: yup... i just realized that
<Radvendii> i thought it maybe had to do with the "given" statement
itself
<masak> me too.
<masak> no, it's just blocks inside reentrant blocks.
* masak updates ticket

@p6rt
Copy link
Author

p6rt commented Jan 29, 2012

From [Unknown Contact. See original ticket]

<Radvendii> nom​: sub foo ($a, $f) { if $f { foo('z', 0) }; {$_=$a; say
$a; say $_} }; foo('x', 1) #does it work explicitly?
<p6eval> nom 9719f7​: OUTPUT«z␤z␤z␤z␤»
<Radvendii> ooh. that's even worse...
<masak> Radvendii​: but it has exactly the same cause.
<Radvendii> masak​: yup... i just realized that
<Radvendii> i thought it maybe had to do with the "given" statement
itself
<masak> me too.
<masak> no, it's just blocks inside reentrant blocks.
* masak updates ticket

@p6rt
Copy link
Author

p6rt commented Jan 29, 2012

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jan 29, 2012

From @masak

<Radvendii> nom​: sub foo ($a, $f) { if $f { foo('z', 0) }; {$_=$a; say
$a; say $_} }; foo('x', 1) #does it work explicitly?
<p6eval> nom 9719f7​: OUTPUT«z␤z␤z␤z␤»
<Radvendii> ooh. that's even worse...
<masak> Radvendii​: but it has exactly the same cause.
<Radvendii> masak​: yup... i just realized that
<Radvendii> i thought it maybe had to do with the "given" statement
itself
<masak> me too.
<masak> no, it's just blocks inside reentrant blocks.
* masak updates ticket

@p6rt
Copy link
Author

p6rt commented Jan 29, 2012

From [Unknown Contact. See original ticket]

<Radvendii> nom​: sub foo ($a, $f) { if $f { foo('z', 0) }; {$_=$a; say
$a; say $_} }; foo('x', 1) #does it work explicitly?
<p6eval> nom 9719f7​: OUTPUT«z␤z␤z␤z␤»
<Radvendii> ooh. that's even worse...
<masak> Radvendii​: but it has exactly the same cause.
<Radvendii> masak​: yup... i just realized that
<Radvendii> i thought it maybe had to do with the "given" statement
itself
<masak> me too.
<masak> no, it's just blocks inside reentrant blocks.
* masak updates ticket

@p6rt
Copy link
Author

p6rt commented Jun 18, 2015

From @usev6

The first example works now as expected​:

$ perl6-m -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; given $a {say $a; say $_} }; foo("x", 1)'
z
z
x
x

The second example works on rakudo.jvm but fails on rakudo.moar​:

$ perl6-j -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; {$_=$a; say $a; say $_} }; foo("x", 1)'
z
z
x
x

$ perl6-m -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; {$_=$a; say $a; say $_} }; foo("x", 1)'
z
z
z
z

I added two tests (the second fudged 'todo' for Moar) to S06-advanced/lexical-subs.t with commit Raku/roast@0867f11ce3

1 similar comment
@p6rt
Copy link
Author

p6rt commented Jun 18, 2015

From @usev6

The first example works now as expected​:

$ perl6-m -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; given $a {say $a; say $_} }; foo("x", 1)'
z
z
x
x

The second example works on rakudo.jvm but fails on rakudo.moar​:

$ perl6-j -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; {$_=$a; say $a; say $_} }; foo("x", 1)'
z
z
x
x

$ perl6-m -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; {$_=$a; say $a; say $_} }; foo("x", 1)'
z
z
z
z

I added two tests (the second fudged 'todo' for Moar) to S06-advanced/lexical-subs.t with commit Raku/roast@0867f11ce3

@p6rt
Copy link
Author

p6rt commented Jun 19, 2015

From @masak

A bit late to the game, but...

<masak> here's a shorter version​:
<masak> m​: my $y = 1; sub foo($x) { $y-- && foo("z"); { say $x } }; foo("x")
<camelia> rakudo-moar d179b4​: OUTPUT«z␤z␤»
<masak> again, should say "z␤x␤"
* masak adds the example to RT #​109322

@p6rt
Copy link
Author

p6rt commented Jun 19, 2015

From @jnthn

On Thu Jun 18 13​:49​:36 2015, bartolin@​gmx.de wrote​:

The first example works now as expected​:

$ perl6-m -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; given $a {say
$a; say $_} }; foo("x", 1)'
z
z
x
x

The second example works on rakudo.jvm but fails on rakudo.moar​:

$ perl6-j -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; {$_=$a; say
$a; say $_} }; foo("x", 1)'
z
z
x
x

$ perl6-m -e 'sub foo ($a, $f) { if $f { foo("z", 0) }; {$_=$a; say
$a; say $_} }; foo("x", 1)'
z
z
z
z

I added two tests (the second fudged 'todo' for Moar) to S06-
advanced/lexical-subs.t with commit
Raku/roast@0867f11ce3

After a fix, the test now passes on MoarVM too. Unfudged it.

@p6rt
Copy link
Author

p6rt commented Jun 19, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant