[perl #128655] Mixup in candidates through optimizer

2016-07-17 Thread via RT
# New Ticket Created by  Elizabeth Mattijsen 
# Please include the string:  [perl #128655]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=128655 >


m: Buf.new((my int $i = 10) +& 0xFF)
Type check failed in initializing element #0 to Buf; expected uint8 but got Int 
(10)
in any  at gen/moar/m-Metamodel.nqp line 1736␤  in block  at  line 1

Actually thrown at:␤  in any  at gen/moar/m-Metamodel.nqp line 3055␤  in an…

On further inspection, it appears that the value found in the argument list is 
a BOOTInt, rather than an Int, and that fails the nqp::istype($a,Int) test.  It 
*feels* like it calling the int/int candidate, when it thinks it's calling the 
Int:D/Int:D candidate.  Since the int/int candidate returns an int, but the 
optimizer probably thinks it is getting an Int, the native is not marshalled 
into an Int when it should.

This bug probably existed for a long time already, but was uncovered by 
de5d9e70cbfe678d2371d284 .  Before, going through all of the iterator stuff, 
would marshall the int into an Int


It appears that all bitwise operators that return an int/Int have the same 
problem with the calling them with a native parameter.  The problem goes away 
if optimizing is somehow inhibited, but that, I feel, is just masking the 
problem.  Ways of stopping optimization are:

- calling perl6 with —optimize=0 or —optimize=1
- adding an nqp::null to the native int candidate

multi sub infix:<+&>(Int:D \a, Int:D \b) {
nqp::bitand_I(nqp::decont(a), nqp::decont(b), Int)
}
multi sub infix:<+&>(int $a, int $b) {
nqp::null;  # stops optimization
nqp::bitand_i($a, $b)
}

Note that the problem gets fixed by adding an optimizer stopper to the 
candidate that is *not* being called, as 0xFF is an Int, and thus int $i +& 
0xFF is calling the Int:D/Int:D candidate!!


Since this idiom is quite normal, a quick fix seems in order.


[perl #128655] Mixup in candidates through optimizer

2016-10-04 Thread Zoffix Znet via RT
Posting on behalf of dogbert17:



I believe that I have encountered the same bug under different circumstances. 
With the help of hackedNODE and others on #perl6
it seems as if the problem described below also suffers from the wrong multi 
candidate being called. In fact, it seems to happen
with any sub with int/Int multis.

dogbert@dogbert-VirtualBox ~ $ perl6 -v
This is Rakudo version 2016.09-122-gc6c0e69 built on MoarVM version 
2016.09-13-g34c375a
implementing Perl 6.c.

# the problem
dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my int $i = 2482111348; say $i; $i = 
$i div 2; say $i'
2482111348
-906427974

# run the same snippet with --optimize=0
dogbert@dogbert-VirtualBox ~ $ perl6 --optimize=0 -e 'my int $i = 2482111348; 
say $i; $i = $i div 2; say $i'
2482111348
1241055674

# also works with --optimize=1
dogbert@dogbert-VirtualBox ~ $ perl6 --optimize=1 -e 'my int $i = 2482111348; 
say $i; $i = $i div 2; say $i'
2482111348
1241055674

A discussion wrt this particular problem can be found here: 
https://irclog.perlgeek.de/perl6/2016-10-04#i_13335782


Re: [perl #128655] Mixup in candidates through optimizer

2016-07-18 Thread mt1957

Hi Elizabeth,

Need to mention that there was a ticket #128624 created 'Buf 
initialization error'.


Regards,
Marcel Timmerman


Re: [perl #128655] Mixup in candidates through optimizer

2016-07-18 Thread Will Coleda
Please reply to all on tickets, so that comments also end up back in
RT as well. (I linked the tickets based on your comment here.)

On Mon, Jul 18, 2016 at 4:10 AM, mt1957  wrote:
> Hi Elizabeth,
>
> Need to mention that there was a ticket #128624 created 'Buf initialization
> error'.
>
> Regards,
> Marcel Timmerman



-- 
Will "Coke" Coleda