Serious bug in 3.10

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Serious bug in 3.10

askoh
Administrator
| block |
block := [:i | Transcript cr; show: i].
1 to: 10 do: [:i | block value: i+1]

The above should print ten times. But it only prints the five even numbers. That is a bug isn't it?

Aik-Siong Koh
Reply | Threaded
Open this post in threaded view
|

RE: [squeak-dev] Serious bug in 3.10

Ramon Leon-5
> Sent: Thursday, July 31, 2008 3:33 PM
> To: [hidden email]
> Subject: [squeak-dev] Serious bug in 3.10
>
>
> | block |
> block := [:i | Transcript cr; show: i].
> 1 to: 10 do: [:i | block value: i+1]
>
> The above should print ten times. But it only prints the five
> even numbers.
> That is a bug isn't it?
>
> Aik-Siong Koh

Try this..

block := [:f | Transcript cr; show: f].
(1 to: 10) do: [:f | block value: f+1]

And you'll see that likely, to:do: is being inlined by the compiler and
causing something funny like allowing you to increment the loops index var
causing it to skip a number each iteration.

Ramon Leon
http://onsmalltalk.com


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Serious bug in 3.10

keith1y
In reply to this post by askoh
askoh wrote:
> | block |
> block := [:i | Transcript cr; show: i].
> 1 to: 10 do: [:i | block value: i+1]
>
> The above should print ten times. But it only prints the five even numbers.
> That is a bug isn't it?
>
> Aik-Siong Koh
>  
More of a "known limitation" than a bug... due to the fact that squeak
does not have proper closures.

try

| block |
block := [:j | Transcript cr; show: j].
1 to: 10 do: [:i | block value: i+1]

Keith


Reply | Threaded
Open this post in threaded view
|

RE: [squeak-dev] Serious bug in 3.10

Ramon Leon-5

> askoh wrote:
> > | block |
> > block := [:i | Transcript cr; show: i].
> > 1 to: 10 do: [:i | block value: i+1]
> >
> > The above should print ten times. But it only prints the
> five even numbers.
> > That is a bug isn't it?
> >
> > Aik-Siong Koh
> >  
> More of a "known limitation" than a bug... due to the fact
> that squeak
> does not have proper closures.
>
> try
>
> | block |
> block := [:j | Transcript cr; show: j].
> 1 to: 10 do: [:i | block value: i+1]
>
> Keith

I was going to say that, but why does it work using (1 to: 10) do: rather
than 1 to: 10 do:, seems related to #to:do: being inlined?

Ramon Leon
http://onsmalltalk.com


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Serious bug in 3.10

Igor Stasenko
2008/8/1 Ramon Leon <[hidden email]>:

>
>> askoh wrote:
>> > | block |
>> > block := [:i | Transcript cr; show: i].
>> > 1 to: 10 do: [:i | block value: i+1]
>> >
>> > The above should print ten times. But it only prints the
>> five even numbers.
>> > That is a bug isn't it?
>> >
>> > Aik-Siong Koh
>> >
>> More of a "known limitation" than a bug... due to the fact
>> that squeak
>> does not have proper closures.
>>
>> try
>>
>> | block |
>> block := [:j | Transcript cr; show: j].
>> 1 to: 10 do: [:i | block value: i+1]
>>
>> Keith
>
> I was going to say that, but why does it work using (1 to: 10) do: rather
> than 1 to: 10 do:, seems related to #to:do: being inlined?
>

#to:do: is a hacky compiler optimization, which replaces true messages. :)
Someday its can be removed, when VM will be powered by good JIT

> Ramon Leon
> http://onsmalltalk.com
>
>
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Serious bug in 3.10

Eliot Miranda-2
In reply to this post by askoh


On Thu, Jul 31, 2008 at 3:32 PM, askoh <[hidden email]> wrote:

| block |
block := [:i | Transcript cr; show: i].
1 to: 10 do: [:i | block value: i+1]

The above should print ten times. But it only prints the five even numbers.
That is a bug isn't it?

