[perl #126176] subroutine with trait rw "return" a scalar cann't be lvalue
# New Ticket Created by 宋文泰 # Please include the string: [perl #126176] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=126176 > ``` perl6 code my $lastval = 4; sub lastval () is rw { return $lastval } dd $lastval; lastval() = 5; dd $lastval; ``` Int $lastval = 4 Cannot assign to a readonly variable or a value in block at t3.p6:7 This is perl6 version 2015.09-115-g4653d98 built on MoarVM version 2015.09-36-g51dcbe4
Re: [perl #126172] maybe a bug
> On 25 Sep 2015, at 06:43, 宋文泰 (via RT) wrote: > > # New Ticket Created by 宋文泰 > # Please include the string: [perl #126172] > # in the subject line of all future correspondence about this issue. > # https://rt.perl.org/Ticket/Display.html?id=126172 > > > > ```perl6 code > > my @a = 1,2,3; > my @b; > @b.push: @a,; > > ``` > > @b is [1,2,3], not [ [1,2,3] ], is this a bug? > in S07: > http://design.perl6.org/S07.html > @a.push: @b,; # pushes 1 value (whatever is in @b) > This is perl6 version 2015.09-115-g4653d98 built on MoarVM version > 2015.09-36-g51dcbe4 Thank you for letting us know. The bug turns out to be in the spec: http://irclog.perlgeek.de/perl6/2015-09-25#i_11273634 So the spec will be adapted. Liz
Re: [perl #126176] subroutine with trait rw "return" a scalar cann't be lvalue
> On 25 Sep 2015, at 12:05, 宋文泰 (via RT) wrote: > > # New Ticket Created by 宋文泰 > # Please include the string: [perl #126176] > # in the subject line of all future correspondence about this issue. > # https://rt.perl.org/Ticket/Display.html?id=126176 > > > > ``` perl6 code > my $lastval = 4; > sub lastval () is rw { return $lastval } > dd $lastval; > lastval() = 5; > dd $lastval; > ``` > > Int $lastval = 4 > Cannot assign to a readonly variable or a value > in block at t3.p6:7 > > This is perl6 version 2015.09-115-g4653d98 built on MoarVM version > 2015.09-36-g51dcbe4 Unfortunately, “is rw” doesn’t (yet anyway) make a left value subroutine work. You need it to return a Proxy object as well: my $lastval; sub lastval() is rw { Proxy.new( FETCH => { $lastval }, # as a RHS, like $a = lastval; STORE => -> $, $value { $lastval = $value }, # as a LHS, like lastval() = $a ) } lastval() = 42; say $lastval; At one point Perl 6 may develop syntactic sugar for this, but for now this is the way to do this. Ticket can be closed as NotABug Liz
Re: [perl #126176] subroutine with trait rw "return" a scalar cann't be lvalue
Liz, you're not quite correct about this I'm afraid. check this out: timo@schmand ~> perl6 -e 'my $lastval = 4; sub lastval is rw { $lastval }; dd $lastval; lastval() = 5; dd $lastval' Int $lastval = 4 Int $lastval = 5 The problem was that "return" was used. If you use "return-rw" or just "last-value-of-block" returning, it'll work as expected. The problem was that "return" behaves as if it were "return-ro". cheers - Timo
[perl #126183] Calling a sub that uses a subsignature leaks memory
# New Ticket Created by Rob Hoelz # Please include the string: [perl #126183] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=126183 > See subject and the attached script. To run the attached test script, you'll need to build a patched MoarVM (apply meminfo-moar.patch and run tools/update_ops.p6), a patched NQP (apply meminfo-nqp.patch), and Rakudo using those two patched programs. The patch adds support for a meminfo() op that reports memory using mallinfo(), which I believe is glibc-specific. The test script prints out memory usage each second; you only really need to care about the first column, which is the amount of memory allocated not using mmap. I have also attached an Octave program I used to plot the data from the script; I have attached one of the plots as well. I believe the problem is here: https://github.com/MoarVM/MoarVM/blob/51dcbe4a41d5e2853ff32c9d9632c53a5ae44340/src/6model/reprs/MVMCallCapture.c#L61 and here: https://github.com/MoarVM/MoarVM/blob/51dcbe4a41d5e2853ff32c9d9632c53a5ae44340/src/core/args.c#L62 effective_callsite points to a new callsite object, which is only free'd if it's not equal to the original callsite object. However, further down in args.c, callsite is set to the location of effective_callsite.#!/usr/bin/env perl6 use nqp; sub noop(*@args) {} sub noop-subsig(*@args ($, *@)) {} sub for-a-second-keep-doing(&code) { my $done = now + 1; while now < $done { code(); } } say(nqp::meminfo()); for 1..60 { for-a-second-keep-doing {; #noop('cat'); noop-subsig('cat'); }; say(nqp::meminfo()); } =begin Instructions Build a MoarVM and NQP using the patches attached to this RT ticket, and use them to build a Rakudo. The patches implement a meminfo opcode, which returns a space-delimited string containing the values returned by C, which, AFAIK, is glibc-specific. Uncomment the C call above, run this script, storing the output to some file. Restore the comment on C, uncomment the call to C. Run and store output to a different file. I used GNU Octave to plot the data; use whatever software you feel comfortable with, or just read the output, if that's your thing. =) I've attached the Octave script I used to plot this in case you want to use that. We only really need to care about the first column, which is the amount of memory allocated by means other than C. Also attached are images that I generated using this setup; one has C and C on, one does not. =end Instructions diff --git a/src/core/interp.c b/src/core/interp.c index c1c5f63..37972f4 100644 --- a/src/core/interp.c +++ b/src/core/interp.c @@ -2,6 +2,8 @@ #include #include "platform/time.h" +#include + /* Macros for getting things from the bytecode stream. */ #define GET_REG(pc, idx)reg_base[*((MVMuint16 *)(pc + idx))] #define GET_LEX(pc, idx, f) f->env[*((MVMuint16 *)(pc + idx))] @@ -5117,6 +5119,21 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex MVM_cross_thread_write_check(tc, obj, blame); goto NEXT; } +OP(meminfo): { +char buffer[256]; +struct mallinfo mi; + +mi = mallinfo(); + +snprintf(buffer, 255, "%d %d %d %d %d %d %d %d %d %d", +mi.arena, mi.ordblks, mi.smblks, +mi.hblks, mi.hblkhd, mi.usmblks, +mi.fsmblks, mi.uordblks, mi.fordblks, mi.keepcost); +buffer[255] = '\0'; +GET_REG(cur_op, 0).s = MVM_string_ascii_decode(tc, tc->instance->VMString, buffer, strlen(buffer)); +cur_op += 2; +goto NEXT; +} #if MVM_CGOTO OP_CALL_EXTOP: { /* Bounds checking? Never heard of that. */ diff --git a/src/core/oplist b/src/core/oplist index 870ef22..7db22f4 100644 --- a/src/core/oplist +++ b/src/core/oplist @@ -841,3 +841,5 @@ prof_allocated .s r(obj) # Cross-thread write analysis logging instruction. ctw_check.s r(obj) int16 + +meminfow(str) diff --git a/src/vm/moar/QAST/QASTOperationsMAST.nqp b/src/vm/moar/QAST/QASTOperationsMAST.nqp index faa62b4..811bb7d 100644 --- a/src/vm/moar/QAST/QASTOperationsMAST.nqp +++ b/src/vm/moar/QAST/QASTOperationsMAST.nqp @@ -2809,6 +2809,8 @@ QAST::MASTOperations.add_core_moarop_mapping('mvmendprofile', 'endprofile'); # MoarVM-specific GC ops QAST::MASTOperations.add_core_moarop_mapping('force_gc', 'force_gc'); +QAST::MASTOperations.add_core_moarop_mapping('meminfo', 'meminfo'); + sub resolve_condition_op($kind, $negated) { return $negated ?? $kind == $MVM_reg_int64 ?? 'unless_i' !! #!/usr/bin/env octave % in this plot, the red line is the arena (non-mmap'd allocated data) usage for % a sub without a subsignature, and the blue line is the arena usage for a sub % with a subsignatur
Misunderstanding when usng elems on undefined Array
Found the following using Array; > my Array $a; > say $a.elems; 1 > $a.push(1) [1] > say $a.perl [1] > say $a.elems 1 > my Array $a .= new; [] > say $a.elems; 0 Seems that an uninitialized Array reports one element but pushing values on the array will define the properly. In this case it is important to initialize. Perl version: 2015.09-95-g3970634 built on MoarVM version 2015.09-35-gd15a446 Greetings Marcel Timmerman
[perl #126184] [BUG] Error in supply block reported at call context instead of definition
# New Ticket Created by Justin DeVuyst # Please include the string: [perl #126184] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=126184 > [jdv@wieldy ~]$ cat -n test.p6 1 use v6; 2 3 my $supply = supply { 4 die; 5 } 6 7 react { 8 whenever $supply { 9 10 } 11 } 12 [jdv@wieldy ~]$ perl6 test.p6 Died in block at test.p6:7 [jdv@wieldy ~]$ perl6 -v This is perl6 version 2015.09-102-gf89dc23 built on MoarVM version 2015.09-35-gd15a446 [jdv@wieldy ~]$ Could we report the error being at line 4 instead of 7? Thanks, jdv
[perl6/specs] 82b803: Spec fix for #126172
Branch: refs/heads/master Home: https://github.com/perl6/specs Commit: 82b80326bad36f4ca0d33d4b8064061f155a21c5 https://github.com/perl6/specs/commit/82b80326bad36f4ca0d33d4b8064061f155a21c5 Author: Elizabeth Mattijsen Date: 2015-09-25 (Fri, 25 Sep 2015) Changed paths: M S07-lists.pod Log Message: --- Spec fix for #126172
[perl #126189] [BUG] [LEAK] loop { 0, .1 ... 1000 }
# New Ticket Created by Larry Wall # Please include the string: [perl #126189] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=126189 > Leaks memory, probably due to the implicit function being called to produce the next value. Also leaks with an explicit function, or any other form of loop around it. (We know the sequence is terminating even if Rats aren't exact, because the implicit form turns the match into an inequality. In any case, one can sum the series and print it out each iteration to be sure.)
require on string stopped working in rakudo 2015.09
Hi, I am really glad Rakudo finally came out. I've installed in and tried to run the tests of Perl6::Maven. They quickly failed as I have been using 'require' on string to check if all the module compile properly. The following code now fails: use v6; my $name = 'Bailador'; require $name; even though require Bailador; works. In 2015.07 both worked. I've fixed my script by switching to EVAL "use $module"; but I wonder if this is a regression or a planned deprecation? Gabor
Should the use of eval recommend EVAL?
Hi, I just tried to use eval "say 19+23"; but I got: ===SORRY!=== Error while compiling a.pl Undeclared routine: eval used at line 3. Did you mean 'val'? Would it be possible to recommend 'EVAL' as well ? Gabor
How to push a hash on an array without flattening it to Pairs?
In the first two cases the hash was converted to Pairs before assigning to the array. Only the third case gave what I hoped for. How can I push a hash onto an array as a single entity? use v6; my %h = x => 6, y => 7; say %h.perl; # {:x(6), :y(7)} my @a = %h; say @a.elems; # say @a[0]; # x => 6 my @c; @c.push(%h); say @c.elems; # 2 say @c[0]; # x => 6 my @b; @b[@b.elems] = %h; say @b.elems; # 1 say @b[0];# x => 6, y => 7