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 blocks get the wrong $_ sometimes in Rakudo #2804

Closed
p6rt opened this issue Jun 29, 2012 · 12 comments
Closed

Null PMC Access when blocks get the wrong $_ sometimes in Rakudo #2804

p6rt opened this issue Jun 29, 2012 · 12 comments

Comments

@p6rt
Copy link

p6rt commented Jun 29, 2012

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

Searchable as RT113904$

@p6rt
Copy link
Author

p6rt commented Jun 29, 2012

From @masak

<tadzik> r​: for Range.new(0, 1) -> $p { when $p { say $_.perl; say $_.path } }
<p6eval> rakudo 39087a​: OUTPUT«use of uninitialized variable $a of
type Any in numeric context in block <anon> at
/tmp/bhcZACNkRT​:1␤␤Null PMC access in find_method('perl') [...]
<tadzik> there we are
* masak submits rakudobug
<pmichaud> ...why is that a bug, ooc?
<masak> pmichaud​: Null PMC access
<tadzik> NPA
<pmichaud> oh, I see.
<masak> r​: for ^1 -> $p { when $p { .foo } }
<p6eval> rakudo 39087a​: OUTPUT«use of uninitialized variable $a of
type Any in numeric context in block <anon> at
/tmp/HzMxDYTCaC​:1␤␤Null PMC access in find_method('foo') [...]
<pmichaud> oh, it's the .ACCEPTS bug
<masak> oh?
<pmichaud> sure, it's the when $p that is attempting to convert
Any into a number
<pmichaud> in order to smart match it against $p
<masak> the interesting thing is that the Range, the 'when' and the
$_.foo call are all irreducible parts of triggering the bug.
<masak> remove any of them, and the Null PMC Access disappears.
<pmichaud> r​: for (0,1) -> $p { when $p { .foo } }
<p6eval> rakudo 39087a​: OUTPUT«use of uninitialized variable $a of
type Any in numeric context in block <anon> at
/tmp/VgCIK_kuoP​:1␤␤Null PMC access in find_method('foo') [...]
<masak> maybe not. :)
<pmichaud> r​: for 0 -> $p { when $p { .foo } }
<masak> ok, the Range is not essential, then.
<p6eval> rakudo 39087a​: OUTPUT«use of uninitialized variable $a of
type Any in numeric context in block <anon> at
/tmp/2BcvX6lmnC​:1␤␤Null PMC access in find_method('foo') [...]
<masak> huh.
<masak> tadzik​: I'm pretty sure we tested that.
<tadzik> masak​: yeah, same. Odd
<pmichaud> given 0 -> $p { when $p { .foo } }
<pmichaud> r​: given 0 -> $p { when $p { .foo } }
<p6eval> rakudo 39087a​: OUTPUT«use of uninitialized variable $a of
type Any in numeric context in block <anon> at
/tmp/SJ1JbHQSej​:1␤␤Null PMC access in find_method('foo') [...]
<pmichaud> r​: (-> $p { when $p { .foo } }).(0)
<p6eval> rakudo 39087a​: OUTPUT«use of uninitialized variable $a of
type Any in numeric context in block <anon> at /tmp/5zdWF1O_Fa​:1␤␤No
such method 'foo' for invocant of type 'Any' [...]
<masak> there. it disappeared.
<masak> I think iteration is involved somehow, anyway.
<pmichaud> well, not with 'given'
<pmichaud> there's no iteration with the .given
<masak> hm, troo.
<masak> so, why does it trigger with 'for' and 'given', but not with
that last one, with a block?
<pmichaud> r​: my $ps = -> $p { when $p { .foo } }; $ps(0);
<p6eval> rakudo 39087a​: OUTPUT«use of uninitialized variable $a of
type Any in numeric context in block <anon> at
/tmp/Ap9xU9dVVo​:1NLNLNo such method 'foo' for invocant of type 'Any'
[...]
<pmichaud> r​: 0.map( -> $p { when $p { .foo } }).eager
<p6eval> rakudo 39087a​: OUTPUT<<use of uninitialized variable $a of
type Any in numeric context in block <anon> at
/tmp/JRkifpk737​:1NLNLNo such method 'foo' for invocant of type 'Any'
[...]
<pmichaud> the NPA has to be something in the way the closures are
being built when part of 'for' or 'given'
<pmichaud> which means it's a bug in <xblock>
<pmichaud> (in Actions.pm)
<pmichaud> here's another, then
<pmichaud> r​: if 1 -> $p { when $p { .foo } }
<p6eval> rakudo 39087a​: OUTPUT<<use of uninitialized variable $a of
type Any in numeric context in block <anon> at
/tmp/C8Mba0rmGT​:1NLNL>>
<pmichaud> hmm.
<pmichaud> okay, so, the "unintialized variable $a..." is coming from
an ACCEPTS call
<pmichaud> I'm guessing it's this one​:
<pmichaud> src/core/Numeric.pm​:4​: multi method ACCEPTS(Numeric​:D​: $a) {
<pmichaud> The NPA is because the pointy block is somehow getting the
wrong outer $_
<masak> ah.
<pmichaud> but only when being used as part of 'for' or 'given' (so
far... could be other structures)
<pmichaud> r​: $_ = Bool; if 1 -> $p { when $p { .say } }
<p6eval> rakudo 39087a​: OUTPUT<<use of uninitialized variable $a of
type Bool in numeric context in block <anon> at
/tmp/amepJyEJYf​:1NLNL>>
<pmichaud> r​: Bool.say
<p6eval> rakudo 39087a​: OUTPUT<<Bool()NL>>
<pmichaud> *there*
<masak> \o/
<pmichaud> the .say got a $_ that isn't the one with the Bool
<pmichaud> even though the one with the Bool is the one that was used
for the smartmatching 'when'
<masak> I'm lost, but I'm including this in the report anyway :P
<pmichaud> please do, it's pretty well golfed.
<masak> pmichaud++

@p6rt
Copy link
Author

p6rt commented Jun 29, 2012

From @pmichaud

Never mind the 'if' example above; it doesn't really evoke the error.

This does, however​:

  > $_ = 0; for ^1 -> $p { when $p { say 'matched'; $_.say } }
  matched
  Null PMC access in find_method('say')
  > $_ = 1; for ^2 -> $p { when $p { say 'matched'; $_.say } }
  matched
  Null PMC access in find_method('say')
  >

I'm guessing the problem has something to do with the way that 'when' is
topicalizing the evaluation of the $p expression and not restoring $_
properly.

Pm

@p6rt
Copy link
Author

p6rt commented Jun 29, 2012

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

@p6rt
Copy link
Author

p6rt commented Jun 29, 2012

From @pmichaud

I'm guessing the problem has something to do with the way that 'when'
is
topicalizing the evaluation of the $p expression and not restoring $_
properly.

This guess is wrong; there's currently no topicalization taking
place around $p . (See --target=pir for proof.)

So, it's something about the way $_ is being left unset in the when block
itself. Perhaps a problem with the signature of the when block (failing
to set $_ = OUTER​::$_), it not being closured properly, or something like
that.

Pm

@p6rt
Copy link
Author

p6rt commented Nov 20, 2012

From @masak

<zjmarlow> r​: my $line; for < one two three >.values -> $line { if True
{ .say } }
<p6eval> rakudo bf472b​: OUTPUT«Null PMC access [...]
<masak> huh.
<masak> we may have this in RT already, actually.
<masak> r​: for 1 -> $ { if 1 { .say } }
<p6eval> rakudo bf472b​: OUTPUT«Null PMC access [...]
<masak> yes, here​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=113904
<masak> though this particular case has an 'if', not a 'when'.
<masak> r​: $_ = 42; .say
<p6eval> rakudo bf472b​: OUTPUT«42␤»
<masak> r​: $_ = 42; for 1 { .say }
<p6eval> rakudo bf472b​: OUTPUT«1␤»
<masak> r​: $_ = 42; for 1 { if 1 { .say } }
<p6eval> rakudo bf472b​: OUTPUT«1␤»
<masak> r​: $_ = 42; for 1 -> $p { .say }
<p6eval> rakudo bf472b​: OUTPUT«42␤»
<masak> r​: $_ = 42; for 1 -> $p { if 1 { .say } }
<p6eval> rakudo bf472b​: OUTPUT«Null PMC access [...]
<masak> this one illustrates it fairly well. I'll paste it into the
ticket.

@p6rt
Copy link
Author

p6rt commented Apr 19, 2013

From @coke

One of the nom regressions (S02-magicals/dollar-underscore.t) is caused by
this NPA​:

19​:12 < [Coke]> r​: $_ = 1; my $tracker = ''; for 12 -> $a { if $_ == 1 {
  $tracker ~= "1 : $_|"; $_ = 2; } }
19​:12 <+camelia> rakudo de2080​: OUTPUT«Null PMC access in
  find_method('Stringy')␤ in block at /tmp/HWQMO6B4wa​:1␤
in
  method reify at src/gen/CORE.setting​:5737␤ in method
reify at
  src/gen/CORE.setting​:5632␤ in method gimme at
  src/gen/CORE.setting​:6053␤ in method eager at
  src/gen/CORE.setting​:6032␤ …

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Apr 19, 2013

From @FROGGS

it only comes if there is a condition within a for-loop with a named
iterator

<FROGGS> r​: $_ = 1; for 12 -> $a { if 1 { "$_" } }
<camelia> rakudo de2080​: OUTPUT«Null PMC access in
find_method('Stringy')␤ in block at /tmp/Bify_dvuSE​:1␤ in method
reify at src/gen/CORE.setting​:5737␤ in method reify at
src/gen/CORE.setting​:5632␤ in method gimme at
src/gen/CORE.setting​:6053␤ in method eager at src/gen/CORE.setting​:6032␤ …

<FROGGS> r​: $_ = 1; for 12 -> $a { unless 0 { "$_" } }
<camelia> rakudo de2080​: OUTPUT«Null PMC access in
find_method('Stringy')␤ in block at /tmp/2A9OMuXLSv​:1␤ in method
reify at src/gen/CORE.setting​:5737␤ in method reify at
src/gen/CORE.setting​:5632␤ in method gimme at
src/gen/CORE.setting​:6053␤ in method eager at src/gen/CORE.setting​:6032␤ …

@p6rt
Copy link
Author

p6rt commented Apr 19, 2013

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

@p6rt
Copy link
Author

p6rt commented Apr 19, 2013

From @FROGGS

$_ is not an SMO​:

r​: for 12 -> $a { if 1 { say $_.WHAT } }
<camelia> rakudo de2080​: OUTPUT«Can only use get_what on a
SixModelObject␤ in block at /tmp/SdPsnKQ9XU​:1␤ in method reify at
src/gen/CORE.setting​:5737␤ in method reify at
src/gen/CORE.setting​:5632␤ in method gimme at
src/gen/CORE.setting​:6053␤ in method eager at src/gen/CORE.setting​:6032␤ …

@p6rt
Copy link
Author

p6rt commented Oct 22, 2014

From @usev6

This Null PMC Access error does not occur any longer. Also the SixModelObject error is gone. (Output of following commands is identical for Moar, Parrot and JVM.)

$ perl6 -e '$_ = 1; for ^2 -> $p { when $p { say "matched"; $_.say } }'
matched
1

$ perl6-m -e '$_ = 42; for 1 -> $p { if 1 { .say } }'
42

$ perl6 -e 'for 12 -> $a { if 1 { say $_.WHAT } }'
Nil

I extended the existing tests in S02-magicals/dollar-underscore.t a bit with the following commit​: Raku/roast@0e579ae7c7

I'm closing this ticket now.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 22, 2014

From @usev6

This Null PMC Access error does not occur any longer. Also the SixModelObject error is gone. (Output of following commands is identical for Moar, Parrot and JVM.)

$ perl6 -e '$_ = 1; for ^2 -> $p { when $p { say "matched"; $_.say } }'
matched
1

$ perl6-m -e '$_ = 42; for 1 -> $p { if 1 { .say } }'
42

$ perl6 -e 'for 12 -> $a { if 1 { say $_.WHAT } }'
Nil

I extended the existing tests in S02-magicals/dollar-underscore.t a bit with the following commit​: Raku/roast@0e579ae7c7

I'm closing this ticket now.

@p6rt
Copy link
Author

p6rt commented Oct 22, 2014

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