yes, but its ancient.  It is to do with the implementation of blocks and specifically block temporaries.  Both blocks bind to the same "i".  So when you evaluate
    block value: i + 1
the 1 to: do:'s i gets incremented.

Try this with my closure implementation (http://www.mirandabanda.org/cogblog/downloads/) and it is fixed.

Aik-Siong Koh
--
View this message in context: http://www.nabble.com/Serious-bug-in-3.10-tp18764850p18764850.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.





Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Serious bug in 3.10

Eliot Miranda-2
In reply to this post by Ramon Leon-5


On Thu, Jul 31, 2008 at 3:54 PM, Ramon Leon <[hidden email]> wrote:

> askoh wrote:
> > | block |
> > block := [:i | Transcript cr; show: i].
> > 1 to: 10 do: [:i | block value: i+1]
> >
> > The above should print ten times. But it only prints the
> five even numbers.
> > That is a bug isn't it?
> >
> > Aik-Siong Koh
> >
> More of a "known limitation" than a bug... due to the fact
> that squeak
> does not have proper closures.
>
> try
>
> | block |
> block := [:j | Transcript cr; show: j].
> 1 to: 10 do: [:i | block value: i+1]
>
> Keith

I was going to say that, but why does it work using (1 to: 10) do: rather
than 1 to: 10 do:, seems related to #to:do: being inlined?

Yes.  In the activation of to:do: there is a different counter.  Look at the implementation of Number>>to:do:.  So while both i's are still the same lvalue, i is not used by Number>>to:do: either to control the loop iterations or to to derive the values for the loop.  Only when the loop is inlined does i become the loop control variable.

HTH
 



Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: Serious bug in 3.10

Nicolas Cellier-3
In reply to this post by Ramon Leon-5
Ramon Leon <ramon.leon <at> allresnet.com> writes:

>
> > Sent: Thursday, July 31, 2008 3:33 PM
> > To: squeak-dev <at> lists.squeakfoundation.org
> > Subject: [squeak-dev] Serious bug in 3.10
> >
> >
> > | block |
> > block := [:i | Transcript cr; show: i].
> > 1 to: 10 do: [:i | block value: i+1]
> >
> > The above should print ten times. But it only prints the five
> > even numbers.
> > That is a bug isn't it?
> >
> > Aik-Siong Koh
>
> Try this..
>
> block := [:f | Transcript cr; show: f].
> (1 to: 10) do: [:f | block value: f+1]
>
> And you'll see that likely, to:do: is being inlined by the compiler and
> causing something funny like allowing you to increment the loops index var
> causing it to skip a number each iteration.
>
> Ramon Leon
> http://onsmalltalk.com
>
>

Yes but:

block := [:f | Transcript cr; show: f].
(1 to: 10) do: [:f | block value: f+1. block value: f].

does not behave much better...
the 10 loops are performed, but since the blocks share same temporary f, things
are still a bit strange.

You need to use different argument names, NewCompiler or Eliot's closures.


Reply | Threaded
Open this post in threaded view
|

RE: [squeak-dev] Re: Serious bug in 3.10

Ramon Leon-5
> >
> > And you'll see that likely, to:do: is being inlined by the
> compiler and
> > causing something funny like allowing you to increment the
> loops index var
> > causing it to skip a number each iteration.
> >
> > Ramon Leon
> > http://onsmalltalk.com
> >
> >
>
> Yes but:
>
> block := [:f | Transcript cr; show: f].
> (1 to: 10) do: [:f | block value: f+1. block value: f].
>
> does not behave much better...
> the 10 loops are performed, but since the blocks share same
> temporary f, things
> are still a bit strange.
>
> You need to use different argument names, NewCompiler or
> Eliot's closures.

Oh I agree, I wasn't suggesting a solution, I know the scope of the args is
shared because of the lack of real closures.  I was more inquiring why the
behavioral difference between (to:) do: and to:do: since the latter is
inlined but normally you'd expect them to be equivalent.

Ramon Leon
http://onsmalltalk.com