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

Null PMC access when declarator with multiple variables contain sigilless in Rakudo #3064

Closed
p6rt opened this issue Mar 4, 2013 · 10 comments

Comments

@p6rt
Copy link

p6rt commented Mar 4, 2013

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

Searchable as RT117043$

@p6rt
Copy link
Author

p6rt commented Mar 4, 2013

From @masak

<TimToady> nr​: my ($x0, \x1) = (1, 2); say $x0; say x1
<p6eval> niecza v24-26-g713c785​: OUTPUT«1␤2␤»
<p6eval> ..rakudo 87ad7c​: OUTPUT«===SORRY!===␤Error while compiling
block : Error while compiling op call​: Error while compiling block :
Error while compiling op call​: Null PMC access in
find_method('handle')␤»
<TimToady> masak​: did you see that one?
<TimToady> it's what blows up
http://rosettacode.org/wiki/Xiaolin_Wu%27s_line_algorithm#Perl_6 in
rakudo
<TimToady> and FROGGS++ for hunting the bug down
<masak> TimToady​: I did not.
* masak submits rakudobug
<masak> nr​: my (\x1) = 1; say x1
<p6eval> niecza v24-26-g713c785​: OUTPUT«1␤»
<p6eval> ..rakudo 87ad7c​: OUTPUT«===SORRY!===␤Error while compiling
block : Error while compiling op call​: Error while compiling block :
Error while compiling op call​: Null PMC access in
find_method('handle')␤»
<masak> so, it's the combination of \ and my () that does it.
<masak> my guess is that the sigilless doesn't get properly registered
when it's in a ()

@p6rt
Copy link
Author

p6rt commented Oct 11, 2014

From @usev6

The assignment to a sigilless in a () no longer results in a Null PMC access error -- but the sigilless doesn't contain the correct value after assignment​:

$ perl6-m -e 'my ($x0, \x1) = (1, 2); say $x0; say x1'
1
(Any)

$ perl6-m -e 'my (\x1) = 1; say x1'
(Any)

$ perl6-m -e 'my \x1 = 1; say x1'
1

The behaves identical on Moar, Parrot and JVM.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 11, 2014

From @usev6

The assignment to a sigilless in a () no longer results in a Null PMC access error -- but the sigilless doesn't contain the correct value after assignment​:

$ perl6-m -e 'my ($x0, \x1) = (1, 2); say $x0; say x1'
1
(Any)

$ perl6-m -e 'my (\x1) = 1; say x1'
(Any)

$ perl6-m -e 'my \x1 = 1; say x1'
1

The behaves identical on Moar, Parrot and JVM.

@p6rt
Copy link
Author

p6rt commented Oct 11, 2014

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

@p6rt
Copy link
Author

p6rt commented Feb 2, 2015

From @usev6

I added two tests (fudged 'todo') to S04-declarations/my.t with commit Raku/roast@c2c4f7cd48

1 similar comment
@p6rt
Copy link
Author

p6rt commented Feb 2, 2015

From @usev6

I added two tests (fudged 'todo') to S04-declarations/my.t with commit Raku/roast@c2c4f7cd48

@p6rt
Copy link
Author

p6rt commented Jun 18, 2015

From @skids

Further investigation of RT#​117043.

1) It is specced (via STD and from there RT#​116607 and from there
S32-exceptions/misc.t) that sigilless my variables must have an
initializer. I could not find an explanation for this.

$ perl6 -e 'my (\a);' # no error
$ perl6 -e 'my \a;' # intended error
===SORRY!=== Error while compiling -e
Term definition requires an initializer
at -e​:1
------> my \a⏏;

2) Whether this principle carries over to sigilless parameters
is hard to discern.

std​: sub (\a?) { }
std 28329a7​: OUTPUT«===SORRY!===␤Unable to parse signature at /tmp/866RutNr2q line 1​:␤------> sub ⏏(\a?) { }␤Couldn't find final ')'; gave up at /tmp/866RutNr2q »
$ perl6 -e 'sub (\a?) { }' # Either LTA error, or broken
===SORRY!=== Error while compiling -e
Missing block
at -e​:1
------> sub (\a⏏?) { }

3) Sigilless variables in general are apparently supposed to
just bind, when "assigned." No spectests seem to try to write
to them.

$ perl6 -e 'my \a = 1; a = 2'
Cannot modify an immutable Int
  in block <unit> at -e​:1
$ perl6 -e 'sub f (\a is copy) { a = 6; a.say }; f(5)' # Seems to be equivalent
Cannot modify an immutable Int
  in sub f at -e​:1
  in block <unit> at -e​:1
$ perl6 -e 'my $b = 4; my \a = $b; $b = 2; a.perl.say;' # Further evidence
2
$ perl6 -e 'my \a = (); a = 3; a.perl.say;' # This is odd
()
$ my \a := (); a = 3; a.perl.say;' # Same thing this way
()
$ perl6 -e 'my $a := (); $a = 3; $a.perl.say;' # Expected behavior
Cannot assign to an immutable value
  in block <unit> at -e​:1

4) Precedence (?) for behavior when a bind does not happen but a
declaration does​:

$ perl6 -e 'my ($a, $b?) := 1,; $b.perl.say'
Mu

5) In any case if '=' means "bind" for sigilless variables,
then any mixture of sigiled and sigilless variables like​:

my ($a, \b) = 3,4;

... means that the signature has to be iterated and the operation
(bind or assign) chosen based on whether the variable is sigilless
or not.

Internally this​:

my (\x1) = 4;

...currently gets routed to a p6store​:

- QAST​::Op(p6store) (\\x1) = 4
  - QAST​::Op(call &infix​:<,>)
  - QAST​::Var(lexical x1 :decl())
  - QAST​::Want 4
  - QAST​::WVal(Int)
  - Ii
  - QAST​::IVal(4)

...and so this probably unintended behavior is possible​:

$ perl6 -e 'my (\a) = 4; a.say; a = 5; a.say;'
(Any)
5

6) The list-declarator construct also admits this​:

my (\c, \d) = @​runtime-valued-array;

...which, if mandatory initialization is desired, must fail at
runtime based on the @​runtime-valued-array.elems.

@p6rt
Copy link
Author

p6rt commented Jun 19, 2015

From @masak

Brian (>)​:

Further investigation of RT#​117043.

1) It is specced (via STD and from there RT#​116607 and from there
S32-exceptions/misc.t) that sigilless my variables must have an
initializer. I could not find an explanation for this.

I expect the explanation is because sigilless variables (like constants) do not mutate after having been declared, and so it only makes sense to declare one if you also intend to assign to it.

@p6rt
Copy link
Author

p6rt commented Mar 12, 2016

From @moritz

On Mon Mar 04 10​:55​:32 2013, masak wrote​:

<TimToady> nr​: my ($x0, \x1) = (1, 2); say $x0; say x1
<p6eval> niecza v24-26-g713c785​: OUTPUT«1␤2␤»
<p6eval> ..rakudo 87ad7c​: OUTPUT«===SORRY!===␤Error while compiling
block : Error while compiling op call​: Error while compiling block :
Error while compiling op call​: Null PMC access in
find_method('handle')␤»

Works now, and the tests in my.t are passing.

@p6rt p6rt closed this as completed Mar 12, 2016
@p6rt
Copy link
Author

p6rt commented Mar 12, 2016

@moritz - 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