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

assignment to native-typed variable fails in repl #4861

Open
p6rt opened this issue Dec 13, 2015 · 5 comments
Open

assignment to native-typed variable fails in repl #4861

p6rt opened this issue Dec 13, 2015 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 13, 2015

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

Searchable as RT126900$

@p6rt
Copy link
Author

p6rt commented Dec 13, 2015

From zefram@fysh.org

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

@p6rt
Copy link
Author

p6rt commented Dec 14, 2015

From @LLFourn

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-archive.perl.org/perl6/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

@p6rt
Copy link
Author

p6rt commented Dec 14, 2015

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

@p6rt
Copy link
Author

p6rt commented Sep 17, 2016

From @hoelzro

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-archive.perl.org/perl6/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

@p6rt
Copy link
Author

p6rt commented Sep 17, 2016

From @hoelzro

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​:

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​:

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-archive.perl.org/perl6/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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant