Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0007093 [Squeak] Compiler minor always 06-13-08 01:24 02-06-11 23:48
Reporter nicolas cellier View Status public  
Assigned To nicolas cellier
Priority normal Resolution fixed  
Status closed   Product Version 3.10
Summary 0007093: to:do: optimization is wrong when the block modifies the limit
Description This loop would not end without a halt if compiled by regular (old) Compiler:

| n |
n := 2.
1 to: n do: [:i | (n := n+1)>10 ifTrue: [self halt: 'Should I get here?']].
^n

When you think in term of message send, well no, you should not get here.
Of course, with parentheses you won't get there:

| n |
n := 2.
(1 to: n) do: [:i | (n := n+1)>10 ifTrue: [self halt: 'You won''t get there']].
^n

Nor:

| n |
1 to: (n := 2) do: [:i | (n := n+1)>10 ifTrue: [self halt: 'Nor will you get there']].
^n

Amazing isn't it?
Additional Information Just as tricky, check this:

| n |
n := 2.
1 to: n by: 1 do: [:i | (n := n+1)>10 ifTrue: [self halt: 'Should I get here?']].
^n

But, subtle difference:

| n inc |
n := 2.
inc := 1.
1 to: n by: inc do: [:i | (n := n+1)>10 ifTrue: [self halt: 'You won''t get there']].
^n

Problem is located into MessageNode>>transformToDo:
Of course, if one corrects this bug, there is a pending Decompiler issue:

testDecompileToDoWithMovingLimit
    | n i |
    n := 4.
    i := 1.
    [i <= n] whileTrue: [
        n := n - 1.
        i := i + 1].

would decompile into:
    | n |
    n := 4.
    1
        to: n
        do: [:i | n := n - 1]
Attached Files  M7093-MessageNode-transformToDo.st [^] (2,596 bytes) 09-07-10 22:14

- Relationships
related to 0006456closed andreas [BUG] Interval of Float do: infinite loop 

- Notes
(0012296 - 54 - 54 - 54 - 146 - 146 - 146)
nicolas cellier
06-13-08 01:54

If optimization of to:do: is to change, think of 0006456
 
(0013864 - 177 - 216 - 216 - 216 - 216 - 216)
nicolas cellier
09-07-10 19:21

The problem still exists in trunk...
Following code halts when it should not.

| n |
n := 2.
1 to: n do: [:i | (n := n+1)>10 ifTrue: [self halt: 'Should I get here?']].
^n
 
(0013870 - 44 - 44 - 44 - 44 - 44 - 44)
nicolas cellier
09-07-10 22:15

Eliot fixed the Compiler bug, file attached.
 
(0013871 - 121 - 139 - 285 - 285 - 285 - 285)
nicolas cellier
09-07-10 23:14

http://source.squeak.org/trunk/Tests-nice.93.mcz [^]
Provides two non regression tests
- 1 for compiler
- 1 for decompiler
 
(0013872 - 384 - 420 - 574 - 574 - 574 - 574)
nicolas cellier
09-07-10 23:38

http://source.squeak.org/trunk/Compiler-nice.173.mcz [^] includes Compiler fix

The idea is to avoid optimizing a to:do: loop that does modify its limit inside the loop.

Note: an alternate solution would be to create a shadow variable, assign it with the limit, and optimize the block.

Note 2: the bug report also has a so far uncorrected Decompiler part and cannot be closed yet.
 
(0014044 - 72 - 72 - 226 - 226 - 226 - 226)
nicolas cellier
02-03-11 23:32

Fixed during 4.2 in http://source.squeak.org/trunk/Compiler-nice.184.mcz [^]
 

- Issue History
Date Modified Username Field Change
06-13-08 01:24 nicolas cellier New Issue
06-13-08 01:54 nicolas cellier Note Added: 0012296
09-07-10 19:21 nicolas cellier Note Added: 0013864
09-07-10 22:14 nicolas cellier File Added: M7093-MessageNode-transformToDo.st
09-07-10 22:15 nicolas cellier Note Added: 0013870
09-07-10 23:14 nicolas cellier Note Added: 0013871
09-07-10 23:38 nicolas cellier Note Added: 0013872
02-03-11 23:27 nicolas cellier Relationship added related to 0006456
02-03-11 23:32 nicolas cellier Status new => resolved
02-03-11 23:32 nicolas cellier Fixed in Version  => trunk
02-03-11 23:32 nicolas cellier Resolution open => fixed
02-03-11 23:32 nicolas cellier Assigned To  => nicolas cellier
02-03-11 23:32 nicolas cellier Note Added: 0014044
02-06-11 23:48 leves Status resolved => closed


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
65 total queries executed.
44 unique queries executed.
Powered by Mantis Bugtracker