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

Binding a variable at BEGIN time doesn't stick aruond for runtime #3676

Open
p6rt opened this issue Feb 10, 2015 · 7 comments
Open

Binding a variable at BEGIN time doesn't stick aruond for runtime #3676

p6rt opened this issue Feb 10, 2015 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Feb 10, 2015

Migrated from rt.perl.org#123776 (status was 'open')

Searchable as RT123776$

@p6rt
Copy link
Author

p6rt commented Feb 10, 2015

From @raydiak

m​: my $a; BEGIN { $a := 1; say $a; }; say $a;
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤(Any)␤»

m​: my $a; BEGIN { $a = 1; say $a; }; say $a; # works with assignment
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤1␤»

@p6rt
Copy link
Author

p6rt commented Dec 1, 2017

From @AlexDaniel

Still reproducible (2017.11, HEAD(5929887)), but is supposed to work?

On 2015-02-09 17​:43​:52, raydiak@​cyberuniverses.com wrote​:

m​: my $a; BEGIN { $a := 1; say $a; }; say $a;
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤(Any)␤»

m​: my $a; BEGIN { $a = 1; say $a; }; say $a; # works with assignment
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤1␤»

@p6rt
Copy link
Author

p6rt commented Dec 1, 2017

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

@p6rt
Copy link
Author

p6rt commented Jan 30, 2018

From @zoffixznet

On Fri, 01 Dec 2017 12​:09​:05 -0800, alex.jakimenko@​gmail.com wrote​:

Still reproducible (2017.11, HEAD(5929887)), but is supposed to work?

Don't see any reason why that'd be questionable.

On 2015-02-09 17​:43​:52, raydiak@​cyberuniverses.com wrote​:

m​: my $a; BEGIN { $a := 1; say $a; }; say $a;
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤(Any)␤»

m​: my $a; BEGIN { $a = 1; say $a; }; say $a; # works with assignment
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤1␤»

Another manifestation of the same bug​:

<Zoffix__> m​: BEGIN { my $a1 := 42; say $a1; }
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN { my $a1 = 42; say $a1; }
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN my $a1 = 42; say $a1;
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN my $a1 := 42; say $a1;
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «(Mu)␤»

@p6rt
Copy link
Author

p6rt commented Jan 31, 2018

From @zoffixznet

On Tue, 30 Jan 2018 15​:08​:38 -0800, cpan@​zoffix.com wrote​:

On Fri, 01 Dec 2017 12​:09​:05 -0800, alex.jakimenko@​gmail.com wrote​:

Still reproducible (2017.11, HEAD(5929887)), but is supposed to work?

Don't see any reason why that'd be questionable.

On 2015-02-09 17​:43​:52, raydiak@​cyberuniverses.com wrote​:

m​: my $a; BEGIN { $a := 1; say $a; }; say $a;
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤(Any)␤»

m​: my $a; BEGIN { $a = 1; say $a; }; say $a; # works with assignment
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤1␤»

Another manifestation of the same bug​:

<Zoffix__> m​: BEGIN { my $a1 := 42; say $a1; }
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN { my $a1 = 42; say $a1; }
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN my $a1 = 42; say $a1;
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN my $a1 := 42; say $a1;
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «(Mu)␤»

Tracked this to Perl6​::World.compile_in_context but leaving it there, as it's getting too hard.
Need to gain a few levels first.

The comment in the method reads​:
  # Create outer lexical contexts with all symbols visible. Maybe
  # we can be a bit smarter here some day. But for now we just make a
  # single frame and copy all the visible things into it.

So I imagine the binding gets made to this faked out block and never propagates back to the source where all the lexicals were copied from.

@p6rt
Copy link
Author

p6rt commented Feb 2, 2018

From @zoffixznet

On Tue, 30 Jan 2018 19​:03​:13 -0800, cpan@​zoffix.com wrote​:

On Tue, 30 Jan 2018 15​:08​:38 -0800, cpan@​zoffix.com wrote​:

On Fri, 01 Dec 2017 12​:09​:05 -0800, alex.jakimenko@​gmail.com wrote​:

Still reproducible (2017.11, HEAD(5929887)), but is supposed to
work?

