Why does this fail?

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

Why does this fail?

Udo Schneider
If I execute the following code I'll get a wallback complaining about true
(false) not understanding #>= although this message isn't sent!!

Just execute the following:

1 to: 10 do: [ :n1 |
    1 to: 10 do: [ :n2 |
        n1 = n2 ifTrue: ["Error!"]
    ]
].

Is this an obvious error or did I miss somethig?



Udo


Reply | Threaded
Open this post in threaded view
|

Re: Why does this fail?

Ian Bartholomew-5
Udo,

> Is this an obvious error or did I miss somethig?

It's a problem that's been around for some time and is to do with the way
the Dolphin compiler optimises some code sequences.

 From the archive (Blair in 1999)

=~=~=~=~=

Its a compiler bug that occurs when empty #ifTrue:[ifFalse:] statements
occur inside an optimized to:do: loop. Inspecting the bytecodes shows that
the compiler has optimized away the redundant conditional, but failed to pop
the result of the condition expression. It seems that this only happens when
the compiler thinks it can remove the #ifTrue:[ifFalse:].

=~=~=~=~=

Just make sure that there is always something in the block -

1 to: 10 do: [ :n1 |
    1 to: 10 do: [ :n2 |
        n1 = n2 ifTrue: [1 + 1]]].

Bit of a kludge but it doesn't happen very often.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: Why does this fail?

Ian Bartholomew-5
In reply to this post by Udo Schneider
Udo,

> Is this an obvious error or did I miss somethig?

It's a problem that's been around for some time and is to do with the way
the Dolphin compiler optimises some code sequences.

>From the archive (Blair in 1999)

=~=~=~=~=

Its a compiler bug that occurs when empty #ifTrue:[ifFalse:] statements
occur inside an optimized to:do: loop. Inspecting the bytecodes shows that
the compiler has optimized away the redundant conditional, but failed to pop
the result of the condition expression. It seems that this only happens when
the compiler thinks it can remove the #ifTrue:[ifFalse:].

=~=~=~=~=

Just make sure that there is always something in the block -

1 to: 10 do: [ :n1 |
    1 to: 10 do: [ :n2 |
        n1 = n2 ifTrue: [1 + 1]]].

Bit of a kludge but it doesn't happen very often.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: Why does this fail?

Udo Schneider
In reply to this post by Ian Bartholomew-5
Ian,

thanks for the quick reply. This explains alot.

So the only way to discover this is to do "incremental" developing ;-)


Udo

"Ian Bartholomew" <[hidden email]> schrieb im Newsbeitrag
news:9s6tmj$11ka5p$[hidden email]...

> Udo,
>
> > Is this an obvious error or did I miss somethig?
>
> It's a problem that's been around for some time and is to do with the way
> the Dolphin compiler optimises some code sequences.
>
> From the archive (Blair in 1999)
>
> =~=~=~=~=
>
> Its a compiler bug that occurs when empty #ifTrue:[ifFalse:] statements
> occur inside an optimized to:do: loop. Inspecting the bytecodes shows that
> the compiler has optimized away the redundant conditional, but failed to
pop
> the result of the condition expression. It seems that this only happens
when

> the compiler thinks it can remove the #ifTrue:[ifFalse:].
>
> =~=~=~=~=
>
> Just make sure that there is always something in the block -
>
> 1 to: 10 do: [ :n1 |
>     1 to: 10 do: [ :n2 |
>         n1 = n2 ifTrue: [1 + 1]]].
>
> Bit of a kludge but it doesn't happen very often.
>
> Ian
>
>
>
>
>
>
>
>
>