[Cuis-dev] Curious bug

Luciano Notarfrancesco luchiano at gmail.com
Wed Jun 24 08:42:24 PDT 2020


Oh, you’re totally right, I see now! (For a moment I thought you just added
bitReverse: in LargePositiveInteger and I forgot it was originally
implemented there as well, I couldn’t understand how the method in Integer
could ever fail.) Thanks for taking the time to debug it!

On Wed, 24 Jun 2020 at 10:36 PM, Juan Vuletich via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> On 6/24/2020 11:34 AM, Luciano Notarfrancesco via Cuis-dev wrote:
>
> But that means that at some point a bit operation (bitShift, bitOr,
> bitAnd) answers a LargeInteger that actually fits in a SmallInteger, right?
> That should never happen, because for example equality fails.
>
> On Wed, 24 Jun 2020 at 9:28 PM, Juan Vuletich <juan at jvuletich.org> wrote:
>
>> On 6/23/2020 10:58 AM, Luciano Notarfrancesco via Cuis-dev wrote:
>>
>> Sorry, should be whileTrue there...
>>
>> On Tue, 23 Jun 2020 at 8:57 PM, Luciano Notarfrancesco <
>> luchiano at gmail.com> wrote:
>>
>>> Try this in a workspace:
>>>
>>> [a _ (1 << 60) atRandom.
>>> b _ (a bitReverse: 64) bitReverse: 64.
>>> a = b] whileFalse
>>>
>>> I tested it in the latest image with a recent cog spur x64 VM. The loop
>>> stops with a ‘b’ that is a LargePositiveInteger but it actually fits in a
>>> SmallInteger and it is equal to ‘a’. I don’t have time to debug it until
>>> the weekend but I thought someone might find it amusing.
>>>
>>
>> Well, this was fun!
>>
>> When you find the problem (the primitive in #bitShiftMagnitude: answers
>> the receiver if the argument is zero, without reducing it to SmallInteger
>> as appropriate), and you try to fix it, then, when you want to write a test
>> that fails without the fix, you can not make it fail!
>>
>> The problem only happens when #bitReverse: gets jitted by the Cog VM, and
>> that requires a few runs to happen. Hence, the test loops a few times,
>> doing exactly the same.
>>
>> Please take a look.
>>
>> Cheers,
>>
>> --
>> Juan Vuletichwww.cuis-smalltalk.orghttps://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Devhttps://github.com/jvuletichhttps://www.linkedin.com/in/juan-vuletich-75611b3
>> @JuanVuletich
>>
>>
> Take a look at the code!
>
> In LargePositiveInteger >> bitReverse: it builds a LargePositiveInteger.
> Before answering the result, it calls #bitShiftMagnitude: . As I told
> above, the primitive in #bitShiftMagnitude: answers the receiver if the
> argument is zero, without reducing it to SmallInteger as appropriate.
> That's not unreasonable. #bitShiftMagnitude: can assume the receiver is a
> sane instance. The fix I included is to call #normalize as appropriate,
> instead of calling #bitShift: when the argument is zero.
>
>
> --
> Juan Vuletichwww.cuis-smalltalk.orghttps://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Devhttps://github.com/jvuletichhttps://www.linkedin.com/in/juan-vuletich-75611b3
> @JuanVuletich
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20200624/1432602a/attachment.htm>


More information about the Cuis-dev mailing list