Don't see any reason why that'd be questionable.

On 2015-02-09 17​:43​:52, raydiak@​cyberuniverses.com wrote​:

m​: my $a; BEGIN { $a := 1; say $a; }; say $a;
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤(Any)␤»

m​: my $a; BEGIN { $a = 1; say $a; }; say $a; # works with
assignment
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤1␤»

Another manifestation of the same bug​:

<Zoffix__> m​: BEGIN { my $a1 := 42; say $a1; }
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN { my $a1 = 42; say $a1; }
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN my $a1 = 42; say $a1;
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN my $a1 := 42; say $a1;
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «(Mu)␤»

Tracked this to Perl6​::World.compile_in_context but leaving it there,
as it's getting too hard.
Need to gain a few levels first.

The comment in the method reads​:
# Create outer lexical contexts with all symbols visible. Maybe
# we can be a bit smarter here some day. But for now we just make a
# single frame and copy all the visible things into it.

So I imagine the binding gets made to this faked out block and never
propagates back to the source where all the lexicals were copied from.

More comments​: https://irclog.perlgeek.de/perl6/2018-02-02#i_15769787

15​:11 jnthn Zoffix​: Yeah. Lexpads are immutable, and when we compile a BEGIN we obviously haven't finished the outer block yet, so we have to fake something up. But what? Containers are cloned from a "prototype", and the fake lexpad contains the static container. Thus what's actually happening is that on entry to the scope post-compilation, the Scalar is cloned complete with the value set in the prototype.
15​:12 Of course, binding doesn't have that level of indirection so there's no way it can work.
15​:12 We should perhaps detect it at compile time and say it can't work. Or...we could try diffing the scope after each BEGIN block and trying to somehow propagate bindings.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Feb 2, 2018

From @zoffixznet

On Tue, 30 Jan 2018 19​:03​:13 -0800, cpan@​zoffix.com wrote​:

On Tue, 30 Jan 2018 15​:08​:38 -0800, cpan@​zoffix.com wrote​:

On Fri, 01 Dec 2017 12​:09​:05 -0800, alex.jakimenko@​gmail.com wrote​:

Still reproducible (2017.11, HEAD(5929887)), but is supposed to
work?

Don't see any reason why that'd be questionable.

On 2015-02-09 17​:43​:52, raydiak@​cyberuniverses.com wrote​:

m​: my $a; BEGIN { $a := 1; say $a; }; say $a;
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤(Any)␤»

m​: my $a; BEGIN { $a = 1; say $a; }; say $a; # works with
assignment
rakudo-{parrot,moar} 0cb22e​: OUTPUT«1␤1␤»

Another manifestation of the same bug​:

<Zoffix__> m​: BEGIN { my $a1 := 42; say $a1; }
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN { my $a1 = 42; say $a1; }
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN my $a1 = 42; say $a1;
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «42␤»
<Zoffix__> m​: BEGIN my $a1 := 42; say $a1;
<camelia> rakudo-moar deffe54b8​: OUTPUT​: «(Mu)␤»

Tracked this to Perl6​::World.compile_in_context but leaving it there,
as it's getting too hard.
Need to gain a few levels first.

The comment in the method reads​:
# Create outer lexical contexts with all symbols visible. Maybe
# we can be a bit smarter here some day. But for now we just make a
# single frame and copy all the visible things into it.

So I imagine the binding gets made to this faked out block and never
propagates back to the source where all the lexicals were copied from.

More comments​: https://irclog.perlgeek.de/perl6/2018-02-02#i_15769787

15​:11 jnthn Zoffix​: Yeah. Lexpads are immutable, and when we compile a BEGIN we obviously haven't finished the outer block yet, so we have to fake something up. But what? Containers are cloned from a "prototype", and the fake lexpad contains the static container. Thus what's actually happening is that on entry to the scope post-compilation, the Scalar is cloned complete with the value set in the prototype.
15​:12 Of course, binding doesn't have that level of indirection so there's no way it can work.
15​:12 We should perhaps detect it at compile time and say it can't work. Or...we could try diffing the scope after each BEGIN block and trying to somehow propagate bindings.

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