Skip Menu |
Report information
Id: 126900
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: zefram [at] fysh.org
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] assignment to native-typed variable fails in repl
Date: Sun, 13 Dec 2015 20:25:39 +0000
From: Zefram <zefram [...] fysh.org>
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 355b
At the REPL top level, post-init assignment to a native-typed variable fails: Show quoted text
> my int $a = 3
3 Show quoted text
> $a = 4
Cannot find method 'qast' Show quoted text
> my int $i
0 Show quoted text
> $i = 3
Cannot find method 'qast' But it works fine in other situations: Show quoted text
> sub foo() { my int $a; $a = 3 }
sub foo () { #`(Sub|53233744) ... } Show quoted text
> foo()
3 $ perl6 -e 'my int $i; $i = 3; say $i' 3 -zefram
To: perl6-compiler [...] perl.org, bugs-bitbucket [...] rt.perl.org
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Date: Mon, 14 Dec 2015 02:10:50 +0000
Subject: Re: [perl #126900] [BUG] assignment to native-typed variable fails in repl
Download (untitled) / with headers
text/plain 792b
You can gold this down to:

perl6 -e 'my int $a = 3; EVAL q|$a = 4|'

#!>Cannot find method 'qast'


On Mon, Dec 14, 2015 at 7:26 AM Zefram <perl6-bugs-followup@perl.org> wrote:
Show quoted text
# New Ticket Created by  Zefram
# Please include the string:  [perl #126900]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=126900 >


At the REPL top level, post-init assignment to a native-typed variable
fails:

> my int $a = 3
3
> $a = 4
Cannot find method 'qast'
> my int $i
0
> $i = 3
Cannot find method 'qast'

But it works fine in other situations:

> sub foo() { my int $a; $a = 3 }
sub foo () { #`(Sub|53233744) ... }
> foo()
3

$ perl6 -e 'my int $i; $i = 3; say $i'
3

-zefram
Download (untitled) / with headers
text/plain 955b
Looks related to RT #127933. On 2015-12-13 18:11:39, lloyd.fourn@gmail.com wrote: Show quoted text
> You can gold this down to: > > perl6 -e 'my int $a = 3; EVAL q|$a = 4|' > > #!>Cannot find method 'qast' > > On Mon, Dec 14, 2015 at 7:26 AM Zefram <perl6-bugs-followup@perl.org> wrote: >
> > # New Ticket Created by Zefram > > # Please include the string: [perl #126900] > > # in the subject line of all future correspondence about this issue. > > # <URL: https://rt.perl.org/Ticket/Display.html?id=126900 > > > > > > > At the REPL top level, post-init assignment to a native-typed variable > > fails: > >
> > > my int $a = 3
> > 3
> > > $a = 4
> > Cannot find method 'qast'
> > > my int $i
> > 0
> > > $i = 3
> > Cannot find method 'qast' > > > > But it works fine in other situations: > >
> > > sub foo() { my int $a; $a = 3 }
> > sub foo () { #`(Sub|53233744) ... }
> > > foo()
> > 3 > > > > $ perl6 -e 'my int $i; $i = 3; say $i' > > 3 > > > > -zefram
Show quoted text
> >
Download (untitled) / with headers
text/plain 2.8k
I dug into this bug for a bit today, and I think I discovered the underlying issue. Let's take a look at the golfed-down example Lloyd provided above: Show quoted text
> perl6 -e 'my int $a = 3; EVAL q|$a = 4|'
When we run the EVAL, the compiler seems to have some knowledge of $i at the Rakudo level - it knows enough to know that $i is a native type, and to be helpful and performant, Rakudo tries to generate a native assignment (that is, assign_i). It leverages the MAST compiler that NQP provides, so let's start looking at NQP. NQP's MAST compiler (in src/vm/moar/QAST/QASTOperationsMAST.nqp) eventually gets to a routine called try_get_bind_scope. This routine climbs up the lexical context chain (in the MAST compiler, it's a chain of BlockInfo objects) to see if it can use a bind operator or if an assign op is really what it wants. However, here's the problem: the BlockInfo chain is incomplete; it doesn't refer to the context that contains $i. After a few iterations, we reach the top of this incomplete chain, which causes us to refer to BlockInfo attributes/methods on an NQPMu, causing the crash. Now, EVAL passes in a context for the new chunk code to use, but this context isn't available until after compilation, when EVAL uses nqp::forceouterctx to set up the context on the compiled code object. There's a bandaid solution that treats the symptom but not the cause - we can alter the while loop in try_get_bind_scope to terminate if the current block in the chain is falsey, which seems to work ok with regards to roast. I have a branch that does this at https://github.com/perl6/nqp/tree/rt-126900. A better solution that treats the underlying cause would be to have the MAST compiler construct a top-level BlockInfo from the passed-in context. Since BlockInfo requires a QAST::Node, I don't know how easy this would be. On 2016-09-16 19:53:59, rob@hoelz.ro wrote: Show quoted text
> Looks related to RT #127933. > > On 2015-12-13 18:11:39, lloyd.fourn@gmail.com wrote:
> > You can gold this down to: > > > > perl6 -e 'my int $a = 3; EVAL q|$a = 4|' > > > > #!>Cannot find method 'qast' > > > > On Mon, Dec 14, 2015 at 7:26 AM Zefram <perl6-bugs-followup@perl.org> > > wrote: > >
> > > # New Ticket Created by Zefram > > > # Please include the string: [perl #126900] > > > # in the subject line of all future correspondence about this > > > issue. > > > # <URL: https://rt.perl.org/Ticket/Display.html?id=126900 > > > > > > > > > > At the REPL top level, post-init assignment to a native-typed > > > variable > > > fails: > > >
> > > > my int $a = 3
> > > 3
> > > > $a = 4
> > > Cannot find method 'qast'
> > > > my int $i
> > > 0
> > > > $i = 3
> > > Cannot find method 'qast' > > > > > > But it works fine in other situations: > > >
> > > > sub foo() { my int $a; $a = 3 }
> > > sub foo () { #`(Sub|53233744) ... }
> > > > foo()
> > > 3 > > > > > > $ perl6 -e 'my int $i; $i = 3; say $i' > > > 3 > > > > > > -zefram
> >
> > >


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org